Prometheus监控Logstash

这里只是对prometheus监控logstash的配置过程做个记录,方便以后查阅。

1.安装go环境

1
sudo yum install -y go

2.下载logstash_exporter

github地址:https://github.com/BonnierNews/logstash_exporter

1
2
go get -u github.com/BonnierNews/logstash_exporter
mv -f go logstash_exporter

3.配置logstash开放指定端口

启动logstash的时候,使用命令 –http.port=9600 指定http端口。因为logstash启动的时候默认是随机使用端口的,但是每一次重启之后端口会发生变化,为了使logstash能有效的被区分、起别名,使用指定端口是最好的选择。

1
/work/admin/logstash-6.5.3-kafka/bin/logstash -f /work/admin/logstash-6.5.3-kafka/conf.d/ --http.port=9600

4.启动logstash_exporter

1
/work/admin/logstash_exporter/bin/logstash_exporter --web.listen-address :9198 --logstash.endpoint http://localhost:9600

默认端口9198

5.prometheus配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- job_name: 'logstash'
static_configs:
- targets: ['192.168.5.247:9100']
labels: {cluster: 'product',type: 'basic',env: 'logstash',job: 'logstash1',export: 'logstash1'}
- targets: ['192.168.5.247:9198']
labels: {cluster: 'product',type: 'middle',env: 'logstash',job: 'logstash1',coures: "logstash_kafka",export: 'logstash_kafka_exporter'}
- targets: ['192.168.5.247:9199']
labels: {cluster: 'product',type: 'middle',env: 'logstash',job: 'logstash1',coures: "logstash_es",export: 'logstash_es_exporter'}
- targets: ['192.168.5.247:9196']
labels: {cluster: 'product',type: 'middle',env: 'logstash',job: 'logstash1',coures: "xy_logstash_kafka",export: 'xy_logstash_kafka_exporter'}
- targets: ['192.168.5.247:9197']
labels: {cluster: 'product',type: 'middle',env: 'logstash',job: 'logstash1',coures: "xy_logstash_es",export: 'xy_logstash_es_exporter'}
- targets: ['192.168.4.59:9100']
labels: {cluster: 'product',type: 'basic',env: 'logstash',job: 'logstash2',export: 'logstash2'}
- targets: ['192.168.4.59:9198']
labels: {cluster: 'product',type: 'middle',env: 'logstash',job: 'logstash2',coures: "logstash_kafka",export: 'logstash_kafka_exporter'}
- targets: ['192.168.4.59:9199']
labels: {cluster: 'product',type: 'middle',env: 'logstash',job: 'logstash2',coures: "logstash_es",export: 'logstash_es_exporter'}

重启prometheus

如果开启了api管理功能,可以如下方式热加载配置

1
curl -X POST http://127.0.0.1:9090/-/reload

6.grafana出图

推荐使用2525
效果如下
image-20191214174936115

-------------本文结束感谢您的阅读-------------