Skip to content
This repository was archived by the owner on Sep 16, 2018. It is now read-only.

Commit 3c2e3a4

Browse files
committed
Gauge type override logic for blob series
Some vendors like Fortigate publish sensor values as OCTECTSTR instead of doing like Cisco and scaling the value. This commit will export metrics that can be fully (all values) converted to float as a gauge series.
1 parent 85844b5 commit 3c2e3a4

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/snmpcollector/src/exporter.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ def export(self, target, result):
120120
target.host, target.layer, result.index, result.data.type)] = (
121121
result.data.value, target.timestamp, result.labels)
122122

123+
def is_only_numeric(self, labels_map):
124+
for (value, _, _) in labels_map.itervalues():
125+
try:
126+
float(value)
127+
except ValueError:
128+
return False
129+
return True
130+
123131
def run_dump(self):
124132
while True:
125133
# Since the label map will be mutated we need to do a deep copy here.
@@ -131,6 +139,13 @@ def run_dump(self):
131139
# Assemble the output
132140
out = []
133141
for obj, (mib, metrics_type, labels_map) in metrics_copy.iteritems():
142+
# Some vendors (e.g. Fortigate) choose to have decimal values as
143+
# OCTETSTR instead of a scaled value. Try to convert all values, if
144+
# we succeed export this metric as guage.
145+
convert_to_float = False
146+
if metrics_type == 'blob' and self.is_only_numeric(labels_map):
147+
metrics_type = 'gauge'
148+
convert_to_float = True
134149
if metrics_type != 'counter' and metrics_type != 'gauge':
135150
continue
136151
out.append('# HELP {0} {1}::{0}\n'.format(obj, mib))
@@ -150,6 +165,9 @@ def run_dump(self):
150165
label_string = ','.join(label_list)
151166
instance = ''.join([obj, '{', label_string, '}'])
152167

168+
if convert_to_float:
169+
value = float(value)
170+
153171
out.append('{0} {1} {2}\n'.format(
154172
instance, value, int(timestamp * 1000)))
155173

0 commit comments

Comments
 (0)