安装Prometheus
下载prometheus
https://prometheus.io/download/
上传至服务器解压到指定位置进入Prometheus目录执行
./prometheus --config.file=prometheus.yml
端口号为9090访问,出现可视化界面则为安装成功
ip:9090
安装node_exporter,此处不再赘述
修改prometheus.yml文件
- job_name: 'job-name'
static_configs:
- targets: ['ip:port']
安装grafana
下载grafana解压安装到指定目录
https://grafana.com/grafana/download
grafana面板仓库地址
https://grafana.com/dashboards
查看grafana图形界面,端口号为3000
ip:3000
配置Prometheus Datasource
安装alertmanager
下载安装完后启动,端口9093
修改alertmanager.yml文件
global:
resolve_timeout: 5m
smtp_from: '发信箱地址'
smtp_smarthost: 'smtp.163.com:25'
smtp_auth_username: '发信箱地址'
smtp_auth_password: 'xxxxxxxxxxHLE' #这里要开启邮箱SMTP/POP3/IMAP认证,记录授权码
smtp_require_tls: false
route:
group_by: ['alertname']
group_wait: 5s
group_interval: 5s
repeat_interval: 8h
receiver: 'email'
receivers:
- name: 'email'
email_configs:
- to: '收信箱地址,收信箱地址'
send_resolved: true
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
修改prometheus.yml文件
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager-ip:port
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "rules/*.yml"
# - "second_rules.yml"
prometheus下添加告警规则
groups:
- name: proc-state
rules:
# java服务
- alert: job-name-one
expr: up{job="auth-15"} == 0
for: 15s
labels:
serverity: ip-addr
service: "service-name-one"
annotations:
summary: "IP地址: {{ $labels.instance }} 进程: {{ $labels.service }} 已经停止运行!"
- alert: job-name-two
expr: up{job="gateway-15"} == 0
for: 15s
labels:
serverity: ip-addr
service: "service-name-two"
annotations:
summary: "IP地址: {{ $labels.instance }} 进程: {{ $labels.service }} 已经停止运行!"
监控mysql
[client]
host=mysql-ip
port=mysql-port
user=mysql-name
password=mysql-password