今天使用 kafka_exporter 采集,因为阿里云云端 Kafka, 只有k8s集群容器上才有 Jmx agent 采集接口
[ -d "/data" ] || mkdir /data
[ ! -d "/data/kafka_exporter" ] || exit 1
cd /usr/local/src
wget https://github.com/danielqsj/kafka_exporter/releases/download/v1.7.0/kafka_exporter-1.7.0.linux-amd64.tar.gz
tar -zxvf kafka_exporter-1.7.0.linux-amd64.tar.gz
mv kafka_exporter-1.7.0.linux-amd64 /data/kafka_exporter
cat >> /lib/systemd/system/kafka_exporter.service <<EOF
[Unit]
Description=kafka_exporter
After=local-fs.target network-online.target network.target
Wants=local-fs.target network-online.target network.target
[Service]
ExecStart=/data/kafka_exporter/kafka_exporter --kafka.server=1.1.1.1:9092
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable kafka_exporter
systemctl start kafka_exporter
systemctl status kafka_exporter
root@monitor-1:/data/monitor/prometheus# cat prometheus.yaml
...略
# Kafka消息队列相关
- job_name: 'Kafka消息队列'
static_configs:
file_sd_configs:
- refresh_interval: 30s
files:
- "vhosts/kafka/*.json"
root@monitor-1:/data/monitor/prometheus# pwd
/data/monitor/prometheus
root@monitor-1:/data/monitor/prometheus# cat vhosts/kafka/saas.json
[
{
"targets": ["2.2.2.2:9308"],
"labels": {
"label": "xxx使用",
"account": "account@xxx.com",
"cloud": "xxx云",
"instance": "1.1.1.1:9092" # Kafka 不在本地,覆盖 instance
}
}
]
./promtool check config prometheus.yml
curl -XPOST localhost:8090/-/reload