基於Prometheus&Grafana的監控方案[2]-安裝配置
架構
這裡我們用第三方的exporter採集機器資料,prometheus直接從exporter的例項pull資料,然後用grafana展現和告警。
grafana可以選擇多個數據來源,所以機器較多時,我們可以配置多個prometheus彙集資料,再統一由grafana展現,一般可以按照地域、業務、機房等維度進行劃分。
Exporter
這裡我們僅僅監控機器的流量、CPU、記憶體、磁碟等基本資訊,因此選用的exporter如下:
分別下載對應的exporter,解壓,直接run,對於linux訪問9100埠,對於win訪問9182埠,如下說明exporter已經開始採集資料了。
Prometheus
prometheus.exe
linux平臺執行:
./prometheus --config.file=prometheus.yml --web.listen-address=:9099
關於啟動的引數說明–help說明的非常詳細
prometheus.yml配置檔案
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15 s # 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: 'node'
static_configs:
- targets: ['xxx.xx.xx.xxx:9182']
labels: {'name':'node_hf_xxx','ip':'xxx.xx.xx.xxx','area':'hf'}
- targets: ['xxx.xx.xx.xxx:9100']
labels: {'name':'node_hf_xxx','ip':'xxx.xx.xx.xxx','area':'hf'}
這裡我們主要關注scrape_configs的配置,設定了job的name為node,同時設定了一些labels,目的是為了後面grafana展現的時候,根據這些lables進行搜尋,方便資料的分類。
訪問9090埠,展現如下說明prometheus已經成功的pull資料了。
Grafana
grafana不僅僅支援prometheus的展現,還支援ES、InfluxDB、OpenTSDB、MYSQL、SQL SERVER等等資料來源,下載地址:
https://grafana.com/grafana/download
這裡我們是win平臺安裝的grafana,下載解壓後直接執行exe檔案,若是centos可以安裝官方文件直接yum安裝,詳見:http://docs.grafana.org/installation/rpm/
我們主要看一下grafana的配置檔案
win平臺
./conf/defaults.ini
centos
/etc/grafana/grafana.ini
配置檔案我們主要關注郵箱的配置,這裡的郵箱就是報警的時候傳送人的配置
#################################### SMTP / Emailing #####################
[smtp]
enabled = true
host = mail.domain.com:25
user = xxxxx
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = xxxxxx
cert_file =
key_file =
skip_verify = true
from_address = xxxxx@domain.com
from_name = Grafana
ehlo_identity =
另外可以設定一下初始登入的使用者名稱和密碼
#################################### Security ############################
[security]
# default admin user, created on startup
admin_user = xxxxx
# default admin password, can be changed before first start of grafana, or in profile settings
admin_password = xxxxxx
登入,配置資料來源:
這裡我們按照地域劃分的資料來源,將name命名為合肥。
監控資料展現效果:
將在第3篇文章介紹以上展示效果的promQL語句