1.Linux主机监控
1.1.Node_export服务下载及安装
- 被监控主机信息
系统:CentOS Linux release 7.4.1708 (Core) IP地址:192.168.1.4 Node exporter版本:node_exporter-1.0.1.linux-amd64.tar.gz
- 下载安装包
Node exporter下载
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
- 解压到指定目录
tar xf node_exporter-1.0.1.linux-amd64.tar.gz -C /app/ [root@centos7 ~]# cd /app/ [root@docker02 app]# chown -R root:root node_exporter-1.0.1.linux-amd64/
- 添加node_exporter为系统服务
[root@centos7 app]# vim /usr/lib/systemd/system/node_exporter.service [root@centos7 app]# cat /usr/lib/systemd/system/node_exporter.service [Unit] Description=node_exporter Documentation=https:// prometheus.io/ After=network-online.target [Service] Type=simple User=root Group=root ExecStart=/app/node_exporter-1.0.1.linux-amd64/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target
- 启动服务
[root@centos7 system]# systemctl daemon-reload [root@centos7 app]# systemctl start node_exporter.service [root@centos7 app]# systemctl enable node_exporter.service [root@centos7 system]# systemctl status node_exporter.service ● node_exporter.service - node_exporter Loaded: loaded (/usr/lib/systemd/system/node_exporter.service; disabled; vendor preset: disabled) Active: active (running) since 五 2021-01-22 17:04:49 CST; 9s ago Main PID: 1662 (node_exporter) CGroup: /system.slice/node_exporter.service └─1662 /app/node_exporter-1.0.1.linux-amd64/node_exporter [root@centos7 ~]# ss -utpln tcp LISTEN 0 128 :::9100 :::* users:(("node_exporter",pid=1662,fd=3))
1.2.把Node_export集成prometheus
- 修改配置文件
[root@centos7 prometheus]# cd /app/prometheus [root@centos7 prometheus]# vim prometheus.yml scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['192.168.1.3:9090'] - job_name: 'node_exporter' static_configs: - targets: ['192.168.1.4:9100']
- 重启prometheus服务
[root@centos7 system]# killall -9 2212 [root@centos7 system]# nohup ./prometheus &
登录192.168.1.3:9090,点击status——>targets可以看到新的监控节点
1.3.在grafana中导入Node_export仪表盘
在grafana主页面左侧导航栏中点击“+”号,点击import,输入8919
点击ID号后面的load,在最下方选择数据源后点击import即可。
(我的已经添加过了,就不做了)
最终效果图如下:
2.Nginx服务监控
2.1.下载安装Nginx服务
安装部署文档链接:Nginx安装部署
链接文档版本有些老,不过步骤相同,此实验版本为Nginx-1.16.1
在编译Nginx过程中,加入以下模块:
--add-module=/path/to/nginx-module-vts
nginx-module-vts模块下载命令:
git clone git://github.com/vozlt/nginx-module-vts.git
2.2.修改配置文件
- 在配置文件中添加以下内容:
http { vhost_traffic_status_zone; ... server { ... location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; } } }
2.3.启动服务并测试
/app/nginx/sbin/nginx
看到以下信息说明配置正确
2.4.下载nginx-vts-exporter并配置
- 下载下载nginx-vts-exporter
wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.10.3/nginx-vts-exporter-0.10.3.linux-amd64.tar.gz
- 解压并启动
[root@node-02 server]# tar xf nginx-vts-exporter-0.10.3.linux-amd64.tar.gz -C /app [root@node-02 server]# cd /app/ [root@node-02 app]# ln -s nginx-vts-exporter-0.10.3.linux-amd64/ nginx-vts-exporter [root@node-02 nginx-vts-exporter]# ./nginx-vts-exporter -nginx.scrape_uri http:// localhost/status/format/json
2.5.添加为系统服务
(默认监听端口为9913)
vim /usr/lib/systemd/system/nginx-vts-exporter.service [Unit] Description=Prometheus Nginx VTS Exporter After=network.target User=nginx Group=nginx [Service] Type=simple Restart=always ExecStart=/app/nginx-vts-exporter/nginx-vts-exporter\ -nginx.scrape_uri http:// localhost/status/format/json [Install] WantedBy=multi-user.target [root@node-02 system]# systemctl daemon-reload [root@node-02 system]# systemctl start nginx_vts_exporter.service [root@node-02 system]# systemctl enable nginx_vts_exporter.service
2.6.与Prometheus集成
- 在prometheus配置文件prometheus.yml中追加以下内容:
- job_name: 'nginx_vts_exporter' scrape_interval: 10s static_configs: - targets: ['192.168.1.5:9913']
- 重新启动prometheus服务
[root@centos7 prometheus]# killall -9 prometheus [root@centos7 prometheus]# nohup ./prometheus &
登录http://192.168.1.3:9090/targets查看
2.7.在grafana中导入仪表盘
- json文件地址:
(将文件内容复制到此处)
https://github.com/hnlq715/nginx-vts-exporter/blob/master/dashboard/nginx-vts-exporter.json
点击load后选择import,可以看到以下结果