Skip to content

Commit f11f409

Browse files
authored
Merge pull request #317 from Helene/raw_counters
Improve rawCounters setting management by PrometheusExporter
2 parents a4b06a0 + d86cd46 commit f11f409

File tree

7 files changed

+61
-2
lines changed

7 files changed

+61
-2
lines changed

source/config.ini

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
# Port number the bridge listening on for Prometheus server requests;
1414
# prometheus = 9250
1515

16-
# Sensor counters deltas will be exported by default.
17-
# Set True if you want export original sensor counters.
16+
# By default, the original values from the platform will be displayed alongside
17+
# the timestamps at which they were measured. This can slow down a ZIMON query
18+
# performance.
19+
# Set rawCounters to False to accelerate query execution time. Keep in mind that
20+
# the exposed timestamps will represent the time at which the value was collected
21+
# from the platform and added to a bucket.
22+
# Sensors including 'increasing counters' metric types will still run in
23+
# rawCounters mode.
1824
rawCounters = True
1925

2026
##################### API Protocol scheme #####################################

source/messages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
'MetricErr': 'Metric {0} cannot be found. Please check if the corresponding sensor is configured',
4646
'InconsistentParams': 'Received parameters {} inconsistent with request parameters {}',
4747
'SensorDisabled': 'Sensor for metric {} is disabled',
48+
'SensorForceRawData': 'Sensor {} includes metrics type counter, which need to be collected as raw data',
4849
'EndpointNotSupported': 'Endpoint {} you try to access is not supported',
4950
'EndpointNotSupportedForPort': 'Endpoint {} is not supported for port {}',
5051
'NoData': 'Empty results received', # Please check the pmcollector is properly configured and running.

source/metadata.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,22 @@ def GET(self, **params):
185185
resp = self.SensorsConfig
186186
# resp = json.dumps(resp)
187187

188+
# /metadata/sensorsconfig
189+
elif '/metadata/sensormetrics' == cherrypy.request.script_name:
190+
resp = {}
191+
sensors = []
192+
# cherrypy.response.headers['Content-Type'] = 'application/json'
193+
if params.get('sensor') is None:
194+
sensors = self.metaData.sensorsSpec.keys()
195+
else:
196+
sensor = params.get('sensor')
197+
self.logger.info(f"Received request for endpoint /metadata/sensormetrics: {sensor}")
198+
sensors.append(sensor)
199+
for sensor in sensors:
200+
metricsData = self.metaData.getSensorMetricTypes(sensor)
201+
resp[sensor] = metricsData
202+
# resp = json.dumps(resp)
203+
188204
del cherrypy.response.headers['Allow']
189205
cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
190206
# cherrypy.response.headers['Content-Type'] = 'application/json'

source/prometheus.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ def build_collector(self, sensor) -> SensorCollector:
133133
if self.raw_data:
134134
attrs = {'sensor': sensor, 'period': period,
135135
'nsamples': period, 'rawData': True}
136+
elif "counter" in self.TOPO.getSensorMetricTypes(sensor).values():
137+
attrs = {'sensor': sensor, 'period': period,
138+
'nsamples': period, 'rawData': True}
139+
self.logger.debug(MSG['SensorForceRawData'].format(sensor))
136140
else:
137141
attrs = {'sensor': sensor, 'period': period,
138142
'nsamples': 1}

source/queryHandler/Topo.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ def getSensorMetricNames(self, searchSensor: str) -> list:
241241
return metrics.values()
242242
return []
243243

244+
def getSensorMetricTypes(self, searchSensor: str) -> Dict[str, str]:
245+
sensorMetricsTypes = {}
246+
metrics = self.__metricsDef.get(searchSensor, None)
247+
if metrics:
248+
typesDict = self.__metricsType
249+
sensorMetricsTypes = {metric: typesDict[metric] for metric in metrics.values()}
250+
return sensorMetricsTypes
251+
244252
def getSensorsForMeasurementMetrics(self, searchMetrics):
245253
sensorsList = []
246254
for metric in searchMetrics:

source/zimonGrafanaIntf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ def main(argv):
290290
{'request.dispatch': cherrypy.dispatch.MethodDispatcher()}
291291
}
292292
)
293+
# query for list zimon sensor metrics
294+
cherrypy.tree.mount(mdHandler, '/metadata/sensormetrics',
295+
{'/':
296+
{'request.dispatch': cherrypy.dispatch.MethodDispatcher()}
297+
}
298+
)
293299

294300
# register OpenTSDB API endpoints
295301
if args.get('port', None):

tests/test_topo_parser.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,21 @@ def test_case01():
2222
sensorLabels = topo.getSensorLabels(searchSensor)
2323
assert len(sensorLabels) > 0
2424
assert "gpfs_disk_name" in sensorLabels
25+
26+
27+
@with_setup(my_setup)
28+
def test_case02():
29+
searchSensor = 'GPFSDiskCap'
30+
typesDict = topo.getSensorMetricTypes(searchSensor)
31+
assert len(typesDict) > 0
32+
assert 'counter' not in typesDict.values()
33+
assert 'gpfs_disk_disksize' in typesDict.keys()
34+
assert typesDict['gpfs_disk_disksize'] == 'quantity'
35+
36+
37+
@with_setup(my_setup)
38+
def test_case03():
39+
searchSensor = 'GPFSNSDFS'
40+
typesDict = topo.getSensorMetricTypes(searchSensor)
41+
assert len(typesDict) > 0
42+
assert 'counter' in typesDict.values()

0 commit comments

Comments
 (0)