Skip to content

Commit 0138ec3

Browse files
committed
Merge pull request ganglia#135 from evanjfraser/master
Fibrechannel module updated
2 parents 75d9a59 + b20a91f commit 0138ec3

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

fibrechannel/README.mkdn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ This is gmond python module that allows SNMP polling of Fibrechannel switches to
33

44
* It works for Brocade FC switches, and probably for any other SNMP enabled switch.
55
* It requires pysnmp (available in debian repositorys)
6+
* Now executes SNMP queries as a separate thread
67
* Handles polling multiple switches from a single gmond.
78
* Spoofs the switch hostname, so each switch shows up separately in ganglia
89

fibrechannel/fibrechannel.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
# Author: Evan Fraser [email protected]
55
# Date: August 2012
66
# Copyright: GPL
7+
# Updated 21/03/2014 to do SNMP calls threaded.
78

89
import sys
910
import os
1011
import re
1112
import time
13+
import threading
1214
import pprint
1315
from pysnmp.entity.rfc3413.oneliner import cmdgen
1416
NIPARAMS = {}
@@ -18,7 +20,8 @@
1820
'data' : {}
1921
}
2022
LAST_NIMETRICS = dict(NIMETRICS)
21-
NIMETRICS_CACHE_MAX = 5
23+
NIMETRICS_CACHE_MAX = 10
24+
SNMPTABLE = {}
2225

2326
descriptors = list()
2427

@@ -33,18 +36,21 @@
3336
'ifOutErrors' : (1,3,6,1,2,1,2,2,1,20),
3437
}
3538

39+
3640
def get_metrics():
3741
"""Return all metrics"""
3842

39-
global NIMETRICS, LAST_NIMETRICS
43+
global NIMETRICS, LAST_NIMETRICS, SNMPTABLE
4044

4145
# if interval since last check > NIMETRICS_CACHE_MAX get metrics again
4246
if (time.time() - NIMETRICS['time']) > NIMETRICS_CACHE_MAX:
4347
metrics = {}
4448
for para in NIPARAMS.keys():
4549
if para.startswith('switch_'):
4650
ipaddr,name = NIPARAMS[para].split(':')
47-
snmpTable = runSnmp(oidDict,ipaddr)
51+
#snmpTable = runSnmp(oidDict,ipaddr)
52+
threading.Thread(runSnmp(oidDict,ipaddr))
53+
snmpTable = SNMPTABLE[ipaddr]
4854
newmetrics = buildDict(oidDict,snmpTable,name)
4955
metrics = dict(newmetrics, **metrics)
5056

@@ -75,7 +81,7 @@ def get_delta(name):
7581

7682
# Separate routine to perform SNMP queries and returns table (dict)
7783
def runSnmp(oidDict,ip):
78-
84+
global SNMPTABLE
7985
# cmdgen only takes tuples, oid strings don't work
8086

8187
# 'ifIndex' : (1,3,6,1,2,1,2,2,1,1),
@@ -111,7 +117,8 @@ def runSnmp(oidDict,ip):
111117
errorStatus.prettyPrint(), errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
112118
)
113119
else:
114-
return(varBindTable)
120+
#return(varBindTable)
121+
SNMPTABLE[ip] = varBindTable
115122

116123
def buildDict(oidDict,t,switch): # passed a list of tuples, build's a dict based on the alias name
117124
builtdict = {}
@@ -146,7 +153,11 @@ def buildDict(oidDict,t,switch): # passed a list of tuples, build's a dict based
146153
# define_metrics will run an snmp query on an ipaddr, find interfaces, build descriptors and set spoof_host
147154
# define_metrics is called from metric_init
148155
def define_metrics(Desc_Skel, ipaddr, switch):
149-
snmpTable = runSnmp(oidDict,ipaddr)
156+
global SNMPTABLE
157+
snmpThread = threading.Thread(runSnmp(oidDict,ipaddr))
158+
snmpTable = SNMPTABLE[ipaddr]
159+
160+
#snmpTable = runSnmp(oidDict,ipaddr)
150161
aliasdict = buildDict(oidDict,snmpTable,switch)
151162
spoof_string = ipaddr + ':' + switch
152163
#print newdict

0 commit comments

Comments
 (0)