安装请看https://blog.51cto.com/liuqs/2027365 ,最好是对应的版本组件,否则可能会有差别。
(一)prometheus + grafana + alertmanager 配置主机监控
(二)prometheus + grafana + alertmanager 配置Mysql监控
(三)prometheus + grafana + alertmanager 配置Redis监控
(四)prometheus + grafana + alertmanager 配置Kafka监控
(五)prometheus + grafana + alertmanager 配置ES监控
(四) prometheus + grafana + alertmanager 配置Kafka监控
一. kafka_exporter安装(登陆到prometheus服务器,prometheus grafana alertmanager在同一台服务器上)
如果是直接搭建的kafka服务器,可以参考上一章的内容。
这里以云kafka来安装与配置,当然直接搭建的服务器kafka也可以使用这种方法。
A. 下载kafka_exporter安装包(下载地址:https://pan.baidu.com/s/17FmukqimaMU9skKz3yzheg ),然后解压到/data/monitor/下。
B. 然后在cd /data/monitor/kafka_exporter/scripts 下,创建每个kafka的监控启动脚本,cat ba_kafka_19002.sh,其它的类似。
nohup /data/monitor/kafka_exporter/bin/kafka_exporter --kafka.server=ukafka-aqtjnc-1-bj11.service.ucloud.cn:9092 --web.listen-address=":19002" >> /data/monitor/kafka_exporter/log/19002_ba_kafka.log 2>&1 &
C. 然后cd /data/monitor/kafka_exporter 下,sh start.sh,查看端口是否监听或者查看进行是否启动
二. prometheus配置
1. vim /data/monitor/prometheus/conf/prometheus.yml
A. 将mysqld_exporter的配置增加到prometheus.yml文件中,vim /data/monitor/prometheus/conf/prometheus.yml
global:
# Server端抓取数据的时间间隔
scrape_interval: 1m
# 评估报警规则的时间间隔
evaluation_interval: 1m
# 数据抓取的超时时间
scrape_timeout: 20s
# 加全局标签
#external_labels:
# monitor: "hk"
# 连接alertmanager
alerting:
alertmanagers:
- static_configs:
- targets: ["localhost:9093"]
# 告警规则
rule_files:
- /data/monitor/prometheus/conf/rule/*.yml
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# 监控prometheus本机
- job_name: 'prometheus'
scrape_interval: 15s
static_configs:
- targets: ['10.8.53.218:9090']
# 监控指定主机
- job_name: 'node_resources'
scrape_interval: 1m
static_configs:
file_sd_configs:
- files:
- /data/monitor/prometheus/conf/node_conf/node_host_info.json
honor_labels: true
# mysql采集器
- job_name: 'mysql_global_status'
scrape_interval: 60s
static_configs:
file_sd_configs:
- files:
- /data/monitor/prometheus/conf/node_conf/node_mysql_info.json
# redis采集器
- job_name: 'redis_resources'
scrape_interval: 60s
static_configs:
file_sd_configs:
- files:
- /data/monitor/prometheus/conf/node_conf/node_redis_info.json
# kafka
- job_name: 'kafka'
scrape_interval: 60s
metrics_path: '/metrics'
static_configs:
file_sd_configs:
- files:
- /data/monitor/prometheus/conf/node_conf/node_kafka_info.json
2. vim /data/monitor/prometheus/conf/node_conf/node_kafka_info.json
[
{
"labels": {
"server": "ukafka-aqtjnc-1-bj11.service.ucloud.cn:9092",
"kafkaversion": "0.10.2.1",
"alias": "ba_kafka"
},
"targets": [
"localhost:19002"
]
},
{
"labels": {
"server": "ukafka-3bjf9p-1-hb01.service.ucloud.cn:9092",
"kafkaversion": "0.10.2.1",
"alias": "other_kafka"
},
"targets": [
"localhost:19003"
]
}
]
2. 然后cd /data/monitor/prometheus下, sh reload.sh
注意:会有一些图表会没有数据,我们是直接对接ucloud的api用脚本生成的数据。
三. 配置grafana
1. 下载kafka监控模板,下载地址:https://pan.baidu.com/s/1m6ANngg2WJcc1UjwHvT-Yw
2. 如何导入请参考配置主机监控的文章中的2.配置grafana中的h至l步骤( https://blog.51cto.com/liuqs/2391282 )
4. 配置alertmanager
A. 在prometheus配置规则,cat /data/monitor/prometheus/conf/rule/kafka.yml ,下面是文件内容,然后重启prometheus,cd /data/monitor/prometheus && sh reload.sh
未完待续。。。。。