grafana/Prometheus/Kafka搭建记录

不打扰是莪最后的温柔 提交于 2020-01-20 21:23:16

Prometheus用于获取并存储Kafka监控数据,然后grafana获取(不存储监控数据)Prometheus监控数据来进行页面展示。

数据流向:
Kafka(端口9092) --> Prometheus(端口9090) --> grafana(端口3000)

本文基于centos7
先安装docker环境

yum install epel-release -y
yum install docker -y
yum install java -y
yum install wget -y

1. Kafka安装

参照官网http://kafka.apache.org/quickstart
安装完后需要下载kafka_exporter并启动

wget https://github.com/danielqsj/kafka_exporter/releases/download/v1.2.0/kafka_exporter-1.2.0.linux-amd64.tar.gz
tar zxvf kafka_exporter-1.2.0.linux-amd64.tar.gz
cd kafka_exporter-1.2.0.linux-amd64
./kafka_exporter --kafka.server=10.10.120.42:9092 #ip为kafka的ip,这里是本机ip

2. Prometheus安装

docker pull prom/prometheus
docker run -d --name=prom -p 9090:9090 docker.io/prom/prometheus

prometheus.yml文件

global:
  scrape_interval: 15s
  scrape_timeout: 10s
  evaluation_interval: 15s
alerting:
  alertmanagers:
  - static_configs:
    - targets: []
    scheme: http
    timeout: 10s
    api_version: v1
scrape_configs:
- job_name: prometheus
  honor_timestamps: true
  scrape_interval: 15s
  scrape_timeout: 10s
  metrics_path: /metrics
  scheme: http
  static_configs:
  - targets:
    - localhost:9090  #Prometheus端口

- job_name: kafka
  static_configs:
  - targets:
    - 10.10.120.42:9308  #kafka_exporter端口

要把这个配置文件修改后拷贝到Prometheus镜像里面去,可用docker cp命令。

docker cp prom:/etc/prometheus/prometheus.yml ./
修改后
docker cp prometheus.yml prom:/etc/prometheus/
然后重启container就行

这时候访问Prometheus就可以看到各项监控数据了。
Prometheus.png

3. grafana

docker拉取graafana官方镜像跑起来,然后安装Prometheus插件即可。非难点,有时间补充。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!