Gateway Metrics via scripting: How to get "gauge" object?

I have a script where I’m trying to get the metrics of the gateway using the javadocs. I have everything coming in except for the gauges.
On this line o = registry.gauge(item) I’m getting an attribute not found error:
AttributeError: 'com.codahale.metrics.MetricRegistry' object has no attribute 'gauge'

Which is strange, because that does exist in the javadocs and the singular version exists for all other metrics (histogram, meter, counter, etc.):
https://www.javadoc.io/doc/io.dropwizard.metrics/metrics-core/4.1.0-rc2/com/codahale/metrics/MetricRegistry.html#gauge--

I used dir to pull out the props/methods of the registry object, and I don’t see gauge (singular) in there :confused: only the plural version gauges. I see all of the other metrics as singular.

Any ideas?
@PGriffith @Kevin.Herron

def getGatewayMetrics():
	fn = 'getGatewaryMetrics'
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	context = IgnitionGateway.get()
	registry = context.getMetricRegistry()
	
	metrics = {}	
	items = registry.getCounters()
	for item in items:
		o = registry.counter(item)
		metrics[item] = {'type': 'counter',
						 'value': o.getCount()
						}
	
	items = registry.getMeters()
	for item in items:
		o = registry.meter(item)
		metrics[item] = {'type': 'meter',
						 'value_1min': o.getOneMinuteRate(),
						 'value_5min': o.getFiveMinuteRate(),
						 'value_15min': o.getFifteenMinuteRate()
						}
	
	items = registry.getGauges()
	for item in items:
		o = registry.gauge(item) ### <--- Error occurs here
		metrics[item] = {'type': 'gauge',
						 'value': o.getValue()
						}

#	items = registry.getHistograms()
#	for item in items:
#		o = registry.histogram(item)
	
	items = registry.getTimers()
	for item in items:
		o = registry.timer(item)
		metrics[item] = {'type': 'timer',
						 'value_1min': o.getOneMinuteRate(),
						 'value_5min': o.getFiveMinuteRate(),
						 'value_15min': o.getFifteenMinuteRate()
						}
	return metrics

I found another way to get them via the getGauges method. This probably shows my lack of Java knowledge :grimacing:
Still interested why gauges isn’t there though.
Edit: I can just use the item, duh… Thanks Travis

def getGatewayMetrics():
	fn = 'getGatewayMetrics'
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	context = IgnitionGateway.get()
	registry = context.getMetricRegistry()
	metrics = {}
	
	for item in registry.getCounters():
		metrics[item] = {'type': 'counter',
						 'value': item.getCount()
						}
	
	for item in registry.getMeters():
		metrics[item] = {'type': 'meter',
						 'value_1min': item.getOneMinuteRate(),
						 'value_5min': item.getFiveMinuteRate(),
						 'value_15min': item.getFifteenMinuteRate()
						}
	
	for item in registry.getGauges():
		metrics[item] = {'type': 'gauge',
						 'value': item.getValue()
						}

#	for item in registry.getHistograms():
	
	for item in registry.getTimers():
		metrics[item] = {'type': 'timer',
						 'value_1min': item.getOneMinuteRate(),
						 'value_5min': item.getFiveMinuteRate(),
						 'value_15min': item.getFifteenMinuteRate()
						}
	
	return metrics

Can't help you on that, but

Not sure what it's for, but be careful with that !

Oh, I’m being careful, I’m very wary of it! :joy:

What version of Ignition is this running on?

8.1.Ancient (8.1.5)

I wonder if it’s a Jython thing with the automatic bean exposure. I don’t readily see why, but that’s my only guess. gauges, meters and counters all return a Map<String, X>, so you should also be able to use items():

for key, gauge in registry.getGauges().items():
    metrics[key] = {...}
1 Like