监控建设实践¶
OpsAny基础监控是基于Zabbix的管理平台,通过和Zabbix的集成,使用Zabbix强大的数据采集和模版管理能力,同时补充Zabbix的不足,如:CMDB集成、管控纳管集成、可视化集成等。虽然我们尽可能的减少对Zabbix界面的依赖,但是仍然需要用户熟悉Zabbix,才能更好的使用基础监控的相关功能。
集成Zabbix¶
接入Zabbix可以在【管控平台】的“采控管理”页面以Zabbix API的方式集成Zabbix。目前仅支持Zabbix LTS(长期支持)版本:5.0 LTS、6.0 LTS、7.0 LTS。建议生产环境采用LTS版本。
OpsAny支持接入多个Zabbix Server,并且对Zabbix Server进行分组管理。自v2.2.2版本开始,默认部署Zabbix 7.0.3版本,并自动集成到管控平台中。
Zabbix Server部署¶
OpsAny提供了zabbix-install.sh可以一键使用Docker部署Zabbix Server,用户也可以直接对接企业已经正在使用的Zabbix,或者自行部署均可。
Zabbix Agent部署¶
在管控平台进行主机纳管时可以选择Zabbix监控插件,OpsAny会自动在目标主机部署Zabbix Agent(被动模式),请选择正确的监控模版,方可正确的完成监控数据采集。
Zabbix Agent模式:
- 被动模式:默认,Zabbix Server主动轮训Zabbix Agent的10050端口,进行数据获取,要求Server的10051端口和Agent 10050端口互相通信。
- 主动模式:Zabbix Agent主动连接Server的10051端口发送监控指标数据,要求Agent配置文件中的HostName字段和配置的名称保持一致,并且选择Active的对应模版。
如果遇到监控状态不正常,可以登录Zabbix Web页面查看,如果Zabbix Web页面也不正常,请检查网络、模版等相关问题。
管控平台和Zabbix¶
由于Zabbix的所有监控对象均为【Host】,为了区分主机和网络设备,管控平台在纳管的时候会给Host增加标签。
- 主机: host_type:server
- 网络设备: host_type: network 、device_type: ROUTER|FIREWALL|SWITCH。后者的设备类型自动从资源平台,网络设备的模型分组中获取,支持自定义模型。
如果你需要将Zabbix的主机反向的同步到OpsAny管控平台,如果有网络设备,需要提前手工设置标签方可顺利进行同步。
Grafana可视化¶
OpsAny基础监控采用Grafana进行可视化展示,Grafana是一款流行的开源的数据可视化工具,默认支持多种数据源,通过安装插件支持Zabbix数据展示。目前基础监控已经嵌入了Grafana,方便用户可以进行自定义Dashboard。
集成Prometheus¶
OpsAny支持集成Prometheus监控,社区版可以手工安装Exporter,进行监控。OpsAny通过Prometheus实现主机、组件、应用的监控,支持自定义指标采集插件,管理功能位于【管控平台】-【采集插件】-【指标采集】。
集成位置:【管控平台】-【采控管理】-【Prometheus集成】添加Prometheus Server。
Prometheus监控MySQL¶
1.部署MySQL Exporter¶
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
[root@dev src]# tar zxf mysqld_exporter-0.13.0.linux-amd64.tar.gz
[root@dev src]# mv mysqld_exporter-0.13.0.linux-amd64 /usr/local/
[root@dev src]# ln -s /usr/local/mysqld_exporter-0.13.0.linux-amd64/ /usr/local/mysqld_exporter
2.配置系统服务¶
[root@dev src]# vim /usr/lib/systemd/system/mysql_exporter.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
[Install]
WantedBy=multi-user.target
3.配置MySQL¶
- 登录到受监控的MySQL中
[root@dev ~]# mysql -u root -p
- 创建MySQL监控账户并授权
MariaDB [(none)]> CREATE USER 'opsany_monitor'@'localhost' IDENTIFIED BY 'OpsAny@2020';
MariaDB [(none)]> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'opsany_monitor'@'localhost';
- 配置MySQL监控账户
[root@dev ~]# vim /usr/local/mysqld_exporter/.my.cnf
[client]
user=opsany_monitor
password=OpsAny@2020
4.启动监控插件¶
systemctl daemon-reload
systemctl restart mysql_exporter.service
5.测试运行¶
curl http://127.0.0.1:9104/metrics
测试没有问题,可以修改Prometheus配置去添加target。
Prometheus监控Redis¶
1.部署Redis Exporter¶
- 下载并部署Redis Exporter
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/oliver006/redis_exporter/releases/download/v1.25.0/redis_exporter-v1.25.0.linux-amd64.tar.gz
[root@dev src]# tar zxf redis_exporter-v1.25.0.linux-amd64.tar.gz
[root@dev src]# mv redis_exporter-v1.25.0.linux-amd64 /usr/local/
[root@dev src]# ln -s /usr/local/redis_exporter-v1.25.0.linux-amd64/ /usr/local/redis_exporter
- 启动参数介绍
启动参数
-redis.addr string:Redis实例的地址,可以使一个或者多个,多个节点使用逗号分隔,默认为 "redis://localhost:6379"
-redis.password string:Redis实例的密码
-web.listen-address string:服务监听的地址,默认为 0.0.0.0:9121
2.启动Redis Exporter¶
- 创建启动用户prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/redis_exporter
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/redis_exporter.service <<EOF
[Unit]
Description=redis_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/redis_exporter/redis_exporter -redis.addr 127.0.0.1:6379 -redis.password 123456 -web.listen-address 0.0.0.0:9121
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
3.启动Redis Exporter¶
[root@dev ~]# systemctl start redis_exporter
[root@dev ~]# systemctl enable redis_exporter
测试访问
curl http://127.0.0.1:9121/metrics
Prometheus监控MongoDB¶
官方地址:https://github.com/percona/mongodb_exporter
1.部署MongoDB Exporter¶
- 下载并部署MongoDB Exporter
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/percona/mongodb_exporter/releases/download/v0.34.0/mongodb_exporter-0.34.0.linux-amd64.tar.gz
[root@dev src]# tar zxf mongodb_exporter-0.34.0.linux-amd64.tar.gz
[root@dev src]# mv mongodb_exporter-0.34.0.linux-amd64 /usr/local/
[root@dev src]# ln -s /usr/local/mongodb_exporter-0.34.0.linux-amd64/ /usr/local/mongodb_exporter
2.启动MongoDB Exporter¶
- 创建启动用户prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/mongodb_exporter
- 创建MongoDB监控用户并授权
use admin
db.createUser({
user: "prometheus",
pwd: "prometheus",
roles: [
{ role: "read", db: "admin" },
{ role: "readAnyDatabase", db: "admin" },
{ role: "clusterMonitor", db: "admin" }
]
});
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/mongodb_exporter.service <<EOF
[Unit]
Description=mongodb_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/mongodb_exporter/mongodb_exporter --mongodb.uri=mongodb://prometheus:prometheus@127.0.0.1:27017/admin --collect-all --collector.topmetrics --collector.indexstats --collector.dbstats --web.listen-address=":9216"
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
3.启动MongoDB Exporter¶
[root@dev ~]# systemctl start mongodb_exporter
[root@dev ~]# systemctl enable mongodb_exporter
测试访问
curl http://127.0.0.1:9216/metrics
Prometheus监控Elasticsearch¶
Prometheus社区提供了Elasticsearch监控的Exporter,地址如下:
- 官网地址:https://github.com/prometheus-community/elasticsearch_exporter
- 下载地址:https://github.com/prometheus-community/elasticsearch_exporter/releases
1.部署Elasticsearch Exporter¶
- 下载并部署Elasticsearch Exporter
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://opsany-saas.oss-cn-beijing.aliyuncs.com/exporter/elasticsearch_exporter-1.5.0.linux-amd64.tar.gz
[root@dev src]# tar zxf elasticsearch_exporter-1.5.0.linux-amd64.tar.gz
[root@dev src]# mv elasticsearch_exporter-1.5.0.linux-amd64 /usr/local/
[root@dev src]# ln -s /usr/local/elasticsearch_exporter-1.5.0.linux-amd64/ /usr/local/elasticsearch_exporter
2.设置Elasticsearch Exporter¶
- 创建启动用户prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/elasticsearch_exporter
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/elasticsearch_exporter.service <<EOF
[Unit]
Description=elasticsearch_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/elasticsearch_exporter/elasticsearch_exporter --web.listen-address 0.0.0.0:9114 --es.uri http://elastic@OpsAny@2023@127.0.0.1:9200 --es.all --es.indices --es.cluster_settings --es.indices_settings --es.shards --es.snapshots
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
3.启动Elasticsearch Exporter¶
[root@dev ~]# systemctl daemon-reload
[root@dev ~]# systemctl start elasticsearch_exporter
[root@dev ~]# systemctl enable elasticsearch_exporter
测试访问
curl http://127.0.0.1:9114/metrics
4.添加Grafana Dashboard¶
- 官方提供的:https://github.com/prometheus-community/elasticsearch_exporter/blob/master/examples/grafana/dashboard.json
Prometheus监控RabbitMQ¶
使用Prometheus监控RabbitMQ有两种方式:
- RabbitMQ官方提供了Prometheus监控的插件 https://www.rabbitmq.com/prometheus.html
- 使用独立的RabbitMQ Exporter
使用RabbitMQ自带的监控插件¶
1. 启用官方自带的监控插件¶
# 启用插件
rabbitmq-plugins enable rabbitmq_prometheus
# 测试访问
curl -s localhost:15692/metrics | head -n 3
使用独立的RabbitMQ Exporter¶
1.部署RabbitMQ Exporter¶
- 下载并部署RabbitMQ Exporter
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/kbudde/rabbitmq_exporter/releases/download/v1.0.0-RC19/rabbitmq_exporter_1.0.0-RC19_linux_amd64.tar.gz
[root@dev src]# tar xf rabbitmq_exporter_1.0.0-RC19_linux_amd64.tar.gz
[root@dev src]# mv rabbitmq_exporter /usr/local/
2.设置RabbitMQ Exporter¶
- 创建启动用户prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/rabbitmq_exporter
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/rabbitmq_exporter.service <<EOF
[Unit]
Description=rabbitmq_exporter
After=network.target
[Service]
Type=simple
User=prometheus
Environment="RABBIT_USER=opsany" "RABBIT_PASSWORD=OpsAny@2020" "OUTPUT_FORMAT=JSON" "PUBLISH_PORT=9099" "RABBIT_URL=http://127.0.0.1:15672"
ExecStart=/usr/local/rabbitmq_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
3.启动RabbitMQ Exporter¶
[root@dev ~]# systemctl daemon-reload
[root@dev ~]# systemctl start rabbitmq_exporter
[root@dev ~]# systemctl enable rabbitmq_exporter
测试访问
curl 127.0.0.1:9099/metrics
添加Grafana Dashboard¶
可以使用官方提供的Dashboard
- 官方提供的:https://github.com/prometheus-community/elasticsearch_exporter/blob/master/examples/grafana/dashboard.json
Prometheus监控ZooKeeper¶
1.部署ZooKeeoer Exporter¶
- 下载并部署ZooKeeper Exporter
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/dabealu/zookeeper-exporter/releases/download/v0.1.13/zookeeper-exporter-v0.1.13-linux.tar.gz
[root@dev src]# tar xf zookeeper-exporter-v0.1.13-linux.tar.gz
[root@dev src]# mv zookeeper-exporter-v0.1.13-linux /usr/local/zookeeper-exporter
2.设置ZooKeeper Exporter¶
- 创建启动用户prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/zookeeper-exporter
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/zookeeper_exporter.service <<EOF
[Unit]
Description=zookeeper_exporter
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=/usr/local/zookeeper-exporter/zookeeper-exporter -zk-hosts 127.0.0.1:2181 -bind-addr :9141
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
EOF
3.将mntr命令加入白名单¶
[root@dev ~]# vim /usr/local/zookeeper/conf/zoo.cfg
在配置文件最后加上:
4lw.commands.whitelist=*
4lw.commands.whitelist=mntr
重启ZooKeeper
[root@dev ~]# zkServer.sh stop
[root@dev ~]# zkServer.sh start
4.启动ZooKeeper Exporter¶
[root@dev ~]# systemctl daemon-reload
[root@dev ~]# systemctl start zookeeper_exporter
[root@dev ~]# systemctl enable zookeeper_exporter
测试访问
curl 127.0.0.1:9141/metrics
5.添加Grafana Dashboard¶
Dashboard JSON下载链接:https://grafana.com/api/dashboards/11442/revisions/1/download
Grafana ID:11442
Prometheus监控Kafka¶
1.部署Kafka Exporter¶
- 下载并部署Kafka Exporter
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/danielqsj/kafka_exporter/releases/download/v1.7.0/kafka_exporter-1.7.0.linux-amd64.tar.gz
[root@dev src]# tar xf kafka_exporter-1.7.0.linux-amd64.tar.gz
[root@dev src]# mv kafka_exporter-1.7.0.linux-amd64 /usr/local/kafka_exporter
2.设置Kafka Exporter¶
- 创建启动用户prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/kafka_exporter
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/kafka_exporter.service <<EOF
[Unit]
Description=kafka_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart= /usr/local/kafka_exporter/kafka_exporter --kafka.server=127.0.0.1:9092 --web.listen-address=9308
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
3.启动Kafka Exporter¶
[root@dev ~]# systemctl daemon-reload
[root@dev ~]# systemctl start kafka_exporter
[root@dev ~]# systemctl enable kafka_exporter
测试访问
curl 127.0.0.1:9308/metrics
4.添加Grafana Dashboard¶
Dashboard JSON下载链接:https://grafana.com/api/dashboards/7589/revisions/5/download
Grafana ID:7589
Prometheus监控Nacos¶
Nacos支持通过暴露Metrics数据接入Prometheus监控Nacos运行状态
Nacos官方监控文档:https://nacos.io/zh-cn/docs/monitor-guide.html
1.Nacos暴露Metrics数据¶
配置application.properties文件,暴露metrics数据
management.endpoints.web.exposure.include=*
如果是集群nacos每个节点都添加
测试访问
访问127.0.0.1:8848/nacos/actuator/prometheus,看是否能访问到metrics数据
curl 127.0.0.1:8848/nacos/actuator/prometheus
2.配置Prometheus¶
修改配置文件prometheus.yml采集Nacos metrics数据
- job_name: 'nacos'
scrape_interval: 15s
metrics_path: '/nacos/actuator/prometheus'
static_configs:
- targets: ['127.0.0.1:8848']
3.添加Grafana Dashboard¶
可以使用官方提供的Dashboard
- 官方提供的Dashboard:https://github.com/nacos-group/nacos-template/blob/master/nacos-grafana.json
- Grafana ID:13221
Prometheus监控MinIO¶
MinIO自身提供了Prometheus监控的指标数据,分为两种形式获取:
- Public方式,开放形式获取(不需要任何认证)
- 身份验证方式
由于Public方式不需要任何认证,所以并不安全,推荐使用身份验证方式抓取MinIO集群的指标
MinIO官方监控文档:https://min.io/docs/minio/linux/operations/monitoring/collect-minio-metrics-using-prometheus.html
1.身份验证方式获取指标数据¶
首先使用minio client 设置别名,然后获取prometheus配置
#运行mc容器
docker pull minio/mc
docker run -it --entrypoint=/bin/sh minio/mc
# 设置别名
mc alias set minio http://127.0.0.1:9000 admin admin
#生成配置
mc admin prometheus generate minio
#配置输出
scrape_configs:
- job_name: minio-job
bearer_token: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjQ4MTI0MDA0NTcsImlzcyI6InByb21ldGhldXMiLCJzdWIiOiJhZG1pbiJ9.o2ymp655JwB05XlsXTtZJzDlpYUfT2ITgxOdYyqxiOfnkMznphUALSU0yhgobAaQCLtwAZgnKbjBfwxQJlzKSA
metrics_path: /minio/v2/metrics/cluster
scheme: http
static_configs:
- targets: ['127.0.0.1:9000']
2.配置Prometheus¶
将刚才生成的配置加入到prometheus的配置中,重启服务即可。prometheus中的配置:
- job_name: minio-job
bearer_token: eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJleHAiOjQ4MTI0MDA0NTcsImlzcyI6InByb21ldGhldXMiLCJzdWIiOiJhZG1pbiJ9.o2ymp655JwB05XlsXTtZJzDlpYUfT2ITgxOdYyqxiOfnkMznphUALSU0yhgobAaQCLtwAZgnKbjBfwxQJlzKSA
metrics_path: /minio/v2/metrics/cluster
scheme: http
static_configs:
- targets: ['127.0.0.1:9000']
3.添加Grafana Dashboard¶
MinIO 提供了几个官方的 Grafana 仪表板,可以从 Grafana 仪表板下载:
-
官方提供的Dashboard:https://raw.githubusercontent.com/minio/minio/master/docs/metrics/prometheus/grafana/minio-dashboard.json
-
Grafana ID:13502
Prometheus监控Kibana¶
1.部署Kibana Exporter¶
- 下载并部署Kibana Exporter
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/chamilad/kibana-prometheus-exporter/releases/download/v8.7.x.2/kibana_exporter-v8.7.x.2-linux-amd64
[root@dev src]# mv kibana_exporter-v8.7.x.2-linux-amd64 /usr/local/kibana_exporter
2.设置Kibana Exporter¶
- 创建启动用户Prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/kibana_exporter
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/kibana_exporter.service <<EOF
[Unit]
Description=kibana_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart= /usr/local/kibana_exporter -kibana.uri http://127.0.0.1:5601 -web.listen-address 0.0.0.0:9684
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
配置:
- debug :此选项在指标收集过程中启用详细输出,通常在开发过程中使用。
- kibana.password :此选项指定用于Kibana API的密码。Kibana API用于从Kibana中获取指标,Kibana是一种数据可视化和探索工具。
- kibana.skip-tls :此选项允许跳过对TLS安全的Kibana URL进行TLS验证。TLS是一种用于保护网络通信的加密协议。
- kibana.uri :此选项指定应从中获取指标的Kibana API URL。
- kibana.username :此选项指定用于与Kibana API进行身份验证的用户名。
- web.listen-address :此选项指定程序应监听HTTP请求的网络地址。默认值为":9684"。
- web.telemetry-path :此选项指定程序应通过HTTP公开指标的路径。默认值为"/metrics"。
3.启动Kibana Exporter¶
[root@dev ~]# systemctl daemon-reload
[root@dev ~]# systemctl start kibana_exporter
[root@dev ~]# systemctl enable kibana_exporter
访问测试
curl http://127.0.0.1:9684/metrics
4.添加Grafana Dashboard¶
Dashboard JSON下载链接:https://github.com/chamilad/kibana-prometheus-exporter/blob/master/grafana/dashboard.json
Grafana ID:21420
Prometheus监控Logstash¶
1.部署Logstash Exporter¶
- 下载并部署Logstash Exporter
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/alxrem/prometheus-logstash-exporter/releases/download/0.7.0/prometheus-logstash-exporter_0.7.0_linux_amd64
[root@dev src]# mv prometheus-logstash-exporter_0.7.0_linux_amd64 /usr/local/logstash_exporter
2.设置Logstash Exporter¶
- 创建启动用户Prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/logstash_exporter
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/logstash_exporter.service <<EOF
[Unit]
Description=logstash_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart= /usr/local/logstash_exporter -logstash.host 127.0.0.1 -logstash.port 9600 -web.listen-address 0.0.0.0:9304
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
3.启动Logstash Exporter¶
[root@dev ~]# systemctl daemon-reload
[root@dev ~]# systemctl start logstash_exporter
[root@dev ~]# systemctl enable logstash_exporter
访问测试
curl http://127.0.0.1:9304/metrics
4.添加Grafana Dashboard¶
Dashboard JSON下载链接:https://grafana.com/grafana/dashboards/17918-logstash-monitoring/
Grafana ID:17918
Prometheus监控PostgreSQL¶
Prometheus社区提供了PostgreSQL监控的Exporter,地址如下:
- 官网地址:https://github.com/prometheus-community/postgres_exporter
- 下载地址:https://github.com/prometheus-community/postgres_exporter/releases
1.部署PostgreSQL Exporter¶
- 下载并部署PostgreSQL Exporter
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/prometheus-community/postgres_exporter/releases/download/v0.15.0/postgres_exporter-0.15.0.linux-amd64.tar.gz
[root@dev src]# tar -zxf postgres_exporter-0.15.0.linux-amd64.tar.gz
[root@dev src]# mv postgres_exporter-0.15.0.linux-amd64 /usr/local/postgres_exporter
2.设置PostgreSQL Exporter¶
- 创建启动用户prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/postgres_exporter
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/postgres_exporter.service <<EOF
[Unit]
Description=postgres_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/postgres_exporter/postgres_exporter --web.listen-address=":9187"
Environment="DATA_SOURCE_URI=127.0.0.1:5432/postgres?sslmode=disable"
Environment="DATA_SOURCE_USER=postgres"
Environment="DATA_SOURCE_PASS=password"
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
- 启动参数
环境变量说明
Environment:设置环境变量。调整数据库地址、数据库用户名和数据库密码
3.启动PostgreSQL Exporter¶
[root@dev ~]# systemctl daemon-reload
[root@dev ~]# systemctl start postgres_exporter
[root@dev ~]# systemctl enable postgres_exporter
测试访问
curl http://127.0.0.1:9187/metrics
4.添加Grafana Dashboard¶
Dashboard JSON下载链接:https://grafana.com/grafana/dashboards/9628-postgresql-database/
Grafana ID:9628
Prometheus监控SQL Server¶
1.部署SQL Server¶
- 下载并部署SQL Server
docker pull awaragi/prometheus-mssql-exporter
docker run -e SERVER=127.0.0.1 -e USERNAME=SA -e PASSWORD=password -e DEBUG=app -p 4000:4000 --name prometheus-mssql-exporter awaragi/prometheus-mssql-exporter
启动参数:
SERVER:服务器 ip 或 dns 名称 (必填)
PORT:服务器端口(可选,默认为 1433)
USERNAME:访问用户(必填)
PASSWORD:访问密码(必填)
ENCRYPT:强制加密设置(可选,默认为 true)
TRUST_SERVER_CERTIFICATE设置trustServerCertificate设置(可选,默认为 true)
DEBUG启用日志的逗号分隔列表(可选,目前支持应用程序和指标)
测试访问:
curl http://127.0.0.1:4000/metrics
2.添加Grafana Dashboard¶
Dashboard JSON下载链接:https://grafana.com/grafana/dashboards/13919
Grafana ID:13919
Prometheus监控Consul¶
官方Exporter地址:https://github.com/prometheus/consul_exporter
1.部署Consul Exporter¶
- 下载并部署
[root@dev ~]# cd /usr/local/src
[root@dev src]# wget https://github.com/prometheus/consul_exporter/releases/download/v0.12.1/consul_exporter-0.12.1.linux-amd64.tar.gz
[root@dev src]# tar -zxf consul_exporter-0.12.1.linux-amd64.tar.gz
[root@dev src]# mv consul_exporter-0.12.1.linux-amd64.tar.gz /usr/local/consul_exporter
2.设置Consul Exporter¶
- 创建启动用户prometheus
[root@dev ~]# groupadd prometheus
[root@dev ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev ~]# chown -R prometheus:prometheus /usr/local/consul_exporter
- 设置Systemd配置
[root@dev ~]# cat > /usr/lib/systemd/system/consul_exporter.service <<EOF
[Unit]
Description=consul_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/consul_exporter/consul_exporter --consul.server=127.0.0.1:8500 --web.listen-address=":9107"
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
3.启动Consul Exporter¶
[root@dev ~]# systemctl daemon-reload
[root@dev ~]# systemctl start consul_exporter
[root@dev ~]# systemctl enable consul_exporter
测试访问
curl http://127.0.0.1:9107/metrics
4.添加Grafana Dashboard¶
Dashboard JSON下载链接:https://grafana.com/grafana/dashboards/12049-consul-exporter-dashboard/
Grafana ID:12049