Created
February 14, 2012 03:17
-
-
Save whatvn/1823093 to your computer and use it in GitHub Desktop.
Nagios script for Moosefs monitoring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Nagios monitoring script for moosefs master server | |
# Based on mfscgiserv from moosefs author | |
# hungnv 13022012 | |
import socket | |
import struct | |
import sys | |
def mysend(socket,msg): | |
totalsent = 0 | |
while totalsent < len(msg): | |
sent = socket.send(msg[totalsent:]) | |
if sent == 0: | |
raise RuntimeError, "socket connection broken" | |
totalsent = totalsent + sent | |
def myrecv(socket,leng): | |
msg = '' | |
while len(msg) < leng: | |
chunk = socket.recv(leng-len(msg)) | |
if chunk == '': | |
raise RuntimeError, "socket connection broken" | |
msg = msg + chunk | |
return msg | |
def get_master_stat(masterhost, masterport): | |
out = [] | |
try: | |
s= socket.socket() | |
s.connect((masterhost,masterport)) | |
#print "connecting..." | |
mysend(s,struct.pack(">LL",510,0)) | |
header = myrecv(s,8) | |
cmd,length = struct.unpack(">LL",header) | |
if cmd==511 and length==68: | |
data = myrecv(s,length) | |
#total,avail,trspace,trfiles,respace,refiles,nodes,chunks,tdcopies = struct.unpack(">QQQLQLLLL",data) | |
v1,v2,v3,total,avail,trspace,trfiles,respace,refiles,nodes,dirs,files,chunks,allcopies,tdcopies = struct.unpack(">HBBQQQLQLLLLLLL",data) | |
if total and avail: | |
#print "Total: " + str(total) | |
#print "Available: " + str(avail) | |
free_space = avail/1000000000000 | |
#print free_space | |
if free_space < 1: return 2 | |
return 0 | |
else: | |
return 1 | |
except Exception, e: | |
return 3 | |
if __name__=='__main__': | |
address = 'master_ip' | |
port = 9421 | |
result = get_master_stat(address, port) | |
if result == 0: | |
print "Storage farm is functioning fine." | |
sys.exit(0) | |
elif result == 1: | |
print "StorageMaster: Cannot unpack result from server." | |
sys.exit(2) | |
elif result == 2: | |
print "Storage farm: freespace is less than 1 TB." | |
sys.exit(2) | |
elif result == 3: | |
print "Storage farm error: unknown error, cannot connect to master server." | |
sys.exit(2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment