-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnmpstat.py
72 lines (50 loc) · 1.96 KB
/
snmpstat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python3
#PYTHON SCRIPT TO MONITOR CPU LOAD AND MEMORY USAGE WITH SNMP AGENT
#IMPORT
import sys
import time
from time import sleep
from easysnmp import Session, snmp_get
#PARAMETERS CHECK
community = input('Enter the community --> ')
hostname = input('Enter hostname --> ')
num_iter = input('Enter the number of iterations --> ')
version = '2'
if (len(community)==0 or len(hostname)==0):
print('Invalid parameters ... Try again!')
sys.exit()
version = int(version)
num_iter = int(num_iter)
if(num_iter <= 0):
print('This parameter must be positive ... Try again!')
###################################################
#CPU LOAD
def CPU_load(session):
print('[CPU LOAD]')
CPU_1minuteload = session.get('laLoad.1') #UDC-SNMP-MIB::laLoad.1
CPU_5minuteload = session.get('laLoad.2') #UDC-SNMP-MIB::laLoad.2
CPU_10minuteload = session.get('laLoad.3') #UDC-SNMP-MIB::laLoad.3
print('1 minute load: ' + CPU_1minuteload.value)
print('5 minute load: ' + CPU_5minuteload.value)
print('10 minute load: ' + CPU_10minuteload.value + '\n')
#####################################################
#MEMORY STATS
def MEM_stats(session):
print('[MEMORY STATISTICS]')
MEM_tot = session.get('memTotalReal.0') #UDC-SNMP-MIB::memTotalReal.0
MEM_avail = session.get('memAvailReal.0') #UDC-SNMP-MIB::AvailReal.0
MEM_buff = session.get('memBuffer.0') #UDC-SNMP-MIB::memBuffer.0
MEM_cache = session.get('memCached.0') #UDC-SNMP-MIB::memCached.0
print('Total: ' + MEM_tot.value + ' kB')
print('Available: ' + MEM_avail.value + ' kB')
print('Buffered: ' + MEM_buff.value + ' kB')
print('Cached: ' + MEM_cache.value + ' kB')
#####################################################
session = Session(hostname=hostname,community=community,version=version) #SNMP SESSION
for i in range(num_iter):
print('\n' + str(i+1) + ') ' + time.ctime())
print('************ REPORT ************')
CPU_load(session)
MEM_stats(session)
print('********** END OF REPORT **********\n\n')
sleep(5)