Hi all
I have the following series of metrics -
{“fields”:{“pool_name”:“POOL1”,“utilization”:27.8},“name”:“pools”,“tags”:{“host”:“trn-wangw1”},“timestamp”:1725310116}
{“fields”:{“pool_name”:“POOL2”,“utilization”:18.1},“name”:“pools”,“tags”:{“host”:“trn-wangw1”},“timestamp”:1725310116}
{“fields”:{“pool_name”:“POOL3”,“utilization”:6.3},“name”:“pools”,“tags”:{“host”:“trn-wangw1”},“timestamp”:1725310116}
{“fields”:{“pool_name”:“POOL4”,“utilization”:6.7},“name”:“pools”,“tags”:{“host”:“trn-wangw1”},“timestamp”:1725310116}
{“fields”:{“pool_name”:“POOL5”,“utilization”:2.4},“name”:“pools”,“tags”:{“host”:“trn-wangw1”},“timestamp”:1725310116}
{“fields”:{“pool_name”:“POOL6”,“utilization”:3.1},“name”:“pools”,“tags”:{“host”:“trn-wangw1”},“timestamp”:1725310116}
{“fields”:{“pool_name”:“POOL7”,“utilization”:0.4},“name”:“pools”,“tags”:{“host”:“trn-wangw1”},“timestamp”:1725310116} and I need to combine these metrics into one per host tag.
Is it possible with help starlark ?
Please outline how your configuration looks like and what you tried. There is the merge aggregator which does exactly this, combining metrics with the same name, tag-set and timestamp into one metric. Please make sure your fields are named differently for each metric…
Thank you very much for your reply
I work with dialout telemetry that I receive from cisco ios heh, in my configuration there is a starlark script that calculates the value of disposal for dhcp pools :
[[processors.starlark]]
source = ‘’’
def round(number, decimals):
factor = 10
for _ in range(decimals - 1):
factor *= 10
return int(number * factor + 0.5) / factor
def apply(metric):
// Extract required fields from the metric
excluded_addr = metric.fields.get(‘subnet_info/stats/excluded_addresses’)
leased_addr = metric.fields.get(‘subnet_info/stats/leased_addresses’)
total_addr = metric.fields.get(‘subnet_info/stats/total_addresses’)
// Check if all fields are present and valid numbers
if excluded_addr != None and leased_addr != None and total_addr != None:
excluded_addr = int(excluded_addr)
leased_addr = int(leased_addr)
total_addr = int(total_addr)
// Calculate utilization
utilization = ((excluded_addr + leased_addr) / total_addr) * 100
metric.fields[“utilization”] = round(utilization, 1)
// Extract the required tags and fields
pool_name = metric.tags.get(‘pool_name’)
utilization = metric.fields.get(‘utilization’)
source_host = metric.tags.get(‘source’)
// Clear all tags and fields
metric.tags.clear()
metric.fields.clear()
// Re-add only the necessary tags and fields
metric.tags[‘host’] = source_host
metric.fields[‘utilization’] = utilization
metric.fields[‘pool_name’] = pool_name
return metric
‘’’
I receive metrics of type - {“fields”:{“pool_name”:“POOL7”,“utilization”:0.4},“name”:“pools”,“tags”:{“host”:“trn-wangw1”},“timestamp”:1725310116}
After that, the metrics in the form of json should be sent to zabix. But on zabbix metrics should come in the form - {“fields”:
{{“pool_name”:“POOL1”,“utilization”:0.4},“pool_name”:“POOL2”,“utilization”:1.4,“pool_name”:“POOL3”,“utilization”:2.4}},“name”:“pools”,“tags”:{“host”:“trn-wangw1”},“timestamp”:1725310116} they should be grouped by host and timestamp. I tried to solve it by adding it to the configuration [[aggregators.merge]]
drop_original = true
grace = “60s”
tags = [“host”]
but it did not help.
Could you explain how your ideal metric should look like on the Telegraf side (i.e. before sending to Zabbix)? Not very familiar with Zabbix so I’m probably not very helpful on this side…
Btw: Please use “preformatted text” sections for configs etc as this will make your post more readable…