monicazhang 发表于 2016-1-13 13:00:01

nagios 监控windows 的磁盘

来自:网络disk = wmi.WMI(moniker='//./root/cimv2:Win32_LogicalDisk.DeviceID="%s:"' %drive)       nagios安装   
#    for disk in c.Win32_LogicalDisk (DriveType=3):
    data_dict['total_available'] += round(float(disk.FreeSpace) / (1024*1024*1024), 2)
    data_dict['total_capacity'] += round(float(disk.Size) / (1024*1024*1024), 2)
    data_dict['total_free'] += round(float(disk.FreeSpace) / (1024*1024*1024), 2)
   
    dev_tmp = {}
    dev_tmp['dev'] = disk.DeviceID
    dev_tmp['available'] = {'volume':round(float(disk.FreeSpace) / (1024*1024*1024), 2), 'unit':'GB'}          开源监控软件
    dev_tmp['capacity'] = {'volume':round(float(disk.Size) / (1024*1024*1024), 2), 'unit':'GB'}
    dev_tmp['free'] = {'volume':round(float(disk.FreeSpace) / (1024*1024*1024), 2), 'unit':'GB'}   nagios配置
    dev_tmp['fstype'] = disk.FileSystem
    dev_tmp['mnt'] = ''
    dev_tmp['used'] = round(long(disk.FreeSpace) / long(disk.Size), 2)
   
    data_dict = dev_tmp
   
    com = win32com.client.Dispatch("WbemScripting.SWbemRefresher")
    obj = win32com.client.GetObject('''winmgmts:\\root\cimv2''')
    diskitems = com.AddEnum(obj, "Win32_PerfFormattedData_PerfDisk_LogicalDisk").objectSet   监控软件
      
    com.Refresh()
    for item in diskitems:
      if item.Name in data_dict:
            data_dict['io_stat'] = {}
            data_dict['io_stat']['r/s'] = {'volume':float(item.DiskReadsPerSec), 'unit':''}
            data_dict['io_stat']['w/s'] = {'volume':float(item.DiskWritesPerSec), 'unit':''}
            data_dict['io_stat']['rkB/s'] = {'volume':(float(item.DiskReadBytesPerSec) / 1024), 'unit':'KB/s'}
            data_dict['io_stat']['wkB/s'] = {'volume':(float(item.DiskWriteBytesPerSec) / 1024), 'unit':'KB/s'}
#    return {'data':data_dict, 'timestamp':time.asctime(time.localtime())}
    return data_dict

#print DISK('C')['C:']['io_stat']['wkB/s']['volume'],DISK('C')['C:']['io_stat']['rkB/s']['volume']    nagios实施
def printr():
    disk = DISK(options.partion)
    diskw = disk['io_stat']['wkB/s']['volume']
    diskr = disk['io_stat']['rkB/s']['volume']      nagios培训
    print "Partion %s IO: READ %2.f KB/s Write %2.f KB/s | READ=%2.fKB WRITE=%2.fKB" %(options.partion,diskr,diskw,diskr,diskw)

if __name__ == '__main__':
    printr()


想做Nagios, Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流QQ群号 :476809427
页: [1]
查看完整版本: nagios 监控windows 的磁盘