Skip to content

Instantly share code, notes, and snippets.

@rodrickbrown
Created June 16, 2014 14:29
Show Gist options
  • Save rodrickbrown/22eb7ff9800206eaf4cd to your computer and use it in GitHub Desktop.
Save rodrickbrown/22eb7ff9800206eaf4cd to your computer and use it in GitHub Desktop.
from checks import AgentCheck
#from md5 import md5
from multiprocessing import Process
import subprocess as sp
import time
import sys
import shlex
class LBMStat(AgentCheck):
def check(self, instance):
if 'host' not in instance:
self.log.info('Skipping instance, host not defined.')
return
if 'port' not in instance:
self.log.info('No port configured using default snmp port => 11161')
port = instance.get('port',11161)
env = instance.get('env',None)
oid_list = ['TNW-MIB::tnwReceiverLbtrmNumberOfEntries.0',
'TNW-MIB::tnwReceiverLbtrmAggDgramsRcved.0',
'TNW-MIB::tnwReceiverLbtrmAggBytesRcved.0',
'TNW-MIB::tnwReceiverLbtrmAggNakPcktsSent.0',
'TNW-MIB::tnwReceiverLbtrmAggNaksSent.0',
'TNW-MIB::tnwReceiverLbtrmAggLost.0',
'TNW-MIB::tnwReceiverLbtrmAggNcfsIgnored.0',
'TNW-MIB::tnwReceiverLbtrmAggNcfsShed.0',
'TNW-MIB::tnwReceiverLbtrmAggNcfsRxDelay.0',
'TNW-MIB::tnwReceiverLbtrmAggNcfsUnknown.0',
'TNW-MIB::tnwReceiverLbtrmAggDuplicateData.0',
'TNW-MIB::tnwReceiverLbtrmAggOutOfOrder.0',
'TNW-MIB::tnwReceiverLbtrmAggUnrecoveredTxw.0',
'TNW-MIB::tnwReceiverLbtrmAggUnrecoveredTmo.0',
'TNW-MIB::tnwReceiverLbtrmAggLbmMsgsRcved.0',
'TNW-MIB::tnwReceiverLbtrmAggLbmMsgsNoTopicRcved.0',
'TNW-MIB::tnwReceiverLbtrmAggLbmReqsRcved.0',
'TNW-MIB::tnwReceiverLbtrmAggDgramsDroppedSize.0',
'TNW-MIB::tnwReceiverLbtrmAggDgramsDroppedType.0',
'TNW-MIB::tnwReceiverLbtrmAggDgramsDroppedVersion.0',
'TNW-MIB::tnwReceiverLbtrmAggDgramsDroppedHdr.0',
'TNW-MIB::tnwReceiverLbtrmAggDgramsDroppedOther.0',
'TNW-MIB::tnwReceiverTcpNumberOfEntries.0',
'TNW-MIB::tnwReceiverTcpAggBytesRcved.0',
'TNW-MIB::tnwReceiverTcpAggLbmMsgsRcved.0',
'TNW-MIB::tnwSourceLbtrmNumberOfEntries.0',
'TNW-MIB::tnwSourceLbtrmAggDgramsSent.0',
'TNW-MIB::tnwSourceLbtrmAggBytesSent.0',
'TNW-MIB::tnwSourceLbtrmAggNakPcktsRcved.0',
'TNW-MIB::tnwSourceLbtrmAggNaksRcved.0',
'TNW-MIB::tnwSourceLbtrmAggNaksIgnored.0',
'TNW-MIB::tnwSourceLbtrmAggNaksShed.0',
'TNW-MIB::tnwSourceLbtrmAggNaksRxDelayIgnored.0',
'TNW-MIB::tnwSourceLbtrmAggRxsSent.0',
'TNW-MIB::tnwSourceLbtrmAggRxBytesSent.0',
'TNW-MIB::tnwContextNumberOfEntries.0',
'TNW-MIB::tnwContextAggTrDgramsSent.0',
'TNW-MIB::tnwContextAggTrBytesSent.0',
'TNW-MIB::tnwContextAggTrBytesRcved.0',
'TNW-MIB::tnwContextAggTrSrcTopics.0',
'TNW-MIB::tnwContextAggTrRcvTopics.0',
'TNW-MIB::tnwContextAggTrRcvUnresolvedTopics.0',
'TNW-MIB::tnwContextAggLbtrmUnknownMsgsRcved.0'] tnwReceiverLbtrmNumberOfEntries = 0
tnwReceiverLbtrmAggDgramsRcved = 0
tnwReceiverLbtrmAggBytesRcved = 0
tnwReceiverLbtrmAggNakPcktsSent = 0
tnwReceiverLbtrmAggNaksSent = 0
tnwReceiverLbtrmAggLost = 0
tnwReceiverLbtrmAggNcfsIgnored = 0
tnwReceiverLbtrmAggNcfsShed = 0
tnwReceiverLbtrmAggNcfsRxDelay = 0
tnwReceiverLbtrmAggNcfsUnknown = 0
tnwReceiverLbtrmAggDuplicateData = 0
tnwReceiverLbtrmAggOutOfOrder = 0
tnwReceiverLbtrmAggUnrecoveredTxw = 0
tnwReceiverLbtrmAggUnrecoveredTmo = 0
tnwReceiverLbtrmAggLbmMsgsRcved = 0
tnwReceiverLbtrmAggLbmMsgsNoTopicRcved = 0
tnwReceiverLbtrmAggLbmReqsRcved = 0
tnwReceiverLbtrmAggDgramsDroppedSize = 0
tnwReceiverLbtrmAggDgramsDroppedType = 0
tnwReceiverLbtrmAggDgramsDroppedVersion = 0
tnwReceiverLbtrmAggDgramsDroppedHdr = 0
tnwReceiverLbtrmAggDgramsDroppedOther = 0
tnwSourceLbtrmNumberOfEntries = 0
tnwSourceLbtrmAggDgramsSent = 0
tnwSourceLbtrmAggBytesSent = 0
tnwSourceLbtrmAggNakPcktsRcved = 0
tnwSourceLbtrmAggNaksRcved = 0
tnwSourceLbtrmAggNaksIgnored = 0
tnwSourceLbtrmAggNaksShed = 0
tnwSourceLbtrmAggNaksRxDelayIgnored = 0
tnwSourceLbtrmAggRxsSent = 0
tnwSourceLbtrmAggRxBytesSent = 0
tnwReceiverTcpNumberOfEntries = 0
tnwReceiverTcpAggBytesRcved = 0
tnwReceiverTcpAggLbmMsgsRcved = 0
tnwContextNumberOfEntries = 0
tnwContextAggTrDgramsSent = 0
tnwContextAggTrBytesSent = 0
tnwContextAggTrDgramsRcved = 0
tnwContextAggTrBytesRcved = 0
tnwContextAggTrSrcTopics = 0
tnwContextAggTrRcvTopics = 0
tnwContextAggTrRcvUnresolvedTopics = 0
tnwContextAggLbtrmUnknownMsgsRcved = 0
oidstrlist = ""
for oid in oid_list:
oidstrlist += str(oid) + " "
oidstrlist = ""
for oid in oid_list:
oidstrlist += str(oid) + " "
host = instance['host']
default_timeout = self.init_config.get('default_timeout', 3)
timeout = float(instance.get('timeout', default_timeout))
#aggregation_key = md5(ip).hexdigest()
#command = "snmpget -v2c -r 0 -t 0.3 -m TNW-MIB -Pd -c public %s:%s %s" % (host,str(instance['port']),oidstrlist)
command = "snmpget -v2c -r 0 -t 0.3 -m TNW-MIB -Pd -c public %s:%s %s" % (host,port,oidstrlist)
command = shlex.split(command)
(res,err) = sp.Popen(command,stdout=sp.PIPE,stderr=sp.PIPE).communicate()
for data in res.split('\n'):
if 'tnwReceiverLbtrmNumberOfEntries' in data:
tnwReceiverLbtrmNumberOfEntries = float(data.split()[-1]) #rate32
self.rate('fxcm.tnwReceiver.Lbtrm.NumberOfEntries', tnwReceiverLbtrmNumberOfEntries, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggDgramsRcved' in data:
tnwReceiverLbtrmAggDgramsRcved = float(data.split()[-1]) #Counter64
self.rate('fxcm.tnwReceiver.Lbtrm.AggDgramsRcved', tnwReceiverLbtrmAggDgramsRcved, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggBytesRcved' in data:
tnwReceiverLbtrmAggBytesRcved = float(data.split()[-1]) #Counter64
self.rate('fxcm.tnwReceiver.Lbtrm.AggBytesRcved', tnwReceiverLbtrmAggBytesRcved, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggNakPcktsSent' in data:
tnwReceiverLbtrmAggNakPcktsSent = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggNakPcktsSent', tnwReceiverLbtrmAggNakPcktsSent, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggNaksSent' in data:
tnwReceiverLbtrmAggNaksSent = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggNaksSent', tnwReceiverLbtrmAggNaksSent, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggLost' in data:
tnwReceiverLbtrmAggLost = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggLost', tnwReceiverLbtrmAggLost, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggNcfsIgnored' in data:
tnwReceiverLbtrmAggNcfsIgnored = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggNcfsIgnored', tnwReceiverLbtrmAggNcfsIgnored, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggNcfsShed' in data:
tnwReceiverLbtrmAggNcfsShed = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggNcfsShed', tnwReceiverLbtrmAggNcfsShed, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggNcfsRxDelay' in data:
tnwReceiverLbtrmAggNcfsRxDelay = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggNcfsRxDelay', tnwReceiverLbtrmAggNcfsRxDelay, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggNcfsUnknown' in data:
tnwReceiverLbtrmAggNcfsUnknown = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggNcfsUnknown', tnwReceiverLbtrmAggNcfsUnknown, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggDuplicateData' in data:
tnwReceiverLbtrmAggDuplicateData = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggDuplicateData', tnwReceiverLbtrmAggDuplicateData, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggOutOfOrder' in data:
tnwReceiverLbtrmAggOutOfOrder = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggOutOfOrder', tnwReceiverLbtrmAggOutOfOrder, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggUnrecoveredTxw' in data:
tnwReceiverLbtrmAggUnrecoveredTxw = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggUnrecoveredTxw', tnwReceiverLbtrmAggUnrecoveredTxw, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggUnrecoveredTmo' in data:
tnwReceiverLbtrmAggUnrecoveredTmo = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggUnrecoveredTmo', tnwReceiverLbtrmAggUnrecoveredTmo, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggLbmMsgsRcved' in data:
tnwReceiverLbtrmAggLbmMsgsRcved = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggLbmMsgsRcved', tnwReceiverLbtrmAggLbmMsgsRcved, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggLbmMsgsNoTopicRcved' in data:
tnwReceiverLbtrmAggLbmMsgsNoTopicRcved = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggLbmMsgsNoTopicRcved', tnwReceiverLbtrmAggLbmMsgsNoTopicRcved, tags=[env],hostname=host)
if 'tnwReceiverLbtrmAggLbmReqsRcved' in data:
tnwReceiverLbtrmAggLbmReqsRcved = float(data.split()[-1])
self.rate('fxcm.tnwReceiver.Lbtrm.AggLbmReqsRcved', tnwReceiverLbtrmAggLbmReqsRcved, tags=[env],hostname=host)
if __name__ == '__main__':
check, instances = LBMStat.from_yaml('/etc/dd-agent/conf.d/lbm_stat.yaml')
for instance in instances:
print("\nRunning the check against host: (%s)" % (instance['host']))
check.check(instance)
time.sleep(3)
check.check(instance)
if check.has_events():
print('Events: %s' % (check.get_events()))
print('Metrics: %s' % (check.get_metrics()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment