0
点赞
收藏
分享

微信扫一扫

Node Export 监控 Linux主机


如何监控服务?


如果要想监控,前提是能获取被监控端指标数据,并且这个数据格式必须遵循Prometheus数据模型,这样才能识别和采集,一般使用exporter提供监控指标数据。




exporter列表: https://prometheus.io/docs/instrumenting/exporters



Node Export 监控 Linux主机_服务器

监控mysql需要安装mysql exporter这个组件,这个组件会连接mysql,从mysq获取到想监控的指标

当你知道要监控哪些服务,那么需要准备相应的exporter组件,准备好之后只要这些组件可以去连接监控的目标,那么启动之后暴露的接口可以在浏览器访问。那么在普罗米修斯配置就会周期性的去采集这些指标写到tsdb数据库当中由grafana去展示

 

node_exporter是什么?

Node Exporter 是用于暴露 ​​*NIX​​ 主机指标的 Exporter,比如采集 CPU、内存、磁盘等信息。采用 Go 编写,不存在任何第三方依赖,所以只需要下载解压即可运行。 

Exporter是Prometheus的一类数据采集组件的总称。它负责从目标处搜集数据,并将其转化为Prometheus支持的格式。与传统的数据采集组件不同的是,它并不向中央服务器发送数据,而是等待中央服务器主动前来抓取。

node-exporter用于采集服务器层面的运行指标,包括机器的loadavg、filesystem、meminfo等基础监控,类似于传统主机监控维度的zabbix-agent。

node_exporter:用于监控Linux系统的指标采集器。

常用指标:

•CPU

• 内存

• 硬盘

• 网络流量

• 文件描述符

• 系统负载

• 系统服务

数据接口:http://IP:9100

使用文档:https://prometheus.io/docs/guides/node-exporter/

GitHub:​​GitHub - prometheus/node_exporter: Exporter for machine metrics​​

☸ ➜ curl http://localhost:9100/metrics
......
# HELP node_load1 1m load average.
# TYPE node_load1 gauge
node_load1 0.01
# HELP node_load15 15m load average.
# TYPE node_load15 gauge
node_load15 0.05
# HELP node_load5 5m load average.
# TYPE node_load5 gauge
node_load5 0.04
# HELP node_memory_Active_anon_bytes Memory information field Active_anon_bytes.
# TYPE node_memory_Active_anon_bytes gauge
node_memory_Active_anon_bytes 8.4393984e+07
# HELP node_memory_Active_bytes Memory information field Active_bytes.
# TYPE node_memory_Active_bytes gauge
node_memory_Active_bytes 1.8167808e+08
# HELP node_memory_Active_file_bytes Memory information field Active_file_bytes.
# TYPE node_memory_Active_file_bytes gauge
node_memory_Active_file_bytes 9.7284096e+07
# HELP node_memory_AnonHugePages_bytes Memory information field AnonHugePages_bytes.
# TYPE node_memory_AnonHugePages_bytes gauge
node_memory_AnonHugePages_bytes 3.5651584e+07
# HELP node_memory_AnonPages_bytes Memory information field AnonPages_bytes.
# TYPE node_memory_AnonPages_bytes gauge
node_memory_AnonPages_bytes 8.159232e+07
# HELP node_memory_Bounce_bytes Memory information field Bounce_bytes.
# TYPE node_memory_Bounce_bytes gauge
node_memory_Bounce_bytes 0
......

该 metrics 接口数据就是一个标准的 Prometheus 监控指标格式,我们只需要将该端点配置到 Prometheus 中即可抓取该指标数据。为了了解 ​​node_exporter​​​ 可配置的参数,我们可以使用 ​​./node_exporter -h​​ 来查看帮助信息:

