Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: modules/nagios/files/check_memory

Issue 29382622: Noissue - Handle nodes without swap (Closed)
Patch Set: Created March 13, 2017, 11:10 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import re, argparse 3 import re, argparse
4 4
5 def format_memory(bytes): 5 def format_memory(bytes):
6 if bytes >= 1024 * 1024: 6 if bytes >= 1024 * 1024:
7 return "%i MB" % (bytes / (1024 * 1024)) 7 return "%i MB" % (bytes / (1024 * 1024))
8 elif bytes >= 1024: 8 elif bytes >= 1024:
9 return "%i kB" % (bytes / 1024) 9 return "%i kB" % (bytes / 1024)
10 else: 10 else:
(...skipping 24 matching lines...) Expand all
35 else: 35 else:
36 value = int(value) 36 value = int(value)
37 meminfo[label] = value 37 meminfo[label] = value
38 38
39 memtotal = meminfo.get("memtotal", 0) 39 memtotal = meminfo.get("memtotal", 0)
40 memfree = meminfo.get("memfree", 0) + meminfo.get("buffers", 0) + meminfo.get( "cached", 0) 40 memfree = meminfo.get("memfree", 0) + meminfo.get("buffers", 0) + meminfo.get( "cached", 0)
41 swaptotal = meminfo.get("swaptotal", 0) 41 swaptotal = meminfo.get("swaptotal", 0)
42 swapfree = meminfo.get("swapfree", 0) + meminfo.get("swapcached", 0) 42 swapfree = meminfo.get("swapfree", 0) + meminfo.get("swapcached", 0)
43 43
44 mempercentage = round(float(memfree) / memtotal * 100) 44 mempercentage = round(float(memfree) / memtotal * 100)
45 swappercentage = round(float(swapfree) / swaptotal * 100) 45 swappercentage = round(float(swapfree) / swaptotal * 100) if swaptotal else 0
46 46
47 status = "memory %i%% (%s/%s) swap %i%% (%s/%s)" % ( 47 status = "memory %i%% (%s/%s) swap %i%% (%s/%s)" % (
48 mempercentage, format_memory(memfree), format_memory(memtotal), 48 mempercentage, format_memory(memfree), format_memory(memtotal),
49 swappercentage, format_memory(swapfree), format_memory(swaptotal) 49 swappercentage, format_memory(swapfree), format_memory(swaptotal)
50 ) 50 )
51 51
52 perfdata = "memory=%i;%i;%i swap=%i;%i;%i" % ( 52 perfdata = "memory=%i;%i;%i swap=%i;%i;%i" % (
53 mempercentage, args.memwarn, args.memcrit, 53 mempercentage, args.memwarn, args.memcrit,
54 swappercentage, args.swapwarn, args.swapcrit 54 swappercentage, args.swapwarn, args.swapcrit
55 ) 55 )
56 56
57 output = "%s|%s" % (status, perfdata) 57 output = "%s|%s" % (status, perfdata)
58 58
59 if mempercentage <= args.memcrit or swappercentage <= args.swapcrit: 59 if mempercentage <= args.memcrit or swappercentage <= args.swapcrit:
60 print "CRITICAL - " + output 60 print "CRITICAL - " + output
61 elif mempercentage <= args.memwarn or swappercentage <= args.swapwarn: 61 elif mempercentage <= args.memwarn or swappercentage <= args.swapwarn:
62 print "WARNING - " + output 62 print "WARNING - " + output
63 else: 63 else:
64 print "OK - " + output 64 print "OK - " + output
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld