The problem
- Telegraf gives errors
**2020-12-02T18:58:07Z E! [processors.starlark] Error in plugin: key “Allocated Virtual Memory” not in Fields.
=====
telegraf.conf has:
[[inputs.snmp]]
agents = [“udp://127.0.0.1:161”]
name = “Local VM”
:
[[inputs.snmp]]
agents = [“udp://192.168.9.1:161,udp://192.168.9.1:162”]
name = “remote VM”
:
[[processors.starlark]]
script = “/home/hn1961/starlark/mine.star”
===
The starlark script ‘mine.star’ has the following:
def apply(metric):
allocatedMem = metric.fields[‘Allocated Virtual Memory’]
usedMem = metric.fields[‘Used Virtual Memory’]
metric.fields[‘freeMem’]= allocatedMem - usedMem
return metric
===
The goal
To have a new metric ‘freeMem’ with the desirable result.
==
Observations
- Chronograf shows:
- Only 127.0.0.1 (with measurement=“Local VM”) have metric names and data.
- Other hosts (192.168.x.x) associated with name = “remote VM” have metric names but no data for any metric field.
- It appears that Telegraf stopped collecting metrics for hosts that do not have metrics mentioned in the starlark script.
=======
The environment:
- Both ‘Allocated Virtual Memory’ and ‘Used Virtual Memory’ are custom MIBs
- Only agent with measurement=“Local VM” has metrics ‘Allocated Virtual Memory’ and ‘Used Virtual Memory’
- Agents with Measurement = “remote VM” do not have the custom MIBs, hence, the metrics are not applicable to them.
======
I tried adding IF-ELSE statement in the starlark script so that the calculation are done for the ‘Local VM’ measurement.
However, I am unable to determine the Condition parameter, for instance,
def apply(metric):
if MEASUREMENT[‘Name’] == “Local VM”:
allocatedMem = metric.fields[‘Allocated Virtual Memory’]
usedMem = metric.fields[‘Used Virtual Memory’]
metric.fields[‘freeMem’]= allocatedMem - usedMem
return metric
else:
return metric
I get errors:
2020-12-02T19:08:56Z E! [telegraf] Error running agent: could not initialize processor starlark: /home/hn1961/starlark/sam.star:2:6: undefined: MEASUREMENT
Next Steps
Any pointer is greatly appreciated.