☸ ➜ ./node_exporter -h
--web.listen-address=":9100" # 监听的端口,默认是9100
--web.telemetry-path="/metrics" # metrics的路径,默认为/metrics
--web.disable-exporter-metrics # 是否禁用go、prome默认的metrics
--web.max-requests=40 # 最大并行请求数,默认40,设置为0时不限制
--log.level="info" # 日志等级: [debug, info, warn, error, fatal]
--log.format=logfmt # 置日志打印target和格式: [logfmt, json]
--version # 版本号
--collector.{metric-name} # 各个metric对应的参数
......

我们可以使用 --collectors.enabled参数指定node_exporter收集的功能模块,或者用--no-collector指定不需要的模块,如果不指定,将使用默认配置。

其中最重要的参数就是 ​​--collector.<name>​​​,通过该参数可以启用我们收集的功能模块,​​node_exporter​​​ 会默认采集一些模块,要禁用这些默认启用的收集器可以通过 ​​--no-collector.<name>​​​ 标志来禁用,如果只启用某些特定的收集器,基于先使用 ​​--collector.disable-defaults​​​ 标志禁用所有默认的,然后在通过指定具体的收集器 ​​--collector.<name>​​ 来进行启用。下图列出了默认启用的收集器: 

Node Export 监控 Linux主机_数据_02

 

部署node_exporter

docker部署

下载镜像

docker pull prom/node-exporter

生成容器

docker run -d -p 9100:9100 prom/node-exporter

Node Export 监控 Linux主机_数据_03

 验证是否安装成功——访问URL ​​http://服务器IP:9100/metrics​

Node Export 监控 Linux主机_服务器_04

二进制部署 

 Node-export也是二进制部署,监控哪台机器就在哪台机器上部署

[root@k8s-master ~]# tar xf node_exporter-1.0.1.linux-amd64.tar.gz 
[root@k8s-master ~]# mv node_exporter-1.0.1.linux-amd64 /usr/local/node_exporter
[root@k8s-master ~]# cd /usr/local/node_exporter/
[root@k8s-master node_exporter]# ls
LICENSE node_exporter NOTICE
[root@k8s-master node_exporter]# ./node_exporter

可以看到将指标暴露出来了 

Node Export 监控 Linux主机_linux_05

为了方便管理使用系统服务管理

[root@k8s-master ~]# cat /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter

[Service]
ExecStart=/usr/local/node_exporter/node_exporter
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.targetcd

[root@k8s-master ~]# systemctl daemon-reload
[root@k8s-master ~]# systemctl start node_exporter
[root@k8s-master ~]# systemctl enable node_exporter
Created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /usr/lib/systemd/system/node_exporter.service.

k8s部署

[root@master prometheus]# cat node-export.yaml 
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-exporter
namespace: monitor
labels:
name: node-exporter
spec:
selector:
matchLabels:
name: node-exporter
template:
metadata:
labels:
name: node-exporter
spec:
hostPID: true
hostIPC: true
hostNetwork: true
containers:
- name: node-exporter
image: prom/node-exporter:v0.16.0
ports:
- containerPort: 9100
resources:
requests:
cpu: 0.15
securityContext:
privileged: true
args:
- --path.procfs
- /host/proc
- --path.sysfs
- /host/sys
- --collector.filesystem.ignored-mount-points
- '"^/(sys|proc|dev|host|etc)($|/)"'
volumeMounts:
- name: dev
mountPath: /host/dev
- name: proc
mountPath: /host/proc
- name: sys
mountPath: /host/sys
- name: rootfs
mountPath: /rootfs
tolerations:
- key: "node-role.kubernetes.io/master"
operator: "Exists"
effect: "NoSchedule"
volumes:
- name: proc
hostPath:
path: /proc
- name: dev
hostPath:
path: /dev
- name: sys
hostPath:
path: /sys
- name: rootfs
hostPath:
path: /


[root@master prometheus]# kubectl get pod -n monitor
NAME READY STATUS RESTARTS AGE
node-exporter-75wzb 1/1 Running 0 19m
node-exporter-pgttj 1/1 Running 0 19m
node-exporter-t8zsg 1/1 Running 0 19m

 

 

