Prometheus是一個獨立的開源監控系統。其組成主要有時序數據庫、數據採集、數據查詢(PromQL查詢語言)和報警。
先看一下Prometheus結構圖
前端
數據採集兩種方式:node
告警規則須要在Prometheus配置文件中配置mysql
原文檔linux
配置文件定義了抑制規則,通知路由和通知接收者。
用以下命令查看全部可配置標籤:web
alertmanager -h
使用目標配置文件啓動Alertmanagersql
./alertmanager --config.file=simple.yml
route匹配數據庫
# The root route with all parameters, which are inherited by the child # routes if they are not overwritten. route: receiver: 'default-receiver' group_wait: 30s group_interval: 5m repeat_interval: 4h group_by: [cluster, alertname] # All alerts that do not match the following child routes # will remain at the root node and be dispatched to 'default-receiver'. routes: # All alerts with service=mysql or service=cassandra # are dispatched to the database pager. - receiver: 'database-pager' group_wait: 10s match_re: service: mysql|cassandra # All alerts with the team=frontend label match this sub-route. # They are grouped by product and environment rather than cluster # and alertname. - receiver: 'frontend-pager' group_by: [product, environment] match: team: frontend
webhooks是一個api概念,是微服務api的使用範式之一,也被成爲反向api,即:前端不主動發送請求,徹底由後端推送。 舉個經常使用例子,好比你的好友發了一條朋友圈,後端將這條消息推送給全部其餘好友的客戶端,就是 Webhooks 的典型場景。
Prometheus經過webhook向Alertmanager推送警報,數據結構以下:
Alers結構以下:
每一個警報的標籤用於標識警報的相同實例並執行重複數據刪除。註釋老是設置爲最近收到的,而且沒有標識警報。
KV是一組用於表示標籤和註釋的鍵/值字符串對。後端
type KV map[string]string
例如:api
{ summary: "alert summary", description: "alert description", }
關於對KV的操做:
數據結構
GET /-/healthy
GET /-/ready
POST /-/reload