# prometheus 安裝 步驟 --- - 安裝 wget - 下載 prometheus - 解壓縮 prometheus - 啟動 prometheus - 安裝並啟動Node Exporter - 設定監控相關參數,並重新啟動prometheus 相關設定與檔案 --- ## prometheus.yml(主要設定檔) ### rule_files 用於指定哪一個檔案設定通報監控機制 ### scrape_configs設定configs 透過job_name指定相關設定類型 #### prometheus(本身設定參數) targets 該監控主機IP #### node_exporter_metrics(受監控者相關設定) targets 受監控主機IP ``` # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: - "alert_rules.yml" # - "first_rules.yml" # - "second_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: ["your_ip:9090"] - job_name: 'node_exporter_metrics' scrape_interval: 5s static_configs: - targets: ['your_ip:9100'] ``` ## alert_rules.yml(監控設定檔) ``` groups: - name: cpu_alerts rules: - alert: HighCPUUsage expr: (1 - rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100 > 80 for: 2m labels: severity: critical instance: "{{ $labels.instance }}" annotations: summary: "High CPU Usage Detected" description: "CPU usage on {{ $labels.instance }} is above 90" - name: memory_alerts rules: - alert: HighMemoryUsage expr: ((node_memory_MemTotal_bytes - node_memory_MemFree_bytes - node_memory_Cached_bytes) / node_memory_MemTotal_bytes) * 100 > 80 for: 2m labels: severity: critical instance: "{{ $labels.instance }}" annotations: summary: "High Memory Usage Detected" description: "Memory usage on {{ $labels.instance }} is above 90%" - name: disk_alerts rules: - alert: DiskSpaceAlert expr: (node_filesystem_free_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"} * 100) < 10 for: 5m labels: severity: critical instance: "{{ $labels.instance }}" annotations: summary: "Disk Space Usage High" description: "Disk space on {{ $labels.instance }} is running low." ``` 參考 --- - [安裝wget](https://www.delftstack.com/zh-tw/howto/linux/how-to-use-wget-command-in-linux/#%25E6%25AA%25A2%25E6%259F%25A5-linux-%25E6%2598%25AF%25E5%2590%25A6%25E5%25AE%2589%25E8%25A3%259D%25E4%25BA%2586-wget) - [安裝prometheus](https://ryanisagoodguy.blogspot.com/2019/12/centosprometheusgrafana.html) - [prometheus 官方文件](https://prometheus.io/download/) - [輕鬆管理 Metrics 的工具,Prometheus 介紹](https://ithelp.ithome.com.tw/articles/10299053) - https://ithelp.ithome.com.tw/articles/10336643 - https://hackmd.io/@gdsc-ntcu/r1fBFO0Pa - https://ken00535.medium.com/use-prometheus-to-monitor-end-devices-bec0712b1d5 - https://hackmd.io/@cheese-owner/BkF8Kmlc5?utm_source=preview-mode&utm_medium=rec ###### tags: `Templates` `Book`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up