采集到的数据

[root@master prometheus]# curl http://192.168.100.5:9100/metrics | grep node_cpu_seconds_total
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0# HELP node_cpu_seconds_total Seconds the cpus spent in each mode.
# TYPE node_cpu_seconds_total counter
node_cpu_seconds_total{cpu="0",mode="idle"} 380.18
node_cpu_seconds_total{cpu="0",mode="iowait"} 1964.76
node_cpu_seconds_total{cpu="0",mode="irq"} 0
node_cpu_seconds_total{cpu="0",mode="nice"} 0.02
node_cpu_seconds_total{cpu="0",mode="softirq"} 9.72
node_cpu_seconds_total{cpu="0",mode="steal"} 0
node_cpu_seconds_total{cpu="0",mode="system"} 146.12
node_cpu_seconds_total{cpu="0",mode="user"} 215.83
node_cpu_seconds_total{cpu="1",mode="idle"} 354.05
node_cpu_seconds_total{cpu="1",mode="iowait"} 1987.14
node_cpu_seconds_total{cpu="1",mode="irq"} 0
node_cpu_seconds_total{cpu="1",mode="nice"} 0.02
node_cpu_seconds_total{cpu="1",mode="softirq"} 6.77
node_cpu_seconds_total{cpu="1",mode="steal"} 0
node_cpu_seconds_total{cpu="1",mode="system"} 147.74
node_cpu_seconds_total{cpu="1",mode="user"} 216.93
100 106k 100 106k 0 0 8283k 0 --:--:-- --:--:-- --:--:-- 8888k

可以看到每个cpu采集到的指标,下面是负载相关的指标,分别在1m,15m,5m

[root@master prometheus]# curl http://192.168.100.5:9100/metrics | grep node_load
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 106k 100 106k 0 0 7519k 0 --:--:-- --:--:-- --:--:-- 8207k
# HELP node_load1 1m load average.
# TYPE node_load1 gauge
node_load1 2.31
# HELP node_load15 15m load average.
# TYPE node_load15 gauge
node_load15 2.49
# HELP node_load5 5m load average.
# TYPE node_load5 gauge
node_load5 2.41

监控linux主机

这里配置组名

采用接口和访问http方式不需要配置,默认

  - job_name: 'webserver'
static_configs:
- targets: ['192.168.179.99:9100','192.168.179.102:9100']

配置好使用工具对其检查,检查配置文件是否正常

[root@localhost prometheus]# ./promtool check config prometheus.yml 
Checking prometheus.yml
SUCCESS: 0 rule files found

 启用热加载配置,不重启服务

[root@localhost prometheus]# ps -ef | grep prometheus
[root@localhost prometheus]# kill -HUP 27228

Node Export 监控 Linux主机_数据_06

看看 指标是否被采集到了?

Node Export 监控 Linux主机_服务器_07

Grafana展示

grafana维护了仪表盘,里面存放了许多的仪表盘

使用Grafana展示node_exporter数据指标,仪表盘ID: 9276

Node Export 监控 Linux主机_linux_08

这里可以导入你的json文件或者使用grafana仓库里面的

Node Export 监控 Linux主机_prometheus_09

​​Dashboards | Grafana Labs​​

这里包含了大量的仪表盘

Node Export 监控 Linux主机_服务器_10

这两个没有数据,打开编辑里面的promql

Node Export 监控 Linux主机_数据_11

Node Export 监控 Linux主机_服务器_12

 修改为指定的网卡

上面的语句就是普罗米修斯的查询语言

irate(node_network_receive_bytes_total{instance=~'$node',device=~'ens32'}[5m])*8

Grafana通过普罗米修斯的查询语言获取指定的数据

Node Export 监控 Linux主机_服务器_13

 

Node Export 监控 Linux主机_服务器_14

举报

相关推荐

0 条评论