Python-implemented Monitoring server hard disk usage script sharing

Source: Internet
Author: User
This script is mainly used for Zabbix monitoring system hard disk only, for Windows and Linux systems, the return value of 0 is normal, there are several partitions of hard disk remaining less than 10G or less than 10% is the alarm threshold (except for Windows C-drive and Linux root partition):

Copy the Code code as follows:


#!/bin/env python
#-*-Coding:utf-8-*-
##########################################################
# @This script is used-to-check disk free space for Zabbix
# @Contact: wangwei03@jb51.net
# @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 <) 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 <) 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 ()
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.