Skip to content

Latest commit

 

History

History
78 lines (67 loc) · 1.91 KB

README.md

File metadata and controls

78 lines (67 loc) · 1.91 KB

Server Exporter使用說明

Dependency

Prometheus Python Client: Prmometheus官方提供的library

安裝方式

pip install prometheus-client

使用說明

external_web = "tw.stock.yahoo.com" # 目標外部網站的domain name or ip
my_web = ["127.0.0.1", 5500] # 自己架站所使用的 ip and port
exporter_port = 8000 # exporter 使用的 port
sleep_interval = 1 # 發送export的間隔時間, 單位為秒

設定完畢後,啟動程式並透過 Prometheus監聽 exporter的 port(以上面的code為例, 8000)

scrape_configs:
  - job_name: 'web_state'
    static_configs:
    - targets: ['127.0.0.1:8000']

Prometheus會有my_web_stateexternal_web_state兩個 metrices

my_web_state

successfail兩種狀態。

當自己的網站存活時 success值為1, fail值為0

當自己的網站死亡時 success值為0, fail值為1

external_web_state

successfail兩種狀態。

當外部的網站存活時 success值為1, fail值為0

當外部的網站死亡時 success值為0, fail值為1

Example

情境: 自己的網站死亡

my_web = ["127.0.0.1", 5500] #5500 port未開啟

in Prometheus

my_web_state{my_web_state="success"} 0.0
my_web_state{my_web_state="fail"} 1.0

情境: 自己的網站存活

my_web = ["127.0.0.1", 5500] #5500 port已開啟

in Prometheus

my_web_state{my_web_state="success"} 1.0
my_web_state{my_web_state="fail"} 0.0

情境: 外部網站死亡

external_web = "never.exist.website"

in Prometheus

external_web_state{external_web_state="success"} 0.0
external_web_state{external_web_state="fail"} 1.0

情境: 外部網站存活

external_web = "google.com.tw"

in Prometheus

external_web_state{external_web_state="success"} 1.0
external_web_state{external_web_state="fail"} 0.0