Prometheus, a Cloud Native Computing Foundation project, is a systems and service monitoring system.
Prometheus的主要特征:
- 多维数据模型(由度量标准名称和键/值维度集定义的时间序列)
- 灵活的查询语言,以利用此维度
- 不依赖于分布式存储;单个服务器节点是自治的
- 时间序列集合通过HTTP上的拉模型进行
- 通过中间网关支持推送时间序列
- 通过服务发现或静态配置发现目标
- 支持多种图形和仪表板
- 支持分层和水平联合
Prometheus有多种安装文件。
二进制文件
Prometheus官方提供了支持多种 OS 的二进制安装文件,下载地址 官网的download section。-
docker镜像
在 github 上搜索镜像 Quay.io 或者 Docker Hub。
启动容器的命令
$ docker run --name prometheus -d -p 127.0.0.1:9090:9090 -v /{mydir}/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
提供源码自行编译构建。
......
配置文件示例
github上的 prometheus.yml 示例
Prometheus官方详细说明
# 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).
# Alertmanager configuration,比如prometheus-alertmanager的url。
alerting:
alertmanagers:
- static_configs:
- targets:
['10.240.0.5:9093']
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
# 首次加载,之后根据evaluation_interval设定的值周期性读取加载
rule_files:
- /etc/prometheus/alerting_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'.
static_configs:
- targets: ['10.240.0.5:9090']
# 关银保数据库埋点
- job_name: 'db_auth'
static_configs:
- targets: ['10.240.0.5:9160']
labels:
group: 'pro-environment'
metrics_path: '/metrics'
scheme: http
# Sets the `Authorization` header on every scrape request with the
# configured username and password.
# password and password_file are mutually exclusive.
#basic_auth:
username: 'admin'
password: 'admin'
#[ password_file: <string> ]
其中的报警规则的配置示例见下面链接
alerting_rules.yml
groups:
- name: gyb-database-alert-rules
rules:
# db-auth告警名称
- alert: DataBase-auth-Down
# 告警的判定条件,参考Prometheus高级查询来设定
expr: oracledb_up{job="db_auth"} < 1
# 满足告警条件持续时间多久后,才会发送告警
for: 1m
labels: #标签项
team: gyb
annotations: # 解析项,详细解释告警信息
summary: "{{$labels.instance}}: auth数据库Down."
description: "{{$labels.instance}}: job {{$labels.job}} has been down."
本文翻译自 github上的 Prometheus 主页.