试用 prometheus

本贴最后更新于 2287 天前,其中的信息可能已经天翻地覆

安装

docker 版本

参考自 prometheus docker

查询

docker search prometheus
NAME                                          DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
prom/prometheus                                                                               357                                     [OK]
basi/prometheus-swarm                         A sample image that can be used as a base ...   6                                       [OK]

下载

docker pull prom/prometheus

启动

默认参数启动

docker run -p 9090:9090 --name prometheus prom/prometheus

自定义参数启动

编译默认配置文件

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

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

# 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'

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

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

使用指定配置文件启动

docker run -p 9090:9090 --log-driver none -v /path/to/prometheus/etc/:/etc/prometheus/ -v /path/to/prometheus/data/:/prometheus/ -v /etc/localtime:/etc/localtime --name prometheus prom/prometheus

完整配置项见这里的文档.

非 docker 版本

主要参考自官方新手入门文档

  1. 下载

  1. 安装

  2. 启动

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

内置界面

其默认主页为

http://localhost:9090

metrics 信息

http://localhost:9090/metrics

可以看到收集到的数据的 metrics 信息

例如 prometheus_target_interval_length_seconds 为主动回收数据间隔时间.

自定义图表

http://localhost:9090/graph

可以自定义图表

示例:

  1. 主动回收数据时间

prometheus_target_interval_length_seconds

  1. 99% 的主动回收数据时间
    prometheus_target_interval_length_seconds{quantile="0.99"}

  2. 回收次数
    count(prometheus_target_interval_length_seconds)

数据回收

产生随机示例数据

# Fetch the client library code and compile example.
git clone https://github.com/prometheus/client_golang.git
cd client_golang/examples/random
go get -d
go build

# Start 3 example targets in separate terminals:
./random -listen-address=:8080
./random -listen-address=:8081
./random -listen-address=:8082

可以在 http://localhost:8080/metrics, http://localhost:8081/metrics, 和 http://localhost:8082/metrics 中看到对应的 metrics 数据.

配置 Prometheus 来监控示例数据

我们将把这三个端点(endpoint)的数据进行采集,前两个端点进入分组 production 中,后一个端点进入分组 canary 中。

修改配置文件

修改 prometheus.yml 文件,增加新的采集任务 example-random,具体内容如下:

scrape_configs:
  - job_name:       'example-random'

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

    static_configs:
      - targets: ['localhost:8080', 'localhost:8081']
        labels:
          group: 'production'

      - targets: ['localhost:8082']
        labels:
          group: 'canary'

监控数据的二次处理

略,见 Configure rules for aggregating scraped data into new time series

其它

Push Gateway

Push Gateway

Grafana

Grafana

FAQ

  • 默认路径为 http://localhost:9090,如何设置相对路径,比如为 http://localhost:9090/prometheus

启动时增加参数

./prometheus --web.external-url=http://localhost:9090/prometheus

参考

  • ClickHouse
    16 引用 • 1 回帖
  • Prometheus
    20 引用 • 8 回帖
  • Java

    Java 是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由 Sun Microsystems 公司于 1995 年 5 月推出的。Java 技术具有卓越的通用性、高效性、平台移植性和安全性。

    3167 引用 • 8207 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...