Prometheus监控手册¶
OpsAny支持集成Prometheus监控,社区版可以手工安装Exporter,进行监控。
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-node0 ~]# groupadd prometheus
[root@dev-node0 ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev-node0 ~]# chown -R prometheus:prometheus /usr/local/redis_exporter
- 设置Systemd配置
[root@dev-node0 ~]# 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-node0 ~]# systemctl start redis_exporter
[root@dev-node0 ~]# systemctl enable redis_exporter
测试访问
curl http://127.0.0.1:9121/metrics
Prometheus监控MongoDB¶
官方地址:https://github.com/percona/mongodb_exporter
1.下载并部署Exporter¶
[root@dev-node0 ~]# cd /usr/local/src
[root@dev-node0 src]# wget https://github.com/percona/mongodb_exporter/releases/download/v0.34.0/mongodb_exporter-0.34.0.linux-amd64.tar.gz
[root@dev-node0 src]# tar zxf mongodb_exporter-0.34.0.linux-amd64.tar.gz
[root@dev-node0 src]# mv mongodb_exporter-0.34.0.linux-amd64 /usr/local/
[root@dev-node0 src]# ln -s /usr/local/mongodb_exporter-0.34.0.linux-amd64/ /usr/local/mongodb_exporter
2.启动MongoDB Exporter¶
- 创建启动用户prometheus
[root@dev-node0 ~]# groupadd prometheus
[root@dev-node0 ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev-node0 ~]# 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-node0 ~]# 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-node0 ~]# systemctl start mongodb_exporter
[root@dev-node0 ~]# 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-node0 ~]# groupadd prometheus
[root@dev-node0 ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev-node0 ~]# chown -R prometheus:prometheus /usr/local/elasticsearch_exporter
- 设置Systemd配置
[root@dev-node0 ~]# 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-node0 ~]# systemctl daemon-reload
[root@dev-node0 ~]# systemctl start elasticsearch_exporter
[root@dev-node0 ~]# 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自带的监控插件¶
1. 启用官方自带的监控插件¶
# 启用插件
rabbitmq-plugins enable rabbitmq_prometheus
# 测试访问
curl -s localhost:15692/metrics | head -n 3
使用独立的RabbitMQ Exporter¶
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-node0 ~]# groupadd prometheus
[root@dev-node0 ~]# useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus
[root@dev-node0 ~]# chown -R prometheus:prometheus /usr/local/elasticsearch_exporter
- 设置Systemd配置
[root@dev-node0 ~]# 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-node0 ~]# systemctl daemon-reload
[root@dev-node0 ~]# systemctl start elasticsearch_exporter
[root@dev-node0 ~]# systemctl enable elasticsearch_exporter
测试访问
curl http://127.0.0.1:9114/metrics
添加Grafana Dashboard¶
- 官方提供的:https://github.com/prometheus-community/elasticsearch_exporter/blob/master/examples/grafana/dashboard.json