大数据技术之用munin来自定义插件监控redis和mongodb
沉沙 2019-04-22 来源 : 阅读 571 评论 0

摘要:本篇文章探讨了大数据技术之用munin来自定义插件监控redis和mongodb,希望阅读本篇文章以后大家有所收获,帮助大家对相关内容的理解更加深入。

本篇文章探讨了大数据技术之用munin来自定义插件监控redis和mongodb,希望阅读本篇文章以后大家有所收获,帮助大家对相关内容的理解更加深入。

大数据技术之用munin来自定义插件监控redis和mongodb

<

求监控组的大哥大妹子们干点事,真不容易 ! 要问他们是谁?  他们是神 。轻易别找他们,因为找了也是白找。

上次因为python和redis长时间brpop的时候,会有线程休眠挂起的情况,所有通知报警平台被下线了。这次算是完美解决了。再把他给上线。这两公司的告警已经开始往我这边的接口开始仍了。

这边正在改zabbix cmdb的控制,所以暂时不能登录。等搞好了后,让他们搞下redis和mogodb的监控,居然还让我发邮件和提供脚本及思路啥的。。。   一寻思,又要去zabbix,又要写脚本,还不如把监控都集合在自己的平台上的了。 

这次没用选用钟爱的ganglia,麻烦。 也没用另一个graphite,而是用的是munin 。   一个直接yum后就可以访问的性能监控页面。

官方的redis监控和mongodb看起来很麻烦的样子,算了。直接看他们是怎么写的。源码是perl写的,插件好多是shell写的。 

写法是相当的简单,只需要指明下图片的显示Y X 轴 ,然后echo就可以了!  

下面是redis 的token使用热点数据,队列的数据,及mongodb count的数据。

上面的图数据没有打满,今天在补上:

脚本的位置:   /etc/munin/plugins

监控mongodb的脚本:

#xiaorui.cc
if [ "$1" = "autoconf" ]; then
        echo yes
        exit 0
fi
if [ "$1" = "config" ]; then
        echo 'graph_title mongodb count mail'
        echo 'graph_args --base 1000 -l 0'
        echo 'graph_vlabel mail queue'
        echo 'graph_scale no'
        echo 'graph_category system'
        echo 'load.label load'
        echo 'graph_info The load average of the machine describes how many processes are in the run-queue (scheduled to run "immediately").'
        echo 'load.info 5 minute load average'
        exit 0
fi
echo -n "load.value "
mongo reportops --eval "db.reportops_log_mail.count()"|tail -n1

监控redis队列的脚本:

#xiaorui.cc
if [ "$1" = "config" ]; then
        # The host name this plugin is for. (Can be overridden to have
        # one machine answer for several)
        # The title of the graph
        echo 'graph_title redis mail'
        # Arguments to "rrdtool graph". In this case, tell it that the
        # lower limit of the graph is '0', and that 1k=1000 (not 1024)
        echo 'graph_args --base 1000 -l 0'
        # The Y-axis label
        echo 'graph_vlabel load'
        # We want Cur/Min/Avg/Max unscaled (i.e. 0.42 load instead of
        # 420 milliload)
        echo 'graph_scale no'
        # Graph category. Defaults to 'other'
        echo 'graph_category system'
        # The fields. "label" is used in the legend. "label" is the only
        # required subfield.
        echo 'load.label load'
        # These two read the environment for warning values for the field
        # "load".  If "load_warning" or "warning" aren't set in the
        # environment, no warning levels are set.  Likewise for "load_critical"
        # and "critical".
        print_warning load
        print_critical load
        # This one is purely to add an explanation to the web page. The first
        # one is for the graph itself, while the second one is for the field
        # "load".
        echo 'graph_info The load average of the machine describes how many processes are in the run-queue (scheduled to run "immediately").'
        echo 'load.info 5 minute load average'
        # Last, if run with the "config"-parameter, quit here (don't
        # display any data)
        exit 0
fi
# If not run with any parameters at all (or only unknown ones), do the
# real work - i.e. display the data. Almost always this will be
# "value" subfield for every data field.
echo -n "load.value "
redis-cli LLEN sendmaillist|cut -d '' -f2

写完了后,/etc/init.d/munin-node restart 就可以了。等一会刷新下页面就出来了。

关键就是最后那两行。。

echo -n "load.value "
redis-cli LLEN sendmaillist|cut -d '' -f2

网上有人做了python的munin操作模块,有兴趣的朋友可以试试。

#!/usr/bin/env python
import os
from munin import MuninPlugin
class LoadAVGPlugin(MuninPlugin):
    title = "Load average"
    args = "--base 1000 -l 0"
    vlabel = "load"
    scale = False
    category = "system"
    @property
    def fields(self):
        warning = os.environ.get('load_warn', 10)
        critical = os.environ.get('load_crit', 120)
        return [("load", dict(
                label = "load",
                info = 'The load average of the machine describes how many processes are in the run-queue (scheduled to run "immediately").',
                type = "GAUGE",
                min = "0",
                warning = str(warning),
                critical = str(critical)))]
    def execute(self):
        if os.path.exists("/proc/loadavg"):
            loadavg = open("/proc/loadavg", "r").read().strip().split(' ')
        else:
            from subprocess import Popen, PIPE
            output = Popen(["uptime"], stdout=PIPE).communicate()[0]
            loadavg = output.rsplit(':', 1)[1].strip().split(' ')[:3]
        return dict(load=loadavg[1])
if __name__ == "__main__":
    LoadAVGPlugin().run()


总结下,munin真的够简单的了,他的简单也意味着,他也就 适合我这样的运维研发人员临时做些统计的场景。  记得以前使用munin,当时做zeromq的统计,超过几十台是没啥问题,当然这话是(feihua),要是几十台都有问题,那这监控的水准确实够烂。  这东西的局限确实够大。也就临时画画图还行。

      本文由职坐标整理发布,学习更多的相关知识,请关注职坐标IT知识库!

本文由 @沉沙 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程