2

I'm looking for a way to round the values output from telergaf. Temperature, usage_idle, memory_usage, etc... to 14 decimals is very huge. It too much for me. It can double some of my measurements.

I haven't found a way to do it easily.

Now I have this in output:

cpu,host=nuc usage_system=1.4107433532279232,usage_idle=95.06239826368747,usage_iowait=0.37981551817639264,usage_user=2.007596310360536

and I would like that:

cpu,host=nuc usage_system=1.4,usage_idle=95.0,usage_iowait=0.4,usage_user=2.0

I guess you'd have to use a processor, but how do you do that in a simple way? starlark just to round a value ?

3 Answers3

2

Sorry, this is a bit of an old thread, but I had the same need, and did not find any built in way to do this given that even Starlarks Math module round function will only round to whole integers.

My approach was very similar.

I wanted single digit precision after the decimal for most of my weather station data since there is no way the sensors are more accurate than that.

So I went with (inside a starlark routine): v = float(int(v*10))/10

It seemed to do what I need and should survive the 0 case.

Tas
  • 21
  • 2
1

I'm not very convinced of my solution, but I did like this... Using a starlak processor.

I haven't found a way to reach a real round function.

[[processors.starlark]]
  source = '''
def apply(metric):
  for k, v in metric.fields.items():
    if type(v) == 'float':
      f = metric.fields[k]
      if (int(f) != 0):
        metric.fields[k] = float(int(f) + float(int((f % int(f)) * 10) / 10))
      else:
        metric.fields[k] = float(int(f * 10) / 10)
  return metric
'''
0

Can you tell where your limitation is? Is it the message size or rather the storage on the InfluxDB? Or is it rather on presenting the data?

Even if you reduce the decimals in telegraf, I believe InfluxDB will still store a float field with 8 byte. So in that case you wouldn't have any advantage.

https://medium.com/dataseries/analysis-of-the-storage-mechanism-in-influxdb-b84d686f3697#4e6e

StephanM.
  • 1
  • 2
  • I don't really have any limitations. My main need is to reduce my payload. Limiting the measures to the one I use only has already greatly reduced my network load and the CPU load of my MQTTs. I figured why not go further by rounding the values. – Julien Brdy Dec 23 '20 at 17:03