check.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:icinga2checks 作者: c-store 项目源码 文件源码
def check_disk(i_warning, i_critical, s_partition):
    """
    Checks for disk stats

    Gets:
        i_warning: Warning Threshold
        i_critical: Critical Threshold
        s_partition: partition that should be used to trigger WARNING/CRITICAL

    Returns:
        check output including perfdata
    """
    test_int(i_warning, i_critical)
    test_string(s_partition)

    s_perfdata                  = ''
    s_output                    = ''
    l_partitions                = psutil.disk_partitions()
    d_io_counters               = psutil.disk_io_counters(perdisk=True)
    f_monitored_partition_usage = 0.0

    for nt_partition in l_partitions:
        # get usage for every partition
        d_disk_usage = psutil.disk_usage(nt_partition.mountpoint)._asdict()
        # add all usage data to perfdata
        for key, value in d_disk_usage.items():
            s_perfdata = add_perfdata(s_perfdata, nt_partition.mountpoint, key, value)

        # check monitored partition and add status to output
        if nt_partition.mountpoint == s_partition:
            s_output = check_status(i_warning, i_critical, d_disk_usage['percent'])
            f_monitored_partition_usage = d_disk_usage['percent']

    # add message if status is not OK
    if not 'OK' in s_output:
        s_output += ' {} has a usage of {} percent.'.format(s_partition, f_monitored_partition_usage)

    # add all the mountpoints and other info to output
    for nt_partition in l_partitions:
        d_partition = nt_partition._asdict()
        for key, value in d_partition.items():
            if not key == 'device':
                s_output += '\n{}.{}={}'.format(
                    d_partition['device'],
                    key,
                    value
                )

    for s_device, nt_partition in d_io_counters.items():
        d_partition = nt_partition._asdict()
        # add all io_counters to perfdata
        for key, value in d_partition.items():
            s_perfdata = add_perfdata(s_perfdata, s_device, key, value)

    # put it all together
    s_output += ' | {}'.format(s_perfdata)

    return s_output
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号