Prometheus + Grafana +中间件 Exporters 监控

3,430 阅读2分钟

上一篇文章讲了我给公司写了个 shell 脚本安装中间件,现在需要监控这些脚本,于是我用到了如标题的方案来监控中间件指标,操作过程记录如下。

PS:这里主要是对于中间件 exporter 的引入过程,详细的监控配置我会后面在写一份。

Prometheus

安装并使用 Prometheus 来收集服务器数据

wget prometheus-2.13.1.linux-amd64.tar.gz
tar -zxvf prometheus-2.13.1.linux-amd64.tar.gz
cd prometheus-2.13.1.linux-amd64
# 创建数据目录、日志目录
mkdir data
mkdir logs
# 后台启动 Prometheus 并指定数据目录、开启配置热加载功能
nohup ./prometheus --storage.tsdb.path="data/" --web.enable-lifecycle > logs/prometheus.log 2>&1 &

访问 http://192.168.1.19:9090/ 安装成功之后页面如下:

image.png

Grafana

安装并使用 Grafana 来展示 Prometheus 收集的数据

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.3.3.linux-amd64.tar.gz
tar -zxvf grafana-enterprise-8.3.3.linux-amd64.tar.gz
cd grafana-8.3.3/
# 创建数据目录
mkdir logs
# 后台启动 Grafana
nohup ./bin/grafana-server  > logs/grafana.log 2>&1 &

访问 http://192.168.1.19:3000/ 安装成功后页面如下:(默认账号密码:admin/admin)

image.png

Grafana 配置使用 Prometheus 数据源和图表

image.png image.png image.png image.png image.png image.png

经过简单配置便可使用 Grafana 展示相关数据。后面会为 Prometheus 配置若干组件监控中间件,配置完成后可以在 Metrices browser 中看到与中间件相关的指标,略加配置便可展示中间件监控信息。

中间件的 Exporter

使用若干组件来为 Prometheus 收集数据

redis exporter

wget https://github.com/oliver006/redis_exporter/releases/download/v1.5.2/redis_exporter-v1.5.2.linux-amd64.tar.gz
tar xf redis_exporter-v1.5.2.linux-amd64.tar.gz
cd redis_exporter-v1.5.2.linux-amd64/
# 创建日志目录
mkdir logs
# 后台启动并配置 redis 地址
nohup ./redis_exporter -redis.addr=redis://192.168.1.19:6379 > logs/redis.log 2>&1 &

通过url 可访问 redis metrics : http://192.168.1.19:9121/metrics

redis 指标参考:github.com/oliver006/r…

image.png

配置 Prometheus job

vim prometheus-2.13.1.linux-amd64/prometheus.yml
# 添加 job
scrape_configs:
  - job_name: 'redis'
    static_configs:
     - targets: ['192.168.1.19:9121']

刷新 Prometheus 配置:curl -XPOST http://192.168.1.19:9090/-/reload

指标参考:github.com/oliver006/r…

zookepper exporter

wget https://github.com/carlpett/zookeeper_exporter/releases/download/v1.1.0/zookeeper_exporter
chmod 755 zookeeper_exporter
# 查看启动参数
./zookeeper_exporter -h
# 启动监控
./zookeeper_exporter -zookeeper="localhost:2181"

访问链接:http://192.168.1.19:9141/metrics

配置 Prometheus job

vim prometheus-2.13.1.linux-amd64/prometheus.yml
# 添加 job
scrape_configs:
  - job_name: 'zookeeper'
    static_configs:
     - targets: ['192.168.1.19:9141']

刷新 Prometheus 配置:curl -XPOST http://192.168.1.19:9090/-/reload

zookepper exporter git 地址:github.com/dabealu/zoo…

kafka exporter

wget https://link.zhihu.com/?target=https%3A//github.com/danielqsj/kafka_exporter/releases/download/v1.2.0/tar -zxvf kafka_exporter-1.2.0.linux-amd64.tar.gz
cd kafka_exporter-1.2.0.linux-amd64/
nohup ./kafka_exporter --kafka.server=192.168.1.19:9092 --kafka.version=1.1.0 --log.level=info > kafka_exporter.log 2>&1 &

访问链接:http://192.168.1.19:9308/metrics

配置 Prometheus job

vim prometheus-2.13.1.linux-amd64/prometheus.yml
# 添加 job
scrape_configs:
  - job_name: 'kafka'
    static_configs:
     - targets: ['192.168.1.19:9308']

刷新 Prometheus 配置:curl -XPOST http://192.168.1.19:9090/-/reload

指标含义参考:github.com/danielqsj/k…

RocketMQ exporter

git clone https://github.com/apache/rocketmq-exporter
cd rocketmq-exporter
mvn clean install
nohup java -jar rocketmq-exporter-0.0.2-SNAPSHOT.jar --rocketmq.config.namesrvAddr="192.168.1.19:9876"  > logs/rocketmq_exporter.log 2>&1 &

访问链接:http://192.168.1.19:5557/metrics

配置 Prometheus job

vim prometheus-2.13.1.linux-amd64/prometheus.yml
# 添加 job
scrape_configs:
  - job_name: 'rocketmq'
    static_configs:
     - targets: ['192.168.1.19:5557']

刷新 Prometheus 配置:curl -XPOST http://192.168.1.19:9090/-/reload

指标含义参考:github.com/apache/rock…

Nacos exporter

# 修改 Nacos 配置
vim application.properties
# 开启下面的配置项
management.endpoints.web.exposure.include=*

重启 nacos,访问链接:http://192.168.1.19:8848/nacos/actuator/prometheus

配置 Prometheus job

vim prometheus-2.13.1.linux-amd64/prometheus.yml
# 添加 job
scrape_configs:
  - job_name: 'nacos'
    metrics_path: '/nacos/actuator/prometheus'
    static_configs:
    - targets: ['192.168.1.19:8848']

刷新 Prometheus 配置:curl -XPOST http://192.168.1.19:9090/-/reload
指标项含义参考:nacos.io/zh-cn/docs/…