Prometheus 入门(二):Prometheus 安装与配

2019-06-26  本文已影响0人  星光下的胖子
一、下载 Prometheus

从Prometheus 官网 https://prometheus.io/download/ 下载 Prometheus 安装包 prometheus-2.10.0.linux-amd64.tar.gz,并解压:

tar xvfz prometheus-*.tar.gz
cd prometheus-*

(注意:启动 Prometheus 之前,需要配置相应的配置文件。)

二、配置 Prometheus 配置文件,使 Prometheus 监控其自身

Prometheus server 除了可以拉取 jobs/exporters 上的 metric,还可以从其他的 Prometheus server(包括自己) 上拉取 metric。虽然在实践中 Prometheus server 收集自身的数据并没有太大用处,但这是一个很好的实例演示,以便我们更好的了解 Prometheus。

添加 prometheus.yml 配置文件,配置内容如下:

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
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'.

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
    - targets: ['localhost:9090']

有关 Prometheus 配置选项的完整规范,可参阅「配置文档」。简单的配置介绍如下:

三、启动 Prometheus

需要使用新的配置文件来启动 Prometheus,需要切换到包含 Prometheus 二进制文件的目录下,并执行命令:

# Start Prometheus.
# By default, Prometheus stores its database in ./data (flag --storage.tsdb.path).
./prometheus --config.file=prometheus.yml

如果是 Windows 系统,那么启动 Prometheus 的命令如下:

start ./prometheus.exe --config.file=prometheus.yml

浏览器访问 Prometheus 主页 http://localhost:9090,启动成功,如下图所示:

Prometheus 的状态信息:http://localhost:9090/status

Prometheus 的监控指标:http://localhost:9090/metrics

四、查看 Prometheus 的监控数据

1)通过 Prometheus 的内置 表达式浏览器 来查看监控数据。
我们以 prometheus_target_interval_length_seconds 指标为例,来进行演示:
(http://localhost:9090/metrics 可获取 Prometheus 监控的所有 metrics。)

prometheus_target_interval_length_seconds
prometheus_target_interval_length_seconds{quantile="0.99"}
count(prometheus_target_interval_length_seconds)
count(prometheus_target_interval_length_seconds{quantile="0.99"})

要了解更多关于 表达式 语法的信息,可参阅「表达式说明文档」

2)使用「图形界面」来查看监控数据。

rate(prometheus_tsdb_head_chunks_created_total[1m])
上一篇 下一篇

猜你喜欢

热点阅读