其他分享
首页 > 其他分享> > check_mk自定义监控增加性能数据图形展示

check_mk自定义监控增加性能数据图形展示

作者:互联网

在nagios中可以实现性能图形展示,利用的是PNP4Nagios,check_mk当然也可以,而且很简单。

这篇文章在前一篇文章《check_mk自定义监控实践之powershell》的基础之前,脚本稍作修改

1、客户端process_top5.ps1

$dp = (Get-Process) | select -First 5
$ops = Get-WmiObject -Class Win32_OperatingSystem

echo `<`<`<process_top5`>`>`>    #这个输出很重要,用来告诉check_mk服务端目标客户端有哪些监控项
foreach($p in $dp){
    #输出进程名称及内存百分占比,这里为方便演示乘上50加大百分比
    Write-Host $p.name ("{0:0.0}" -f ($p.WorkingSet*50/$ops.TotalVisibleMemorySize))
}

2、监控端process_top5, 实际上只需要添加两行代码就可以实现 性能数据收集

process_top5_default_values=(20,30)

def inventory_process_top5(info):
   inventory = []
   for line in info:
      disk = line[0]
      field = float(line[1])
      inventory.append( (disk, "process_top5_default_values") )

   return inventory


def check_process_top5(item,params,info):
        warn,crit = params
        for line in info:
            if (line[0]) == item :
                celsius = float(line[1])
                perfdata = [ ( "process mem", celsius, warn, crit ) ]  #表示每次check后收集相关数据
                if celsius > crit:
                        return (2, "mem is %d %%" % celsius, perfdata)
                elif celsius > warn:
                        return (1, "mem is %d %%" % celsius, perfdata)
                else:
                        return (0, "mem is %d %%" % celsius, perfdata)
        return (3, "%s not found in agent output" % item)


check_info["process_top5"] = {
    'check_function':            check_process_top5,
    'inventory_function':        inventory_process_top5,
    'service_description':       '%s',
    'has_perfdata':              True,      #打开收集性能数据开关
}

现在打开check_mk页面,可以看到相应监控项后面已经多了个 星星的图标,点击进去就是PNP4Nagios的性能图形展示

3、check_mk还可以将实时的性能数据用图形很方便的展示在每一项的后面,即Perf-O-Meters,官方文档:http://mathias-kettner.de/checkmk_devel_agentbased.html

就像上图中“Check_MK”项,为了实现这个可能需要写些脚本,不过check_mk本身已经有了不少样式的脚本,这里我们可以利用cpu的Perf-O-Meters脚本(因为都是百分比,所以可以偷懒了)。

打开文件/usr/share/check_mk/web/plugins/perfometer/check_mk.py",找到perfometer_cpu_utilization函数,然后在底下添加一个perfometers项目

def perfometer_cpu_utilization(row, check_command, perf_data):
    util = float(perf_data[0][1]) # is already percentage
    color = "#60f020"
    return "%.0f%%" % util, perfometer_linear(util, color)

#perfometer_linear(perc, color)
perfometers["check_mk-h3c_lanswitch_cpu"] = perfometer_cpu_utilization
perfometers["check_mk-winperf_processor.util"] = perfometer_cpu_utilization
perfometers["check_mk-netapp_cpu"] = perfometer_cpu_utilization
perfometers["check_mk-cisco_cpu"] = perfometer_cpu_utilization
perfometers["check_mk-juniper_cpu"] = perfometer_cpu_utilization
perfometers["check_mk-brocade_mlx.module_cpu"] = perfometer_cpu_utilization
perfometers["check_mk-process_top5"] = perfometer_cpu_utilization   #为process_top5添加perfometers功能

重启web服务,然后就可以看到perfometers图了

转载于:https://www.cnblogs.com/waiwofei/p/3810664.html

标签:自定义,process,top5,mk,check,perfometer,cpu
来源: https://blog.csdn.net/weixin_34238633/article/details/94314293