promutheus 與nginx 對比
優(yōu)勢
- 安裝簡單
- 時序數(shù)據(jù)庫茂嗓,對于監(jiān)控場景,以時間維度查詢性能高
- 告警條件多樣化
多維度數(shù)據(jù)模型庶柿。
靈活的查詢語言。
不依賴分布式存儲徽鼎,單個服務器節(jié)點是自主的。
通過基于HTTP的pull方式采集時序數(shù)據(jù)弹惦。
可以通過中間網(wǎng)關進行時序列數(shù)據(jù)推送否淤。
通過服務發(fā)現(xiàn)或者靜態(tài)配置來發(fā)現(xiàn)目標服務對象。
支持多種多樣的圖表和界面展示棠隐,比如Grafana等石抡。
promutheus概念與配置
時間序列:
- 指標名稱
- 標簽
- 時間戳
- 樣本值
表達式:
<metric name>{<label name>=<label value>, ...}
例如:
api_http_requests_total{method="POST", handler="/messages"}
指標類型
計數(shù)器(counter),從開始監(jiān)控助泽,到指定時間點啰扛,單調(diào)遞增,只增不減嗡贺;
儀表盤(gauge)隐解,瞬時值,例如溫度诫睬;
直方圖(Histogram)煞茫,按時間區(qū)間統(tǒng)計;
匯總(Summary)
docker 方式啟動
docker run -p 9090:9090 -v /prometheus-data \
prom/prometheus --config.file=/prometheus-data/prometheus.yml
springboot項目暴露監(jiān)控信息
讓 springboot 輸出 prometheus 支持的監(jiān)控信息格式;
添加依賴:
image
開啟監(jiān)控
image
image
在promutheus 的配置文件 /etc/alertmanager/alertmanager.yml
中配置要監(jiān)控的應用
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: ['localhost:9090']
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prod_k12'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
metrics_path: '/prometheus'
static_configs:
- targets: ['ip:port']
- job_name: 'prod_ngx'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
metrics_path: '/status/format/prometheus'
static_configs:
- targets: ['ip:port']
promutheus 通過 eureka 動態(tài)發(fā)現(xiàn)服務并進行監(jiān)控
在eureka server 中加入依賴
<!-- prometheus 服務發(fā)現(xiàn)用 -->
<dependency>
<groupId>at.twinformatics</groupId>
<artifactId>eureka-consul-adapter</artifactId>
<version>1.0.1</version>
</dependency>
配置 promutheus.yml
image
grafana配置
在官網(wǎng) 搜索 模板 Spring Boot Statistics
添加
alertmanager 郵件告警配置
在 prometheus.yml
中加入告警配置
image
告警規(guī)則文件 alert_rules.yml
內(nèi)容
image
alertmanager.yml
文件 內(nèi)容:
image