系统运维


Prometheus监控测试文档

<h5>环境:Prometheus-server、Prometheus-client</h5> <h3>1. 监控服务端口信息</h3> <table> <thead> <tr> <th style="text-align: center;">主机</th> <th style="text-align: center;">服务</th> <th style="text-align: center;">端口</th> <th style="text-align: center;">状态</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">180.184.138.201</td> <td style="text-align: center;">Prometheus</td> <td style="text-align: center;">9090</td> <td style="text-align: center;">up</td> </tr> <tr> <td style="text-align: center;">42.192.10.73 180.184.138.201</td> <td style="text-align: center;">alertmanager</td> <td style="text-align: center;">9093</td> <td style="text-align: center;">up</td> </tr> <tr> <td style="text-align: center;">42.192.10.73 180.184.138.201</td> <td style="text-align: center;">nginx</td> <td style="text-align: center;">80</td> <td style="text-align: center;">up</td> </tr> <tr> <td style="text-align: center;">42.192.10.73 180.184.138.201</td> <td style="text-align: center;">mysqld_exporter</td> <td style="text-align: center;">9104</td> <td style="text-align: center;">up</td> </tr> <tr> <td style="text-align: center;">42.192.10.73 180.184.138.201</td> <td style="text-align: center;">node_exporter</td> <td style="text-align: center;">9100</td> <td style="text-align: center;">up</td> </tr> <tr> <td style="text-align: center;">180.184.138.201</td> <td style="text-align: center;">rabbitmq_exporter</td> <td style="text-align: center;">9419</td> <td style="text-align: center;">up</td> </tr> <tr> <td style="text-align: center;">42.192.10.73 180.184.138.201</td> <td style="text-align: center;">redis_exporter</td> <td style="text-align: center;">9121</td> <td style="text-align: center;">up</td> </tr> </tbody> </table> <h3>2.监控指标(展示部分)</h3> <ul> <li>主机内存使用率告警 expr:(node_memory_MemTotal_bytes - (node_memory_MemFree_bytes + node_memory_Buffers_bytes + node_memory_Cached_bytes)) / node_memory_MemTotal_bytes * 100 &gt; 80</li> <li>主机CPU使用率告警 expr:sum by (instance, appname) (avg without (cpu) (irate(node_cpu_seconds_total{mode!=&quot;idle&quot;}[5m]))) &gt; 0.8</li> <li>主机文件系统使用率告警 expr:(node_filesystem_size_bytes - node_filesystem_free_bytes) / node_filesystem_size_bytes * 100 &gt; 80</li> <li>主机宕机 expr:up == 0</li> <li>Mysql端口告警 expr:mysql_up == 0</li> <li>Mysql在线连接数&gt;80% expr:max_over_time(mysql_global_status_threads_connected[1m]) / mysql_global_variables_max_connections * 100 &gt; 80</li> <li>Mysql重启告警 expr:mysql_global_status_uptime &lt; 60</li> <li>Redis端口告警 expr:redis_up == 0</li> <li>Redis在线连接数&gt;80% expr:redis_connected_clients / redis_config_maxclients * 100 &gt; 80</li> </ul> <h3>3.测试结果</h3> <h4>3.1 Grafana主机整体监控效果</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=0f54bb3fd8f04d06d880e80ba9a07628&amp;file=file.png" alt="" /></p> <h4>- 修改内存监控指标为5%</h4> <p><strong>处于PENDING状态,即已触发告警但未满足告警时间,持续时间1分钟</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=54a0c931adc6be5d80f0801c45b123a0&amp;file=file.png" alt="" /></p> <p><strong>处于FIRING状态,即已触发告警,并且发送告警</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=784876d5cab9889e3dc8e4eaf7b8b627&amp;file=file.png" alt="" /></p> <p><strong>这时alertmanager已识别,instance即为告警目标IP+端口,job为监控插件,name告警类型,severity告警级别</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=16ab23d3910f18e3f2bc68b3d874baec&amp;file=file.png" alt="" /></p> <p><strong>告警消息通知</strong> Status:firing(正在发生)、resolved(已恢复)</p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=788da6caa1c53f0e7229ccefa4412a2e&amp;file=file.png" alt="" /></p> <h4>3.2 Grafana MySQL整体监控效果</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=483a702b633589cf29b8d471187c1329&amp;file=file.png" alt="" /></p> <p><strong>关闭mysql服务,已触发告警</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=3e68b20ac6b6c1e4df7b6b40519b9aae&amp;file=file.png" alt="" /></p> <p><strong>alertmanager获取告警信息</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=1f64192234224b850f348956b432796e&amp;file=file.png" alt="" /></p> <p><strong>告警消息通知</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=b2aa5861bda56157895b3f43c6226841&amp;file=file.png" alt="" /></p> <p><strong>同时,MySQL发生一次重启,也会被检测到</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=3df663f6ec6fc18c26bceda3614dfd3e&amp;file=file.png" alt="" /></p> <h4>3.3 Grafana Redis整体监控效果</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=aa6d147bc0652640910722a9313effe9&amp;file=file.png" alt="" /></p> <p><strong>关闭Redis服务,已触发告警</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=ab9eca6e8e2215a319d174c007ebd348&amp;file=file.png" alt="" /></p> <p><strong>alertmanager获取告警信息</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=6355b77eeea366d883eb27cce4398106&amp;file=file.png" alt="" /></p> <p><strong>告警消息通知</strong></p> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=578a1a2ad9c6c9f432a22acac477c284&amp;file=file.png" alt="" /></p> <h4>3.4 Grafana Nginx整体监控效果</h4> <p><img src="https://www.showdoc.com.cn/server/api/attachment/visitFile?sign=08562443ebd05514c2bb01e88d106013&amp;file=file.png" alt="" /></p> <h4>Tips:</h4> <p>在部署客户端nginx--module-vts-master时,在已经按照好的nginx基础上再次添加module,进入到nginx的configure文件所在目录,再次配置,配置完成后只需要make,不需要make install,不然会覆盖原有的文件。</p> <h3>总结:</h3> <p>Prometheus是基于时间序列来存储数据、收集指标,通过配置报警规则,把触发的报警发送到alertmanager。exporter是用于暴露已有的第三方服务的metrics数据给Prometheus。alertmanager是从Prometheus server端接收到alerts后,通过路由到相应的接收方发出报警,这里采用的是webhook的方式告知企微机器人。 针对于告警模板的优化,因为是采用docker部署一个wechat的容器,容器镜像基于guyongquan/webhook-adapter构建的,其镜像内部可能拟定了告警模板,导致外界套用自定义模板无效。监控指标可以根据实际工作需求进行相应更改。 Prometheus的web界面各监控项不是实时更新的,需要刷新网页或者菜单栏来回切换后才能刷新最新状态。</p>

页面列表

ITEM_HTML