基于prometheus的监控解决方案

一、前言

    鄙人就职于某安全公司,团队的定位是研发安全产品云汇聚平台,为用户提供弹性伸缩的云安全能力。前段时间产品组提出了一个监控需求,大致要求:平台对vm实行动态实时监控,输出相应图表界面,并提供警报(资源不足等问题而产生)等功能。

二、方案调研

    经过团队调研,目前业界流行的监控方案大致有这么几种:基于 zabbix 的、基于 prometheus 的、基于 influxdb 等时序数据库的。结合当前我们的业务场景来讲,zabbix对我们来说有点重,而 influxdb 方案灵活但是投入的研发时间可能是比较多的,prometheus就成了我们的不二之选择。

三、prometheus介绍

    

         1. What is prometheus ?  下面是官网的一段原话:

    Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have  adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company.To emphasize this, and to clarify the project's governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project,after Kubernetes.

    大致就是说  prometheus是一个开源的监控,警报系统,最初呢是构建在SoundCloud之上的。。。然后很多公司组织都在用,活跃的开发者很多,社区也很多,反正很牛逼。。。这样。

   

    2.Components

     prometheus大致有这么几个组件组成:

       1). Prometheus server: 用于抓取数据,并存储到时序数据库

       2). client librabries:用于一些应用的定制化监控

       3). push gateway:用于短生存周期的job推送

       4). exporter:安装在监控目标的机子上,为server提供数据抓取的接口,需要定制化。。当然官网也提供了很多常用的exporter ,用于mysql,redis,nginx,宿主机等等等等,有需求的可以去这里https://prometheus.io/docs/instrumenting/exporters/看看。

                     5). alertmanager:用于处理警报。

     

    3.架构图

      

        

            应该不需要怎么介绍了吧,我相信大家都可以看得懂。

      

四、结合业务使用

    有了prometheus这个强大的监控开源系统之后,我们所需要投入的工作就是查询api的封装和配置文件的下发。查询api的封装没什么好说的,无非就是前端调用我们自己的server,我们的   server呢通过http协议去调用prometheus的api接口查询到原始数据,然后进行组装,最后返回给前端。 配置文件的话包含三部分吧,警报的定义,alertmanager的配置,以及prometheus的配置,这里也不好展开讲,有兴趣的可以去官网看看,最后给出一张我们的物理结构示意图,供大家参考。    

原文地址:https://www.cnblogs.com/think-in-java/p/9094635.html