I feel obliged to point out that this blog post is roughly 5 years and 1 month old. People change, opinions evolve. In just a few years, vast technological landscapes can shift. And don't get me started on config files. Please consider this text in the context of its time.

I’m playing a lot with Telegraf recently in order to get a handle on monitoring an Exadata or the Oracle DB with it. As I don’t have an Exadata at home, my source of data for my first steps with Telegraf were my IoT devices at home.

I have Youless energy monitoring devices in my home to log the energy consumption of my home. You will find some information about them at this site (sorry, it’s in Dutch). They can count LED blinks (which works really well) and they can count the passing of the red line on Ferraris wheel based power meters (which works well when it works but doesn’t work sometimes at all. I have four meters in my house, three of them are Ferraris based, two can be read, one not — and they look absolutely identical).

To integrate them into Telegraf is really straightforward. The nice thing about the Youless devices is that they deliver the data directly as JSON output by sending an HTTP request to them like http://aaa.bbb.xxx.yyy/a?f=j

{"cnt":" 7515,292","pwr":331,"lvl":0,"dev":"","det":"","con":"","sts":"","raw":0}

What I really hate about them is the fact that they deliver the count as a string with a leading whitespace. So I had to convert the string into a float.

So I just put the following file as youless.conf into /etc/telegraf/telegraf.d in order to read the data into my InfluxDB.

[[inputs.http]]
  urls = [
    "http://aaa.bbb.xxx.yyy/a?f=j",
    "http://aaa.bbb.xxx.yyy/a?f=j"
  ]
  data_format = "json"
  interval = "60s"
  json_string_fields = ["cnt"]
  [inputs.http.tags]
   sourcedevice = "youless"
[[processors.regex]]
  order=1
  [processors.regex.tagpass]
    sourcedevice = ["youless"]
  [[processors.regex.fields]]
    key = "cnt"
    pattern = "^\\s*([0-9]*),([0-9]*)$"
    replacement = "${1}.${2}"
    result_key = "cnt_kwh"
    drop_original = true
[[processors.converter]]
  order=2
  [processors.converter.tagpass]
    sourcedevice = ["youless"]
  [processors.converter.fields]
    float = ["cnt_kwh"]

This currently works reasonably well.

Written by

Joerg Moellenkamp

Grey-haired, sometimes grey-bearded Windows dismissing Unix guy.