WordPress.com



#!/usr/bin/env python

""" Write a script to test a servers network connectivity and the upstream

services on which it depends (e.g., DNS, file service, LDAP or other

directory service).

SNMP

CPU Statistics

Load

1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1

5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2

15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3

CPU

percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0

raw user cpu time: .1.3.6.1.4.1.2021.11.50.0

percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0

raw system cpu time: .1.3.6.1.4.1.2021.11.52.0

percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0

raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0

raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0

Memory Statistics

Total Swap Size: .1.3.6.1.4.1.2021.4.3.0

Available Swap Space: .1.3.6.1.4.1.2021.4.4.0

Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0

Total RAM used: .1.3.6.1.4.1.2021.4.6.0

Total RAM Free: .1.3.6.1.4.1.2021.4.11.0

Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0

Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0

Disk Statistics

The snmpd.conf needs to be edited. Add the following (assuming a machine with a single / partition):

disk / 100000 (or)

includeAllDisks 10% for all partitions and disks

The OIDs are as follows

Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1

Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1

Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1

Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1

Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1

Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1

Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1

System Uptime: .1.3.6.1.2.1.1.3.0

"""

import netsnmp

import sys

import datetime

# create a class for snmp session

class snmpSession(object):

""" a base class for snmp session"""

def __init__(self,oid="sysDescr", Version=2, DestHost="localhost", Community="linux"):

self.oid = oid

self.Version = Version

self.DestHost = DestHost

munity = Community

def query(self):

"""snmp query session"""

try:

result = netsnmp.snmpget(self.oid, Version = self.Version, DestHost = self.DestHost, Community = munity)

except:

import sys

print sys.exc_info()

result = None

return result

# verify number of input parameters

if len(sys.argv) != 2:

print "Usage: ./snmpServerMonitor \n"

print "where is the name of the server that needs to be monitored"

sys.exit(1)

# create a file with server statistics

currentDate = datetime.date.today().strftime('%Y%m%d')

fServerMon = "/home/andrei/software/scripts/python/proiecte/" + sys.argv[1] + "_" + currentDate + ".txt"

f = open(fServerMon,'w')

f.write("\tMonitoring server " + sys.argv[1] + "\n\n\n")

# new snmp connection

z = snmpSession()

z.DestHost = sys.argv[1]

# cpu statistics

f.write("CPU Statistics\n\nLoad\n")

z.oid = ".1.3.6.1.4.1.2021.10.1.3.1" # 1 minute load

f.write("1 minute load: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.10.1.3.2" # 5 minute load

f.write("5 minute load: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.10.1.3.3" # 15 minute load

f.write("15 minute load: " + z.query()[0] + "\n\n")

f.write("CPU\n")

z.oid = ".1.3.6.1.4.1.2021.11.9.0" # percentage of user CPU time

f.write("percentage of user CPU time: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.11.50.0" # raw user cpu time

f.write("raw user cpu time: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.11.10.0" # percentage of system CPU time

f.write("percentage of system CPU time: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.11.52.0" # percentage of idle CPU time

f.write("percentage of idle CPU time: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.11.53.0" # raw idle cpu time

f.write("raw idle cpu time: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.11.51.0" # raw nice cpu time

f.write("raw nice cpu time: " + z.query()[0] + "\n\n\n")

# memory statistics

f.write("Memory Statistics (mb)\n\n")

z.oid = ".1.3.6.1.4.1.2021.4.3.0" # total swap size

f.write("total swap size: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.4.4.0" # available swap size

f.write("available swap size: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.4.5.0" # total ram

f.write("total ram: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.4.6.0" # ram used

f.write("ram used: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.4.11.0" # ram free

f.write("ram free: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.4.13.0" # ram shared

f.write("ram shared: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.4.14.0" # ram buffered

f.write("ram buffered: " + z.query()[0] + "\n\n\n")

# disk statistics

f.write("Disk Statistics\n\n")

z.oid = ".1.3.6.1.4.1.2021.9.1.2.1" # path where the disk is mounted

f.write("path where the disk is mounted: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.9.1.3.1" # path of the device for the partition

f.write("path of the device for the partition: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.9.1.6.1" # total size of the disk/partion (kBytes)

f.write("total size of the disk/partion (kBytes): " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.9.1.7.1" # available space on the disk

f.write("available space on the disk: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.9.1.8.1" # used space on the disk

f.write("used space on the disk: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.9.1.9.1" # percentage of space used on disk

f.write("percentage of space used on disk: " + z.query()[0] + "\n")

z.oid = ".1.3.6.1.4.1.2021.9.1.10.1" # percentage of inodes used on disk

f.write("percentage of inodes used on disk: " + z.query()[0] + "\n\n")

f.close()

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download