Skip to content

Latest commit

 

History

History
155 lines (93 loc) · 3.38 KB

prometheus-stack.md

File metadata and controls

155 lines (93 loc) · 3.38 KB

prometheus stack

tags: note, prometheus, grafana

prometheus stack

  • prometheus: monitoring system and time series database.
  • grafana: The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.

install by docker

公司環境都是使用 docker 的安裝方式安裝

Grafana

default login info admin/admin

docker run -d -p 3000:3000 --name grafana grafana/grafana:6.5.0

node-exporter

Exporter for machine metrics

在需要監控的主機裝就好了

docker run -d \
  --net="host" \
  --pid="host" \
  --name node-exporter \
  -v "/:/host:ro,rslave" \
  quay.io/prometheus/node-exporter:latest \
  --path.rootfs=/host

Prometheus

先設定好 prometheus config

prometheus/prometheus.yml

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  # 監控的 metric 位置,指向 node-exporter 安裝的主機
  - job_name: 'prometheus'
    static_configs:
     - targets: ['10.110.86.130:9100']
       labels:
          instance: 'local-01'
          platform: 'sh'

安裝 prometheus

docker run -d \
    -p 9090:9090 \
    -v /home/blockchain/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
    --name prometheus \
    prom/prometheus

Prometheus

http://10.110.86.130:9090

這邊紀錄了所以收集來的監控資訊

Target

http://10.110.86.130:9090/targets

可以看到 targets 的狀況(也就是 prometheus config 設定那些目標

Graph

可以直接將收集來的資料產生圖片

Grafana

http://10.110.86.130:3000

顯示介面、告警

Dashboard(Import)

可以在官方的圖表庫中 Official & community built dashboards 找別人設定好的圖來用

隨邊找個 postgres 模板

點下 Copy ID to Clipboard 後,回到 Grafana,按下 Create > Import

貼上 Dashboard ID

按下 Load 後,就可以匯入 template 了

Dashboard(New)

或是自己新增

Query

使用 Querying basics | Prometheus 來過濾 Metrics 資料

Visualization

資料源過濾完後,可以選擇要顯示的圖表樣式

Alert

告警服務,這邊需要先設定要連接的平台

然後回到顯示頁面的 Alert 頁

Conditions 觸發的情況下,推到 Notification 那邊

slack