Grafana+Prometheus+Node_export+Pushgateway 监控可视化
一、组件说明
-
监控访问页面,所有数据集中展示
-
监控系统,对比zabbix可不需要部署zabbix-agent端,只需脚本实现;
-
收集云主机整体性能数据;
-
数据中转,接收脚本执行结果并传输prometheus,可精确到进程使用资源详情,类似于zabbix自定义key;
-
- prometheus还支持mysql_export、haproxy_exporter、memcache_export、process_export等组件;
- 自身支持告警,依赖alertmanager;
二、数据流向说明
三、部署架构分部说明
监控每台服务器的性能资源,则每台需部署node_export;
监控进程、日志等信息,则需要一台PushGateway数据中转应用;
Grafana+Prometheus+PushGateway可部署在1台上面,需要有外网IP;
四、部署步骤
-
Grafana
安装文档
说明:- 登录名默认:admin/admin
- 端口3000
-
node_export
安装文档
说明:- 端口9100
-
pushgateway
安装文档
说明:- 端口9091
-
Prometheus
安装文档
说明:- 端口9090
五、配置说明
-
核心配置(prometheus.yml)
scrape_configs: - job_name: '集中监控平台' static_configs: - targets: ['192.168.0.47:9100'] ## 配置node_export 节点 - targets: ['localhost:9100'] - job_name: 'process_name' static_configs: - targets: ['192.168.0.47:9256'] ## 配置process_export 节点 - job_name: 'pushgateway_test' static_configs: - targets: ['192.168.0.47:9091'] ## 配置pushgateway 节点
六、自定义监控项
- 监控进程使用内存,结合crontab运行;
#!/bin/bash
instance_name=`hostname`
label="number_process" #定义key名
number_process=`ps aux | grep "$1" | grep -v grep | grep -v "process" | awk '{print $4}'`
echo "$label: $number_process"
echo "$label $number_process" | curl --data-binary @- http://192.168.0.47:9091/metrics/job/pushgateway_test/instance/$instance_name
七、Grafan添加数据源
-
添加Prometheus
-
Prometheus可用模板
- 导入模板,示例图如下
八、示例图
- 服务器资源使用展示
- 进程资源使用情况