目錄
系統環境
環境:centos7.0
Prometheus版本:2.14.0
node_exporter版本:0.18.1
Prometheus 是什麼?
- Prometheus是一套開源的監控&報警&時間序列數據庫的組合,起始是由SoundCloud公司開發的。隨着發展,越來越多公司和組織接受採用Prometheus,社區也十分活躍,他們便將它獨立成開源項目,並且有公司來運作。google SRE的書內也曾提到跟他們BorgMon監控系統相似的實現是Prometheus。現在最常見的Kubernetes容器管理系統中,通常會搭配Prometheus進行監控。
Prometheus 的優點
- 非常少的外部依賴,安裝使用超簡單
- 已經有非常多的系統集成 例如:docker HAProxy Nginx JMX等等
- 服務自動化發現
- 直接集成到代碼
- 設計思想是按照分佈式、微服務架構來實現的
Prometheus 的特性
- 自定義多維度的數據模型
- 非常高效的存儲 平均一個採樣數據佔 ~3.5 bytes左右,320萬的時間序列,每30秒採樣,保持60天,消耗磁盤大概228G。
- 強大的查詢語句
- 輕鬆實現數據可視化
Prometheus系統架構
- 下圖說明了Prometheus的體系結構及其某些生態系統組件
Prometheus下載二進制文件並安裝運行
[root@localhost ~]# mkdir -p /data/prometheus
[root@localhost ~]# cd /data/prometheus
[root@localhost prometheus]# wget https://github.com/prometheus/prometheus/releases/download/v2.14.0-rc.0/prometheus-2.14.0-rc.0.linux-amd64.tar.gz
[root@localhost prometheus]# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
[root@localhost prometheus]# tar -zxf prometheus-2.14.0-rc.0.linux-amd64.tar.gz
[root@localhost prometheus]# tar -zxf node_exporter-0.18.1.linux-amd64.tar.gz
[root@localhost prometheus-2.14.0-rc.0.linux-amd64]# cd /data/prometheus/prometheus-2.14.0-rc.0.linux-amd64
[root@localhost prometheus-2.14.0-rc.0.linux-amd64]# sed -i 's/localhost/192.168.100.228/g' prometheus.yml
[root@localhost prometheus-2.14.0-rc.0.linux-amd64]# nohup ./prometheus &
使用瀏覽器訪問Prometheus
出現以下頁面則表示Prometheus搭建成功
使用node_exporter獲取監控主機的數據
[root@localhost prometheus]# cat /data/prometheus/prometheus-2.14.0-rc.0.linux-amd64/prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "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: ['192.168.100.228:9090']
- job_name: 'server'
static_configs:
- targets: ['192.168.100.228:9100']
[root@localhost ~]# cd /data/prometheus/prometheus-2.14.0-rc.0.linux-amd64/ && nohup ./prometheus &
[root@localhost ~]# cd /data/prometheus/node_exporter-0.18.1.linux-amd64 &&nohup ./node_exporter &
再次使用瀏覽器查看Prometheus系統是否添加主機進來
Prometheus與grafana集成監控
[root@localhost ~]# mkdir -p /data/grafana
[root@localhost ~]# cd /data/grafana
[root@localhost grafana]# wget https://dl.grafana.com/oss/release/grafana-6.4.4.linux-amd64.tar.gz
[root@localhost grafana]# tar zxf grafana-6.4.4.linux-amd64.tar.gz
grafana默認賬戶密碼爲:admin/admin,第一次登陸成功後會強制修改默認密碼
修改密碼
點擊添加數據源
然後選擇第一個Prometheus
輸入Prometheus監控系統的地址,這裏爲192.168.100.228
在grafana官網下載模板
獲取模板ID
返回儀表盤,添加儀表盤,
將獲取到的模板ID填入該文本框中
選擇Prometheus,然後點擊import
至此,grafana與Prometheus監控系統搭建成功