安裝請看http://www.javashuo.com/article/p-bfwlieic-do.html ,最好是對應的版本組件,不然可能會有差異。
html
(一)prometheus + grafana + alertmanager 配置主機監控node
(二)prometheus + grafana + alertmanager 配置Mysql監控mysql
(三)prometheus + grafana + alertmanager 配置Redis監控web
(四)prometheus + grafana + alertmanager 配置Kafka監控redis
(五)prometheus + grafana + alertmanager 配置ES監控sql
(三) prometheus + grafana + alertmanager 配置Redis監控json
一. redis_exporter安裝vim
若是是直接搭建的redis服務器,能夠參考上一章的內容。api
這裏以雲redis來安裝與配置,固然直接搭建的服務器redis也可使用這種方法(登錄到prometheus服務器,prometheus grafana alertmanager在同一臺服務器上)。服務器
A. 下載redis_exporter安裝包(下載地址: https://pan.baidu.com/s/1k-KcATTpxux9qiPFDt_6hQ ),而後解壓到/data/monitor/下。
B. 而後在cd /data/monitor/redis_exporter/scripts 下,建立每一個redis的監控啓動腳本,cat ba_10.8.100.140_6379_18019.sh,其它的相似。
nohup /data/monitor/redis_exporter/bin/redis_exporter -web.listen-address=':18019' -redis.addr=10.8.100.140:6379 >> /data/monitor/redis_exporter/log/18019_10.8.100.140_6379.log 2>&1 &
C. 而後cd /data/monitor/redis_exporter 下,sh start.sh,查看端口是否監聽或者查看進行是否啓動
二. prometheus配置
1. 將mysqld_exporter的配置增長到prometheus.yml文件中,vim /data/monitor/prometheus/conf/prometheus.yml
global:
# Server端抓取數據的時間間隔
scrape_interval: 1m
# 評估報警規則的時間間隔
evaluation_interval: 1m
# 數據抓取的超時時間
scrape_timeout: 20s
# 加全局標籤
#external_labels:
# monitor: "hk"
# 鏈接alertmanager
alerting:
alertmanagers:
- static_configs:
- targets: ["localhost:9093"]
# 告警規則
rule_files:
- /data/monitor/prometheus/conf/rule/*.yml
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# 監控prometheus本機
- job_name: 'prometheus'
scrape_interval: 15s
static_configs:
- targets: ['10.8.53.218:9090']
# 監控指定主機
- job_name: 'node_resources'
scrape_interval: 1m
static_configs:
file_sd_configs:
- files:
- /data/monitor/prometheus/conf/node_conf/node_host_info.json
honor_labels: true
# mysql採集器
- job_name: 'mysql_global_status'
scrape_interval: 60s
static_configs:
file_sd_configs:
- files:
- /data/monitor/prometheus/conf/node_conf/node_mysql_info.json
# redis採集器
- job_name: 'redis_resources'
scrape_interval: 60s
static_configs:
file_sd_configs:
- files:
- /data/monitor/prometheus/conf/node_conf/node_redis_info.json
2. vim /data/monitor/prometheus/conf/node_conf/node_redis_info.json
[
{
"labels": {
"addr": "10.8.100.140:6379",
"alias": "ba_redis",
"desc": "ba_redis_10.8.100.140:6379"
},
"targets": [
"localhost:18019"
]
},
{
"labels": {
"addr": "10.8.194.27:6379",
"alias": "openapi_redis",
"desc": "openapi_redis_10.8.194.27:6379"
},
"targets": [
"localhost:18047"
]
}
]
2. 而後cd /data/monitor/prometheus下, sh reload.sh
注意:redis 3.0及如下版本會有一些圖表會沒有數據,咱們是直接對接ucloud的api用腳本生成的數據。
三. 配置grafana
1. 下載redis監控模板,下載地址: https://pan.baidu.com/s/151lqEyDFObEs7BDFiBr1bw
2. 如何導入請參考配置主機監控的文章中的2.配置grafana中的h至l步驟( http://www.javashuo.com/article/p-ybzkorax-mn.html )
4. 配置alertmanager
A. 在prometheus配置規則,cat /data/monitor/prometheus/conf/rule/redis.yml ,下面是文件內容,而後重啓prometheus,cd /data/monitor/prometheus && sh reload.sh
groups:
- name: redis_alert
rules:
### 內存 ###
# 默認內存告警策略
- alert: redis內存95%
expr: ((floor(redis_memory_used_rss_bytes / redis_memory_max_bytes * 100) >= 95) or (floor(redis_mem_use_ratio) >= 95)) and ((redis_memory_max_bytes <= 1024 * 1024 * 1024 * 4) or (redis_mem_total_size <= 4))
for: 3m
labels:
severity: warning
annotations:
description: "[{{ $labels.alias }}],地址:[{{ $labels.addr }}],告警值爲:[{{ $value }}%],告警初始時長爲3分鐘."
- alert: redis內存98%
expr: ((floor(redis_memory_used_rss_bytes / redis_memory_max_bytes * 100) >= 98) or (floor(redis_mem_use_ratio) >= 98)) and ((redis_memory_max_bytes > 1024 * 1024 * 1024 * 4) or (redis_mem_total_size > 4))
for: 3m
labels:
severity: warning
annotations:
description: "[{{ $labels.alias }}],地址:[{{ $labels.addr }}],告警值爲:[{{ $value }}%],告警初始時長爲3分鐘."
B. 配置alertmanager, cat /data/prometheus/alertmanager/conf/alertmanager.yml ,若是是相同的接收人,能夠直接在原來的資源後面增長,若是是不一樣的接收人,就須要從新定義接收人模板,而後再定義資源規則並綁定到新的接收人模板
global:
resolve_timeout: 2m
smtp_auth_password: q5AYahvxi3WLDap3 #發送郵箱密碼
smtp_auth_username: itliuqs@163.com #發送郵箱
smtp_from: itliuqs@163.com #發送郵箱
smtp_require_tls: false
smtp_smarthost: smtp.163.com:465 #發送服務器
wechat_api_url: https://qyapi.weixin.qq.com/cgi-bin/ #微信接口連接
inhibit_rules:
- equal:
- instance
source_match:
alertname: "主機CPU90%"
target_match:
alertname: "主機負載太高"
- equal:
- instance
source_match:
alertname: "mysql運行進程數5分鐘增加數>150"
target_match:
alertname: "mysql慢查詢5分鐘100條"
- equal:
- instance
source_match:
severity: error
target_match:
severity: warning
- equal:
- instance
source_match:
severity: fatal
target_match:
severity: error
- equal:
- service_name
source_match:
severity: error
target_match:
severity: warning
receivers:
- email_configs: #定義test發送人模塊
- html: '{{ template "email.default.html" . }}' #調用的模板
send_resolved: true
to: liuqs@126.com #將報警信息發給些郵箱,多人用|
name: test #發送人模板名
wechat_configs: #微信接收這些信息請看最下面的企業微信介紹
- agent_id: 1000002 #應用id
api_secret: hnyU1LTGnJUiBaCp47l3WVQLTEFF5RXyfNO751xlaHa #應用認證
corp_id: wwd397231fa801beaa #企業微信ID
send_resolved: true
to_user: LiuQingShan|liuqs #發送給企業微信通信人的Id 多我的就用|分開
- email_configs: #定義默認的發送人
- html: '{{ template "email.default.html" . }}'
send_resolved: true
to: liuqs@126.com
name: default_group
wechat_configs:
- agent_id: 1000002
api_secret: hnyU1LTGnJUiBaCp47l3WVQLTEFF5RXyfNO751xlaHa
corp_id: wwd397231fa801beaa
send_resolved: true
to_user: LiuQingShan
route: #定義資源報警規則
group_by:
- monitor
group_interval: 2m
group_wait: 30s
receiver: default_group
repeat_interval: 6h
routes:
- continue: true
match_re:
instance: 10.8.46.117:9100|10.8.80.126:9100|10.8.32.67:9100|10.8.9.35:9100|10.8.69.81:9100|localhost:15050|localhost:15221|localhost:15052|localhost:15053|localhost:15049|localhost:15051|localhost:15060|localhost:18019|localhost:18047 #定義使用的資源
receiver: test #使用test發送人模板
templates:
- /data/monitor/alertmanager/template/*.tmpl #調用報警內容模板的路徑