
参考链接:
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#tls_config
- 1.prometheus端创建etcd证书目录
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]# pwd
/violet/softwares/prometheus-2.53.4.linux-amd64
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]#
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]# mkdir -p certs/etcd
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]#
- 2.将etcd的自建证书拷贝prometheus服务器
[root@node-exporter41 ~]# scp /violet/certs/etcd/etcd-{ca.pem,server-key.pem,server.pem} 10.0.0.31:/violet/softwares/prometheus-2.53.4.linux-amd64/certs/etcd
- 3.Prometheus查看证书文件
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]# tree certs/etcd/
certs/etcd/
├── etcd-ca.pem
├── etcd-server-key.pem
└── etcd-server.pem
0 directories, 3 files
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]#
4.修改Prometheus的配置文件【修改配置时,可以将中文注释删除,此处的中文注释是方便你理解的。】
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]# vim prometheus.yml
...
- job_name: "violet-etcd-cluster"
# 使用https协议
scheme: https
# 配置https证书相关信息
tls_config:
# 指定CA的证书文件
ca_file: certs/etcd/etcd-ca.pem
# 指定etcd服务的公钥文件
cert_file: certs/etcd/etcd-server.pem
# 指定etcd服务的私钥文件
key_file: certs/etcd/etcd-server-key.pem
static_configs:
- targets:
- 10.0.0.41:2379
- 10.0.0.42:2379
- 10.0.0.43:2379
- 5.检查配置文件是否正确
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]# ./promtool check config prometheus.yml
Checking prometheus.yml
SUCCESS: 1 rule files found
SUCCESS: prometheus.yml is valid prometheus config file syntax
Checking violet-linux96-rules.yml
SUCCESS: 3 rules found
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]#
- 6.热加载配置文件
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
- 7.检查配置是否生效
http://10.0.0.31:9090/targets
- 8.grafana导入模板ID
21473
3070
10323
Prometheus的配置文件参考:
https://gitee.com/jasonyin2020/cloud-computing-stack/tree/linux96/linux96/prometheus
prometheus监控MySQL
- 1.启动MySQL数据库
[root@elk93 ~]# /etc/init.d/mysql.server start
Starting mysql.server (via systemctl): mysql.server.service.
[root@elk93 ~]#
[root@elk93 ~]# ss -ntl | grep 3306
LISTEN 0 151 *:3306 *:*
LISTEN 0 70 *:33060 *:*
[root@elk93 ~]#
mysql> SELECT user,host,plugin FROM mysql.user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| linux | % | mysql_native_password |
| nacos | % | mysql_native_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
6 rows in set (0.00 sec)
mysql>
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO linux;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW GRANTS FOR linux;
+-------------------------------------------------------------------+
| Grants for linux@% |
+-------------------------------------------------------------------+
| GRANT SELECT, PROCESS, REPLICATION CLIENT ON *.* TO `linux`@`%` |
| GRANT ALL PRIVILEGES ON `violet_kafka`.* TO `linux`@`%` |
+-------------------------------------------------------------------+
2 rows in set (0.01 sec)
mysql>
- 2.下载mysql_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.17.2/mysqld_exporter-0.17.2.linux-amd64.tar.gz
- 3.解压程序
[root@elk91 ~]# tar xf mysqld_exporter-0.17.2.linux-amd64.tar.gz -C /usr/local/bin/ mysqld_exporter-0.17.2.linux-amd64/mysqld_exporter --strip-components=1
[root@elk91 ~]#
[root@elk91 ~]# ll /usr/local/bin/
total 17936
drwxr-xr-x 2 root root 4096 Mar 27 10:56 ./
drwxr-xr-x 18 root root 4096 Mar 24 18:03 ../
-rwxr-xr-x 1 1001 1002 18356306 Feb 26 15:16 mysqld_exporter*
[root@elk91 ~]#
- 4.启动MySQL exporter
[root@elk91 ~]# cat .my.cnf
[client]
user=linux
password=123456
host=10.0.0.93
[root@elk91 ~]#
[root@elk91 ~]# mysqld_exporter --config.my-cnf="/root/.my.cnf"
time=2025-03-27T03:09:09.709Z level=INFO source=mysqld_exporter.go:239 msg="Starting mysqld_exporter" version="(version=0.17.2, branch=HEAD, revision=e84f4f22f8a11089d5f04ff9bfdc5fc042605773)"
time=2025-03-27T03:09:09.709Z level=INFO source=mysqld_exporter.go:240 msg="Build context" build_context="(go=go1.23.6, platform=linux/amd64, user=root@18b69b4b0fea, date=20250226-07:16:19, tags=unknown)"
time=2025-03-27T03:09:09.709Z level=INFO source=mysqld_exporter.go:252 msg="Scraper enabled" scraper=global_status
time=2025-03-27T03:09:09.709Z level=INFO source=mysqld_exporter.go:252 msg="Scraper enabled" scraper=global_variables
time=2025-03-27T03:09:09.709Z level=INFO source=mysqld_exporter.go:252 msg="Scraper enabled" scraper=slave_status
time=2025-03-27T03:09:09.709Z level=INFO source=mysqld_exporter.go:252 msg="Scraper enabled" scraper=info_schema.innodb_cmp
time=2025-03-27T03:09:09.709Z level=INFO source=mysqld_exporter.go:252 msg="Scraper enabled" scraper=info_schema.innodb_cmpmem
time=2025-03-27T03:09:09.709Z level=INFO source=mysqld_exporter.go:252 msg="Scraper enabled" scraper=info_schema.query_response_time
time=2025-03-27T03:09:09.710Z level=INFO source=tls_config.go:347 msg="Listening on" address=[::]:9104
time=2025-03-27T03:09:09.710Z level=INFO source=tls_config.go:350 msg="TLS is disabled." http2=false address=[::]:9104
- 5.访问测试
[root@elk93 ~]# curl -s http://10.0.0.91:9104/metrics| wc -l
2573
[root@elk93 ~]#
- 6.Prometheus监控MySQL
[root@prometheus-server31 ~]# tail -5 /violet/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-mysql-exporter
static_configs:
- targets:
- 10.0.0.91:9104
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
- 7.验证Prometheus配置是否生效
http://10.0.0.31:9090/targets?search=
- 8.grafana导入模板ID
17320
18949
14057
7362
Prometheus监控zookeeper
- 1.修改zookeeper集群的配置信息
[root@elk91 ~]# vim /usr/local/zookeeper/conf/zoo.cfg
[root@elk91 ~]#
[root@elk91 ~]# tail -5 /usr/local/zookeeper/conf/zoo.cfg
# https://prometheus.io Metrics Exporter
metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
metricsProvider.httpHost=0.0.0.0
metricsProvider.httpPort=7000
metricsProvider.exportJvmInfo=true
[root@elk91 ~]#
[root@elk91 ~]# scp /usr/local/zookeeper/conf/zoo.cfg 10.0.0.92:/usr/local/zookeeper/conf/
[root@elk91 ~]# scp /usr/local/zookeeper/conf/zoo.cfg 10.0.0.93:/usr/local/zookeeper/conf/
- 2.重启zookeeper服务
[root@elk91 ~]# zkServer.sh restart
[root@elk92 ~]# zkServer.sh restart
[root@elk93 ~]# zkServer.sh restart
- 3.访问测试
http://10.0.0.91:7000/metrics
http://10.0.0.92:7000/metrics
http://10.0.0.93:7000/metrics
- 4.配置prometheus监控zookeeper
[root@prometheus-server31 ~]# tail -7 /violet/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-zk-exporter
static_configs:
- targets:
- 10.0.0.91:7000
- 10.0.0.92:7000
- 10.0.0.93:7000
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
- 5.验证配置是否生效
http://10.0.0.31:9090/targets?search=
- 6.grafana导入模板ID
10465
Prometheus监控kafka集群
- 1.启动kafka集群
[root@elk91 ~]# kafka-server-start.sh -daemon /usr/local/kafka_2.13-3.9.0/config/server.properties
[root@elk91 ~]# ss -ntl | grep 9092
LISTEN 0 50 [::ffff:10.0.0.91]:9092 *:*
[root@elk91 ~]#
[root@elk92 ~]# kafka-server-start.sh -daemon /usr/local/kafka_2.13-3.9.0/config/server.properties
[root@elk92 ~]# ss -ntl | grep 9092
LISTEN 0 50 [::ffff:10.0.0.92]:9092 *:*
[root@elk92 ~]#
[root@elk93 ~]# kafka-server-start.sh -daemon /usr/local/kafka_2.13-3.9.0/config/server.properties
[root@elk93 ~]# ss -ntl | grep 9092
LISTEN 0 50 [::ffff:10.0.0.93]:9092 *:*
[root@elk93 ~]#
- 2.下载kafka exporter
wget https://github.com/danielqsj/kafka_exporter/releases/download/v1.9.0/kafka_exporter-1.9.0.linux-amd64.tar.gz
- 3.解压软件包
[root@elk92 ~]# tar xf kafka_exporter-1.9.0.linux-amd64.tar.gz -C /usr/local/bin/ kafka_exporter-1.9.0.linux-amd64/kafka_exporter --strip-components=1
[root@elk92 ~]#
[root@elk92 ~]# ll /usr/local/bin/
total 24520
drwxr-xr-x 2 root root 4096 Mar 27 11:44 ./
drwxr-xr-x 14 root root 4096 Mar 18 14:38 ../
-rwxr-xr-x 1 1001 fwupd-refresh 25099148 Feb 17 11:04 kafka_exporter*
[root@elk92 ~]#
- 4.启动kafka exporter
[root@elk92 ~]# kafka_exporter --kafka.server=10.0.0.91:9092 --kafka.server=10.0.0.92:9092 --kafka.server=10.0.0.93:9092 --kafka.version="3.9.0"
- 5.访问kafka exporter的WebUI
http://10.0.0.92:9308/metrics
- 6.配置Prometheus监控kafka集群
[root@prometheus-server31 ~]# tail -5 /violet/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-kafka-exporter
static_configs:
- targets:
- 10.0.0.92:9308
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
- 7.验证配置是否生效
http://10.0.0.31:9090/targets?search=
- 8.grafana导入模板ID
12460
10122
prometheus监控nacos服务
参考链接:
https://nacos.io/docs/v2.4/manual/admin/monitor/
- 1.启动nacos集群
[root@elk91 ~]# /usr/local/nacos/bin/startup.sh
[root@elk92 ~]# /usr/local/nacos/bin/startup.sh
[root@elk93 ~]# /usr/local/nacos/bin/startup.sh
访问测试 :
http://10.0.0.93:8848/
- 2.修改nacos服务启用Metrics接口
[root@elk91 ~]# vim /usr/local/nacos/conf/application.properties
...
management.endpoints.web.exposure.include=prometheus,health
...
[root@elk91 ~]# scp /usr/local/nacos/conf/application.properties 10.0.0.92:/usr/local/nacos/conf/
[root@elk91 ~]# scp /usr/local/nacos/conf/application.properties 10.0.0.92:/usr/local/nacos/conf/
- 3.重启服务
[root@elk91 ~]# /usr/local/nacos/bin/shutdown.sh
[root@elk92 ~]# /usr/local/nacos/bin/shutdown.sh
[root@elk93 ~]# /usr/local/nacos/bin/shutdown.sh
[root@elk91 ~]# /usr/local/nacos/bin/startup.sh
[root@elk92 ~]# /usr/local/nacos/bin/startup.sh
[root@elk93 ~]# /usr/local/nacos/bin/startup.sh
- 4.访问nacos的WebUI
http://10.0.0.91:8848/actuator/prometheus
http://10.0.0.92:8848/actuator/prometheus
http://10.0.0.93:8848/actuator/prometheus
- 5.配置Prometheus监控nacos集群
[root@prometheus-server31 ~]# tail -8 /violet/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-nacos-exporter
metrics_path: "/actuator/prometheus"
static_configs:
- targets:
- 10.0.0.91:8848
- 10.0.0.92:8848
- 10.0.0.93:8848
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
- 6.验证Prometheus配置是否生效
http://10.0.0.31:9090/targets?search=
- 7.grafana导入模板ID
13221
Prometheus监控docker原生Metrics
参考链接:
https://docs.docker.com/reference/cli/dockerd/#daemon-metrics
- 1.停止docker
[root@elk93 ~]# systemctl stop docker
- 2.修改docker启动脚本启用Metrics监控指标
[root@elk93 ~]# cat /lib/systemd/system/docker.service
[Unit]
Description=violet linux Docker Engine
Documentation=https://docs.docker.com,https://www.oldboyedu.com
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd --metrics-addr 0.0.0.0:5200
[Install]
WantedBy=multi-user.target
[root@elk93 ~]#
[root@elk93 ~]# systemctl daemon-reload
[root@elk93 ~]#
[root@elk93 ~]# systemctl restart docker.service
[root@elk93 ~]#
[root@elk93 ~]# ss -ntl | grep 5200
LISTEN 0 4096 *:5200 *:*
[root@elk93 ~]#
- 3.访问docker的Metrics接口
5.访问docker的Metrics接口
http://10.0.0.93:5200/metrics
[root@node-exporter41 ~]# curl -s http://10.0.0.93:5200/metrics| wc -l
589
[root@node-exporter41 ~]#
- 4.prometheus监控docker服务
[root@prometheus-server31 ~]# tail -5 /violet /softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-docker-exporter
static_configs:
- targets:
- 10.0.0.93:5200
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
- 5.验证Prometheus配置是否生效
http://10.0.0.31:9090/targets?search=
- 6.grafana导入模板ID
9621
Prometheus基于cAdvisor监控容器
- 1.在docker节点拉取镜像
[root@elk92 ~]# docker pull gcr.io/cadvisor/cadvisor-amd64:v0.52.1
v0.52.1: Pulling from cadvisor/cadvisor-amd64
44cf07d57ee4: Already exists
8e1b64a25f57: Pull complete
9f163ef62c30: Pull complete
4f4fb700ef54: Pull complete
b7db0b79d658: Pull complete
Digest: sha256:2981fb05889903af160f67c3b26066ca063229a50f956fc62c9952b0299fc9c7
Status: Downloaded newer image for gcr.io/cadvisor/cadvisor-amd64:v0.52.1
gcr.io/cadvisor/cadvisor-amd64:v0.52.1
[root@elk92 ~]#
- 2.运行cAdvisor
[root@elk92 ~]# docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=18080:8080 \
--detach=true \
--name=cadvisor \
--privileged \
--device=/dev/kmsg \
gcr.io/cadvisor/cadvisor-amd64:v0.52.1
[root@elk92 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3857cc9ff34e gcr.io/cadvisor/cadvisor-amd64:v0.52.1 "/usr/bin/cadvisor -…" 2 minutes ago Up About a minute (healthy) 0.0.0.0:18080->8080/tcp, :::18080->8080/tcp cadvisor
[root@elk92 ~]#
[root@elk92 ~]# curl -s http://10.0.0.92:18080/metrics | wc -l
4885
[root@elk92 ~]#
- 3.访问cAdVisor的webUI测试
http://10.0.0.92:18080/containers/
- 4.配置Prometheus监控docker容器
[root@prometheus-server31 ~]# tail -6 /violet/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-cadVisor-exporter
static_configs:
- targets:
- 10.0.0.92:18080
- 10.0.0.93:18080
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
- 5.验证Prometheus配置是否生效
http://10.0.0.31:9090/targets?search=
- 6.grafana导入模板ID
11600
prometheus监控nginx
- 1 编译安装nginx
1.1 安装编译工具
apt -y install git wget gcc make zlib1g-dev build-essential libtool openssl libssl-dev
1.2 克隆nginx-module-vts模块
[root@elk91 ~]# env| grep http
https_proxy=http://10.0.0.1:7890
http_proxy=http://10.0.0.1:7890
[root@elk91 ~]#
[root@elk91 ~]# git clone https://github.com/vozlt/nginx-module-vts.git
Cloning into 'nginx-module-vts'...
remote: Enumerating objects: 1134, done.
remote: Counting objects: 100% (262/262), done.
remote: Compressing objects: 100% (87/87), done.
remote: Total 1134 (delta 206), reused 175 (delta 175), pack-reused 872 (from 2)
Receiving objects: 100% (1134/1134), 1.22 MiB | 935.00 KiB/s, done.
Resolving deltas: 100% (746/746), done.
[root@elk91 ~]#
1.3 下载nginx软件包
[root@elk91 ~]# wget http://nginx.org/download/nginx-1.27.3.tar.gz
1.4 解压nginx
[root@elk91 ~]# tar xf nginx-1.27.3.tar.gz
[root@elk91 ~]#
1.5 配置nginx
[root@elk91 ~]# cd nginx-1.27.3/
[root@elk91 nginx-1.27.3]#
[root@elk91 nginx-1.27.3]# ./configure --prefix=/violet/softwares/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --without-http_rewrite_module --with-http_stub_status_module --without-http_gzip_module --with-file-aio --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/root/nginx-module-vts
1.6 编译并安装nginx
make -j 2 && make install
1.7 修改nginx的配置文件
[root@elk91 nginx-1.27.3]# vim /violet/softwares/nginx/conf/nginx.conf
...
http {
vhost_traffic_status_zone;
upstream violet-promethues {
server 10.0.0.31:9090;
}
...
server {
...
location / {
root html;
# index index.html index.htm;
proxy_pass http://violet-promethues;
}
location /nginx_status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}
1.8 检查配置文件语法
[root@elk91 nginx-1.27.3]# /violet/softwares/nginx/sbin/nginx -t
nginx: the configuration file /violet/softwares/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /violet/softwares/nginx/conf/nginx.conf test is successful
[root@elk91 nginx-1.27.3]#
1.9 启动nginx
[root@elk91 nginx-1.27.3]# systemctl disable --now nginx
Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable nginx
Removed /etc/systemd/system/multi-user.target.wants/nginx.service.
[root@elk91 nginx-1.27.3]#
[root@elk91 nginx-1.27.3]# /violet/softwares/nginx/sbin/nginx
[root@elk91 nginx-1.27.3]#
[root@elk91 nginx-1.27.3]#
1.10 访问nginx的状态页面
http://10.0.0.91/status/
http://10.0.0.91/status/format/prometheus
1.11 修改Prometheus的配置文件
[root@prometheus-server31 ~]# tail -6 /violet/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-nginx-vts-modules
metrics_path: "/nginx_status/format/prometheus"
static_configs:
- targets:
- 10.0.0.91:80
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
1.12 导入模板ID
9785
2.安装nginx-vtx-exporter
1 下载nginx-vtx-exporter
[root@elk92 ~]# wget https://github.com/sysulq/nginx-vts-exporter/releases/download/v0.10.8/nginx-vtx-exporter_0.10.8_linux_amd64.tar.gz
2 解压软件包到path路径
[root@elk92 ~]# tar xf nginx-vtx-exporter_0.10.8_linux_amd64.tar.gz -C /usr/local/bin/ nginx-vtx-exporter
[root@elk92 ~]#
[root@elk92 ~]# ll /usr/local/bin/nginx-vtx-exporter
-rwxr-xr-x 1 1001 avahi 7950336 Jul 11 2023 /usr/local/bin/nginx-vtx-exporter*
[root@elk92 ~]#
3 运行nginx-vtx-exporter
[root@elk92 ~]# nginx-vtx-exporter -nginx.scrape_uri=http://10.0.0.91/nginx_status/format/json
2025/03/27 16:25:19 Starting nginx_vts_exporter (version=, branch=, revision=)
2025/03/27 16:25:19 Build context (go=go1.20.5, user=, date=)
2025/03/27 16:25:19 Starting Server at : :9913
2025/03/27 16:25:19 Metrics endpoint: /metrics
2025/03/27 16:25:19 Metrics namespace: nginx
2025/03/27 16:25:19 Scraping information from : http://10.0.0.91/nginx_status/format/json
4.访问nginx exporter的WebUI
http://10.0.0.92:9913/metrics
5.配置prometheus采集nginx数据
[root@prometheus-server31 ~]# tail -12 /oldboyedu/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-nginx-vts-modules
metrics_path: "/nginx_status/format/prometheus"
static_configs:
- targets:
- 10.0.0.91:80
- job_name: violet-linux-nginx-vtx-exporter
static_configs:
- targets:
- 10.0.0.92:9913
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
6.导入grafana模板
2949
Prometheus监控redis
- 1.拉取redis镜像
[root@elk92 ~]# docker pull redis:7.4.2-alpine
7.4.2-alpine: Pulling from library/redis
f18232174bc9: Already exists
16cd0457255f: Pull complete
fa05f5234346: Pull complete
4d03bd351ab9: Pull complete
4738865c5f32: Pull complete
927ba88b2847: Pull complete
4f4fb700ef54: Pull complete
4c7f0522bc7d: Pull complete
Digest: sha256:02419de7eddf55aa5bcf49efb74e88fa8d931b4d77c07eff8a6b2144472b6952
Status: Downloaded newer image for redis:7.4.2-alpine
docker.io/library/redis:7.4.2-alpine
[root@elk92 ~]#
- 2.部署redis服务
[root@elk92 ~]# docker run -d --network host --name redis-server redis:7.4.2-alpine
14f6cd2c24f0735bb5bfd189730898b15380101dd11516ad2af3b7776a33a75a
[root@elk92 ~]#
[root@elk92 ~]# ss -ntl | grep 6379
LISTEN 0 511 0.0.0.0:6379 0.0.0.0:*
LISTEN 0 511 [::]:6379 [::]:*
[root@elk92 ~]#
- 3.部署redis-exporter
wget https://github.com/oliver006/redis_exporter/releases/download/v1.69.0/redis_exporter-v1.69.0.linux-amd64.tar.gz
- 4.解压软件包
[root@elk93 ~]# tar xf redis_exporter-v1.69.0.linux-amd64.tar.gz -C /usr/local/bin/ redis_exporter-v1.69.0.linux-amd64/redis_exporter --strip-components=1
[root@elk93 ~]#
[root@elk93 ~]# ll /usr/local/bin/redis_exporter
-rwxr-xr-x 1 mysql fwupd-refresh 9638072 Mar 15 12:41 /usr/local/bin/redis_exporter*
[root@elk93 ~]#
- 5.运行redis exporter
[root@elk93 ~]# redis_exporter -redis.addr redis://10.0.0.92:6379
INFO[0000] Redis Metrics Exporter v1.69.0 build date: 2025-03-15-04:40:26 sha1: 71dbe37fb14a4ae2537c1790a239dc1e568ffba5 Go: go1.24.1 GOOS: linux GOARCH: amd64
INFO[0000] Providing metrics at :9121/metrics
- 6.访问redis exporter的WebUI
http://10.0.0.93:9121/metrics
- 7.配置Prometheus监控redis容器指标
[root@prometheus-server31 ~]# tail -7 /violet/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-redis-exporter
static_configs:
- targets:
- 10.0.0.93:9121
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
- 8.验证Prometheus配置是否生效
http://10.0.0.31:9090/targets?search=
- 9.grafana导入模板ID
763
14091
14615
Prometheus监控MongoDB
- 1.下载mongoDB镜像
[root@elk92 ~]# docker pull mongo:8.0.6-noble
8.0.6-noble: Pulling from library/mongo
5a7813e071bf: Already exists
cf12757b6444: Pull complete
20cfb5e922d1: Pull complete
d11968535d8a: Pull complete
c711ee204b1d: Pull complete
4fc65ca4253f: Pull complete
dacd77ad2ef6: Pull complete
5fa69bd3db1e: Pull complete
Digest: sha256:1697f35db2404e7ca87650fee7e5aab4188d2c2f3f0adbe211d060ec9b5799e8
Status: Downloaded newer image for mongo:8.0.6-noble
docker.io/library/mongo:8.0.6-noble
[root@elk92 ~]#
- 2.部署mongoDB服务
[root@elk92 ~]# docker run -d --name mongodb-server --network host mongo:8.0.6-noble
4b0f00dea78bb571c216c344984ced026c1210c94db147fdc9e32f549e3135de
[root@elk92 ~]#
[root@elk92 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b0f00dea78b mongo:8.0.6-noble "docker-entrypoint.s…" 2 seconds ago Up 1 second mongodb-server
[root@elk92 ~]#
[root@elk92 ~]# ss -ntl | grep 27017
LISTEN 0 4096 0.0.0.0:27017 0.0.0.0:*
[root@elk92 ~]#
- 3.下载MongoDB的exporter
https://github.com/percona/mongodb_exporter/releases/download/v0.43.1/mongodb_exporter-0.43.1.linux-amd64.tar.gz
- 4.解压软件包
[root@elk91 ~]# tar xf mongodb_exporter-0.43.1.linux-amd64.tar.gz -C /usr/local/bin/ mongodb_exporter-0.43.1.linux-amd64/mongodb_exporter --strip-components=1
[root@elk91 ~]#
[root@elk91 ~]# ll /usr/local/bin/mongodb_exporter
-rwxr-xr-x 1 1001 geoclue 20467864 Dec 13 20:10 /usr/local/bin/mongodb_exporter*
[root@elk91 ~]#
- 5.运行mongodb-exporter
[root@elk91 ~]# mongodb_exporter --mongodb.uri=mongodb://10.0.0.92:27017 --log.level=info --collector.dbstats
time=2025-03-27T09:56:34.382Z level=INFO source=tls_config.go:347 msg="Listening on" address=[::]:9216
time=2025-03-27T09:56:34.382Z level=INFO source=tls_config.go:350 msg="TLS is disabled." http2=false address=[::]:9216
[root@node-exporter41 ~]#
[root@node-exporter41 ~]# curl -s http://10.0.0.91:9216/metrics | wc -l
218
[root@node-exporter41 ~]#
- 6.验证mongoDB-exporter的WebUI
http://10.0.0.91:9216/metrics
- 7.配置Prometheus监控mongoDB容器
[root@prometheus-server31 ~]# tail -7 /violet/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-mongodb-exporter
static_configs:
- targets:
- 10.0.0.91:9216
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
- 8.验证Prometheus配置是否生效
http://10.0.0.31:9090/targets?search=
- 9.grafana导入模板ID
目前我没有发现好用的,你可以自行探索。
当然如果实在找不到,就只能自己定义Dashboard。
比如: "mongodb_up"
Prometheus监控MongoDB模块化管理机制
- 1.下载mongoDB镜像
[root@elk92 ~]# docker pull mongo:8.0.6-noble
8.0.6-noble: Pulling from library/mongo
5a7813e071bf: Already exists
cf12757b6444: Pull complete
20cfb5e922d1: Pull complete
d11968535d8a: Pull complete
c711ee204b1d: Pull complete
4fc65ca4253f: Pull complete
dacd77ad2ef6: Pull complete
5fa69bd3db1e: Pull complete
Digest: sha256:1697f35db2404e7ca87650fee7e5aab4188d2c2f3f0adbe211d060ec9b5799e8
Status: Downloaded newer image for mongo:8.0.6-noble
docker.io/library/mongo:8.0.6-noble
[root@elk92 ~]#
- 2.部署mongoDB服务
[root@elk92 ~]# docker run -d --name mongodb-server --network host mongo:8.0.6-noble
4b0f00dea78bb571c216c344984ced026c1210c94db147fdc9e32f549e3135de
[root@elk92 ~]#
[root@elk92 ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b0f00dea78b mongo:8.0.6-noble "docker-entrypoint.s…" 2 seconds ago Up 1 second mongodb-server
[root@elk92 ~]#
[root@elk92 ~]# ss -ntl | grep 27017
LISTEN 0 4096 0.0.0.0:27017 0.0.0.0:*
[root@elk92 ~]#
- 3.下载MongoDB的exporter
https://github.com/percona/mongodb_exporter/releases/download/v0.43.1/mongodb_exporter-0.43.1.linux-amd64.tar.gz
- 4.解压软件包
[root@elk91 ~]# tar xf mongodb_exporter-0.43.1.linux-amd64.tar.gz -C /usr/local/bin/ mongodb_exporter-0.43.1.linux-amd64/mongodb_exporter --strip-components=1
[root@elk91 ~]#
[root@elk91 ~]# ll /usr/local/bin/mongodb_exporter
-rwxr-xr-x 1 1001 geoclue 20467864 Dec 13 20:10 /usr/local/bin/mongodb_exporter*
[root@elk91 ~]#
- 5.运行mongodb-exporter
[root@elk91 ~]# mongodb_exporter --mongodb.uri=mongodb://10.0.0.92:27017 --log.level=info --collect-all
time=2025-03-28T01:15:56.128Z level=INFO source=tls_config.go:347 msg="Listening on" address=[::]:9216
time=2025-03-28T01:15:56.128Z level=INFO source=tls_config.go:350 msg="TLS is disabled." http2=false address=[::]:9216
INFO[0003] failed to get PBM configuration: get: mongo: no documents in result collector=pbm
- 6.验证mongoDB-exporter的WebUI
http://10.0.0.91:9216/metrics
[root@node-exporter41 ~]# curl -s http://10.0.0.91:9216/metrics | wc -l
12172
[root@node-exporter41 ~]#
- 7.配置Prometheus监控mongoDB容器
[root@prometheus-server31 ~]# tail -7 /violet/softwares/prometheus-2.53.4.linux-amd64/prometheus.yml
- job_name: violet-linux-mongodb-exporter
static_configs:
- targets:
- 10.0.0.91:9216
[root@prometheus-server31 ~]#
[root@prometheus-server31 ~]# curl -X POST http://10.0.0.31:9090/-/reload
[root@prometheus-server31 ~]#
- 8.验证Prometheus配置是否生效
http://10.0.0.31:9090/targets?search=
可以进行数据的查询,推荐使用: mongodb_dbstats_dataSize
- 9.grafana导入模板ID
16504
由于我们的MongoDB版本较为新,grafana的社区模板更新的并不及时,因此可能需要我们自己定制化一些Dashboard。
参考链接:
https://grafana.com/grafana/dashboards
Prometheus监控tomcat实战案例
- 1.下载Dockerfile
[root@elk93 ~]# wget http://192.168.16.253/Resources/Prometheus/Dockerfile-tomcat-exporter/Dockerfile-tomcat-exporter.zip
注意:也可以取docker官方镜像仓库取下载镜像,去docker镜像仓库直接搜tomcat-exporter即可通过docker pull拉取!
- 2.解压软件包
[root@elk93 ~]# mkdir /violet/dockerfile
[root@elk93 ~]#
[root@elk93 ~]# unzip Dockerfile-tomcat-exporter.zip -d /violet/dockerfile/
Archive: Dockerfile-tomcat-exporter.zip
inflating: /violet/dockerfile/build.sh
inflating: /violet/dockerfile/Dockerfile
inflating: /violet/dockerfile/metrics.war
inflating: /violet/dockerfile/server.xml
creating: /violet/dockerfile/libs/
inflating: /violet/dockerfile/libs/simpleclient-0.12.0.jar
inflating: /violet/dockerfile/libs/simpleclient_common-0.12.0.jar
inflating: /violet/dockerfile/libs/simpleclient_hotspot-0.12.0.jar
inflating: /violet/dockerfile/libs/simpleclient_servlet-0.12.0.jar
inflating: /violet/dockerfile/libs/simpleclient_servlet_common-0.12.0.jar
inflating: /violet/dockerfile/libs/tomcat_exporter_client-0.0.15.jar
creating: /violet/dockerfile/myapp/
inflating: /violet/dockerfile/myapp/1.png
inflating: /violet/dockerfile/myapp/index.jsp
[root@elk93 ~]#
- 3.编译安装包
[root@elk93 ~]# cd /violet/dockerfile/
[root@elk93 dockerfile]#
[root@elk93 dockerfile]# ll
total 36
drwxr-xr-x 4 root root 4096 Mar 28 17:39 ./
drwxr-xr-x 5 root root 4096 Mar 28 17:39 ../
-rw-r--r-- 1 root root 73 Apr 2 2024 build.sh
-rw-r--r-- 1 root root 503 Apr 2 2024 Dockerfile
drwxr-xr-x 2 root root 4096 Mar 28 17:35 libs/
-rw-r--r-- 1 root root 3407 Apr 2 2024 metrics.war
drwxr-xr-x 2 root root 4096 Mar 28 17:35 myapp/
-rw-r--r-- 1 root root 7604 Apr 2 2024 server.xml
[root@elk93 dockerfile]#
[root@elk93 dockerfile]#
[root@elk93 dockerfile]# chmod +x build.sh
[root@elk93 dockerfile]# ./build.sh
- 4.运行容器
[root@elk93 dockerfile]# docker run -d -p 99:8080 --name tomcat-exporter harbor.vionletarchitect.top/tomcat/tomcat-app:v2
dabce05b52fa3ed31ed490443465086ae587e29b9c8b284a3d14db20bcf7b7a0
[root@elk93 dockerfile]#
- 5.访问测试
http://10.0.0.93:99/myapp/
http://10.0.0.93:99/metrics/
- 6.Prometheus监控tomcat exporter
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]# vim prometheus.yml
...
- job_name: "violet-linux-tomcat-exporter"
static_configs:
- targets:
- "10.0.0.93:99"
- 7.启动Prometheus server
[root@prometheus-server31 prometheus-2.53.4.linux-amd64]# ./prometheus
- 8.展示数据
参考链接:
https://github.com/nlighten/tomcat_exporter/blob/master/dashboard/example.json