本文共 3060 字,大约阅读时间需要 10 分钟。
wget https://studygolang.com/dl/golang/go1.10.3.linux-amd64.tar.gzsudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gzvim /etc/profile
export GO_HOME=/usr/local/goexport PATH=$GO_HOME/bin:$PATHsource /etc/profilego version
wget https://github.com/prometheus/prometheus/releases/download/v2.3.0/prometheus-2.3.0.linux-amd64.tar.gztar zxvf prometheus-2.3.0.linux-amd64.tar.gz -C ~/softwarecd ~/software/prometheus-2.3.0.linux-amd64vim prometheus.yml
scrape_configs: - job_name: prometheus scrape_interval: 5m static_configs: - targets: ['localhost:9090'] labels: instance: prometheus - job_name: node scrape_interval: 5m static_configs: - targets: ['localhost:9100'] labels: instance: server1 - job_name: mysql scrape_interval: 5m static_configs: - targets: ['localhost:9104'] labels: instance: db1 - job_name: redis scrape_interval: 5m static_configs: - targets: ['localhost:9121'] labels: instance: redis1
nohup ./prometheus --config.file=prometheus.yml &
检查运行状态:
ps -ef | grep prometheus
wget https://dl.grafana.com/oss/release/grafana_6.2.2_amd64.debsudo dpkg -i grafana_6.2.2_amd64.debsudo service grafana-server start
访问监控面板:
http://localhost:3000/login
点击“Add Data Source”,选择Prometheus,输入配置信息并保存。
wget https://github.com/prometheus/alertmanager/releases/download/v0.19.0/alertmanager-0.19.0.linux-amd64.tar.gztar zxvf alertmanager-0.19.0.linux-amd64.tar.gz -C ~/softwarecd ~/software/alertmanager-0.19.0.linux-amd64vim altermanager.yml
[receiver "alertmanager"] smtp_smarthost = 'smtp.qq.com:465' smtp_auth_password = '你的QQ邮箱授权码' smtp_from = '你的QQ邮箱' smtp_tls = false
nohup ./alertmanager --config.file=altermanager.yml &
vim ~/software/prometheus-2.3.0.linux-amd64/rules.yml
groups: - name: test-rules rules: - alert: InstanceDown expr: up == 0 for: 2m labels: status: warning annotations: summary: '{instance}: has been down' description: '{instance}: job {job} has been down' - alert: NodeCpuUsage expr: (100 - (avg by (instance) (rate(node_cpu{mode="idle"}[2m])) * 100)) > 99 for: 15m labels: service_name: test level: warning annotations: description: '{instance}: CPU usage is above 99% (current value: {value})' ps -ef | grep prometheuskill -f xxxnohup ./prometheus --config.file=prometheus.yml &
访问告警页面:
http://localhost:9090/alerts
smtp_tls设置为false,并使用POP3/SMTP服务。安装饼图插件:
sudo grafana-cli plugins install grafana-piechart-panelsudo service grafana-server restart
可以根据实际需求配置企业版微信、钉钉等告警接收地址。
Prometheus+Grafana+Altermanager是一套灵活高效的监控告警解决方案,适合Docker、Kubernetes等现代化容器化环境。通过合理配置Exporter、Prometheus、Grafana和Altermanager,可以实现对集群、存储、网络等多维度的实时监控,并通过邮件、钉钉等方式接收告警信息。
转载地址:http://jexfk.baihongyu.com/