-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to gather metrics with less complexity? #2
Comments
def masac_poller(device_type, timeout, retries, sqlitedbtable, banned):
""" Fetch SNMP metrics using fastsnmp module and send them to Carbon server """
# oids in group must be with same indexes
node = platform.node().replace('.', '-')
tags = ("Vlan","unrouted","thernet")
oid_group = {"1.3.6.1.2.1.2.2.1.2": "ifDescr", "1.3.6.1.2.1.2.2.1.10": "ifInOctets","1.3.6.1.2.1.2.2.1.16": "ifOutOctets",}
count = 0
for h in get_db_device_list(sqlitedbtable, device_type, banned):
timestamp = int(time.time())
hostnames = []
hostnames.append(h['ip'])
snmp_data = snmp_poller.poller(hostnames, (oid_group.keys(),), h['snmp_community'], int(timeout), int(retries))
if len(list(snmp_data)) < 1 or h['snmp_community'] == '':
update_device_in_db(sqlitedbtable, h['login'], device_type, 1)
print("Banned " + h['ip'])
continue
snmp_data = snmp_poller.poller(hostnames, (oid_group.keys(),), h['snmp_community'], int(timeout), int(retries))
e = {}
lines= []
for d in snmp_data:
metrics = []
oid = oid_group[d[1]]
host = d[0]
index = d[2]
value = d[3]
e['hostname'] = host
if "ifDescr" in oid:
e['ifDescr'] = value
e['index'] = index
if "ifInOctets" in oid:
pline = ("host=%s oid=%s.%s value=%s" % (host, oid, index, value))
e['ifHCInOctets'] = value
e['index'] = index
if "ifOutOctets" in oid:
e['ifHCOutOctets'] = value
e['index'] = index
metrics.insert(int(e['index']), e)
for device in metrics:
if len(device) == 5:
identity = h['login'].replace(".","_").replace("@","_at_")
if "sdsl" in device_type:
identity = str(h['hostname'].replace(".","_").replace("@","_at_")) + "_" + str(h['ip'])
for metric in ("ifHCInOctets","ifHCOutOctets"):
line = '%s.%s.%s.%s.%s %d %d' % (METRIC_PREFIX, device_type, identity, device['ifDescr'].replace("/","_").replace(" ","_"), metric, device[metric], timestamp)
if tags[0] not in device['ifDescr'] and tags[1] not in device['ifDescr'] and tags[2] in device['ifDescr']:
lines.append(line)
message = '\n'.join(lines) + '\n'
sock = socket.socket()
sock.connect((CARBON_SERVER, CARBON_PORT))
print(message)
sock.sendall(message.encode('UTF-8'))
sock.close()
hostnames.pop() # Pop the hostnames after fetching needed metrics
return count |
Check this example https://github.com/gescheit/fastsnmp/blob/master/examples/graphite_sender.py |
@gescheit Real thanks. I am going to check that soon and feedback. By the first read, I can tell this is some real python programming. |
Hi, gesheit, Do you have a benchmark for fastsnmp? Don't have to be accurate. For example, to poll one OID, how many hosts can it poll per second? 100, 1K, etc. To poll 4 OIDS, how many host can it poll per second? Thanks |
Hi! |
Thank you for your answer. I am very interested in your work. I may give it a try. From: gescheit <[email protected]mailto:[email protected]> Hi! Reply to this email directly or view it on GitHubhttps://github.com//issues/2#issuecomment-149358899. |
Hello,
As you can see in the following example, it's very expensive to get metrics with less complexity.
The text was updated successfully, but these errors were encountered: