「Prometheus」- 服务部署

快速开始(=> INTRODUCTION/First steps)

First steps | Prometheus
PROMETHEUS/Getting started

快速开始 01

官方 INTRODUCTION/First steps 文档,展示如何快速开始,这里不再赘述细节;

配置文件:

global:
  scrape_interval:     15s                                                      # 每 15 秒,进行一次抓取
  evaluation_interval: 15s                                                      # 每 15 秒,执行 rule 定义

rule_files:                                                                     # 这里 rule 定义为空
  # - "first.rules"
  # - "second.rules"

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']                                             # 默认抓取 Prom 自身暴露的指标;

运行服务:

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

指标格式(http://localhost:9090/metrics):

...
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 1
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0

执行查询(http://localhost:9090/graph
通过 Graph 标签能够显示图示;

如果需要监控更多指标或其他服务,需要程序本身提供 http/metrics 接口,或者其他 Exporter 程序;

快速开始 02

官方 PROMETHEUS/Getting started 文档,展示更加详细的示例,及更多的概念;

1)常规指标抓取;
2)通过 labels 配置,为 Instance 添加自定义标签;
3)通过 rule_files 配置,对指标进行聚合;

系统集成(=> OPERATING/Integrations)

Integrations | Prometheus

1)文件服务发现
2)远端存储;
3)告警接收;
4)Prom 的管理;
5)还有部分其他集成工具;