python檢測伺服器硬碟使用方式

來源:互聯網
上載者:User

#!/bin/env python # -*- coding: utf-8 -*- ########################################################## # @This script is used to check disk free space for zabbix # @Contact:      wangwei03@gyyx.cn # @Name:         disk.py # @Function:     check disk free space for zabbix # @Author:       wangwei ########################################################## import platform import commands  def w_disk():     import wmi     c = wmi.WMI ()     i = 0     for disk in c.Win32_LogicalDisk (DriveType=3):         a = int(disk.FreeSpace) / (1024*1024*1024)         b = int(100.0 * long (disk.FreeSpace) / long (disk.Size))         if disk.Caption == "C:":             if (a < 2) or (b < 10):                 i += 1             else:                 i += 0         else:             if (a < 10) or (b < 10):                 i += 1             else:                 i += 0     print i  def L_disk():     free = commands.getstatusoutput('df -h|grep dev|egrep -v "tmp|var|shm"')     list = free[1].split('\n')     i = 0     for disk in range(len(list)):         vd = list[disk][6:8]         a = list[disk].split()[3]         if a[-1] == 'T':             a = int(float(a[:-1]))*1024         else:             a = int(float(a[:-1]))         b = 100 - int(list[disk].split()[4][:-1])         if vd == "da":             if (a < 2) or (b < 10):                 i += 1             else:                 i += 0         else:             if (a < 10) or (b < 10):                 i += 1             else:                 i += 0     print i  if __name__ == "__main__":     os = platform.system()     if os == "Windows":         w_disk()     elif os == "Linux":         L_disk() 

此指令碼主要用於zabbix監控系統硬碟只用,適用於windows和linux系統,傳回值為0為正常,有幾個分區的硬碟剩餘少於10G或低於10%就為警示閥值(windows的C盤和linux的根分區除外 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.