Prometheus(三)监控服务器:node_exporter

2019-07-17  本文已影响0人  咩咩的毛球

为监控服务器CPU、内存、磁盘、I/O等信息,需要node_exporter,作用是用于机器系统数据收集。

  1. 安装 node_exporter
$ git clone https://github.com/prometheus/node_exporter.git
$ mv node_exporter-0.18.1.linux-amd64 /usr/local/prometheus/node_exporter
  1. 创建Systemd服务
$ vim /etc/systemd/system/node_exporter.service

[Unit]
Description=node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
  1. 启动Node exporter,并使其在系统启动时每次启动。
$ systemctl start node_exporter
$ systemctl enable node_exporter
  1. 验证Node exporter是否启动成功
$ systemctl status node_exporter

● node_exporter.service - node_exporter
   Loaded: loaded (/etc/systemd/system/node_exporter.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2019-07-17 15:10:26 CST; 10s ago
 Main PID: 13085 (node_exporter)
    Tasks: 3
   Memory: 1.1M
      CPU: 5ms
   CGroup: /system.slice/node_exporter.service
           └─13085 /usr/local/prometheus/node_exporter/node_exporter
  1. 修改prometheus.yml,加入下面的监控目标:
    Node Exporter默认的抓取地址为http://IP:9100/metrics
$ vim  /usr/local/prometheus/prometheus.yml

  - job_name: 'linux'
    static_configs:
      - targets: ['localhost:9100']
        labels:
          instance: node1

prometheus.yml中一共定义了两个监控:一个是监控prometheus自身服务,另一个是监控Linux服务器。这里给个完整的示例:

- job_name: 'prometheus'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'linux'
    static_configs:
      - targets: ['localhost:9100']
        labels:
          instance: node1
  1. 重启Prometheus
$ systemctl restart prometheus
  1. 在Prometheus Web查看监控的目标
  1. 使用Prometheus Web来验证Node Exporter的数据已经被正确的采集。

常用指令

https://www.howtoing.com/how-to-install-prometheus-and-node-exporter-on-centos-7

上一篇 下一篇

猜你喜欢

热点阅读