# Prometheus

# 一、安装

# 1.1 下载安装包

官方 (opens new window) 最新安装包prometheus-2.30.0.linux-amd64.tar.gz

[root@master01 opt]# tar -xzf ~/prometheus-2.30.0.linux-amd64.tar.gz
[root@master01 opt]# mv prometheus-2.30.0.linux-amd64/ prometheus-2.30.0
1
2

# 1.2 修改配置文件 prometheus.yml

以添加ClickHouse监控配置为例












 
 
 
 

[root@master01 prometheus-2.30.0]# vim  prometheus.yml
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["master01:9090"]

 #添加 ClickHouse 监控配置
 - job_name: clickhouse-1
   static_configs:
     - targets: ['master01:9363']
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  1. global 配置块:控制 Prometheus 服务器的全局配置
    scrape_interval:配置拉取数据的时间间隔,默认为1分钟。
    evaluation_interval:规则验证(生成alert)的时间间隔,默认为1分钟。
  2. rule_files 配置块:规则配置文件
  3. scrape_configs 配置块:配置采集目标相关, prometheus 监视的目标。Prometheus 自身 的运行信息可以通过 HTTP 访问,所以 Prometheus 可以监控自己的运行数据。
    job_name:监控作业的名称
    static_configs:表示静态目标配置,就是固定从某个target拉取数据
    targets:指定监控的目标,其实就是从哪儿拉取数据。Prometheus 会从http://master01:9090/metrics 上拉取数据。

Prometheus 是可以在运行时自动加载配置的。启动时需要添加:--web.enable-lifecycle

# 1.3 启动

[root@master01 prometheus-2.30.0]# nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &
1

在前端页面访问http://master01:9090/targets,看到prometheus (1/1 up)表明服务启动成功

更新时间: 9/26/2021, 6:34:35 PM