Telegraf ignores some output from inputs.exec plugin

I have the following script:

import sys
import json
import subprocess
from pprint import pprint

x = subprocess.check_output(["C:\\Python36\\Scripts\\liquidctl.exe", "status", "--json"])
x = x.decode("ascii", errors="ignore")

corsair = json.loads(x)[0]

if corsair["description"] != "Corsair Commander Pro":

meas = corsair["status"]
ostr = "corsair "

for m in meas:
    name = m["key"].replace(" ", "_").replace("+", "")
    value = float(m["value"])
    ostr += "{}={},".format(name, value)
tele = ostr[0:-1]
print(tele, end="")

It outputs the following line:

So far so good, testing Telegraf with the following config:

> corsair,host=freenas 12V_rail=12.075,3.3V_rail=3.364,5V_rail=5.004,Fan_1_speed=668,Fan_2_speed=649,Fan_3_speed=684,Fan_4_speed=1396,Fan_5_speed=756,Temperature_1=24.23,Temperature_2=24.44,Temperature_3=19.84,Temperature_4=33.02 1636931880000000000

But, only the *rail entries are sent to InfluxDB:

Config fromt telegraf:


  commands = [
  timeout = "5s"
  data_format = "influx"

What is wrong here?

I can’t see the cause at the moment.

However, I would not assemble the influx line protocol manually myself, there are ready-made libraries for this.

Here is an example of how you could use it in your plugin:

from influxdb_client import Point

dictionary = dict()
dictionary['measurement'] = 'corsair'
dictionary['tags'] = dict()
dictionary['tags']['host'] = 'freenas'
dictionary['fields'] = dict()
dictionary['fields']['12V_rail'] = 12.075
dictionary['fields']['5V_rail'] = 5.004
dictionary['fields']['Fan_1_speed'] = 668
point = Point.from_dict(dictionary)  # metric from dict
print(point.to_line_protocol())  # write to stdout

Thanks, I have rewritten it with influxdb_client, but it did not help.

Script changes:

dictionary = dict()
dictionary['measurement'] = 'corsair'
dictionary['fields'] = dict()

for m in meas:
    name = m["key"].replace(" ", "_").replace("+", "")
    value = float(m["value"])
    dictionary['fields'][name] = value

point = Point.from_dict(dictionary)  # metric from dict
print(point.to_line_protocol())  # write to stdout

Script output:

corsair 12V_rail=12.078,3.3V_rail=3.364,5V_rail=5.001,Fan_1_speed=673,Fan_2_speed=654,Fan_3_speed=694,Fan_4_speed=1401,Fan_5_speed=816,Temperature_1=26.21,Temperature_2=27.04,Temperature_3=22.1,Temperature_4=34.89

Test outputs all values, but only the rails are sent to Influxdb.

> corsair,host=freenas 12V_rail=12.093,3.3V_rail=3.367,5V_rail=5.004,Fan_1_speed=675,Fan_2_speed=654,Fan_3_speed=698,Fan_4_speed=1399,Fan_5_speed=811,Temperature_1=26.23,Temperature_2=27.06,Temperature_3=22.1,Temperature_4=35.03 1636975253000000000

Telegraf 1.20.3 (git: HEAD 7a4e60aa)

What do you see, if you add a file output plugin (for debugging) in Telegraf?
Do you have any fields filter active in one of the plugins involved?

Debug = true was already set, but did not yield an error in the file.

I added output.file:

win_disk,host=freenas,instance=F:,objectname=LogicalDisk Percent_Disk_Time=0.012608564458787441,Percent_Disk_Read_Time=0.012608564458787441,Percent_Disk_Write_Time=0,Current_Disk_Queue_Length=0,Percent_Free_Space=9.781941413879395,Free_Megabytes=746436,Percent_Idle_Time=99.96805572509766 1636976941000000000
win_disk,host=freenas,instance=HarddiskVolume24,objectname=LogicalDisk Percent_Free_Space=16.3424129486084,Free_Megabytes=84,Percent_Idle_Time=99.98114776611328,Percent_Disk_Time=0,Percent_Disk_Read_Time=0,Percent_Disk_Write_Time=0,Current_Disk_Queue_Length=0 1636976941000000000
corsair,host=freenas 12V_rail=12.078,3.3V_rail=3.365,5V_rail=5.004 1636976942000000000

Other metrics are working. Not sure what you mean with field filters.

  ## Default data collection interval for all inputs
  interval = "30s"
  ## Rounds collection interval to 'interval'
  ## ie, if interval="10s" then always collect on :00, :10, :20, etc.
  round_interval = true

  ## Telegraf will cache metric_buffer_limit metrics for each output, and will
  ## flush this buffer on a successful write.
  metric_buffer_limit = 1000
  ## Flush the buffer whenever full, regardless of flush_interval.
  flush_buffer_when_full = true

  ## Collection jitter is used to jitter the collection by a random amount.
  ## Each plugin will sleep for a random time within jitter before collecting.
  ## This can be used to avoid many plugins querying things like sysfs at the
  ## same time, which can have a measurable effect on the system.
  collection_jitter = "0s"

  ## Default flushing interval for all outputs. You shouldn't set this below
  ## interval. Maximum flush_interval will be flush_interval + flush_jitter
  flush_interval = "10s"
  ## Jitter the flush interval by a random amount. This is primarily to avoid
  ## large write spikes for users running a large number of telegraf instances.
  ## ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s
  flush_jitter = "0s"

  ## Logging configuration:
  ## Run telegraf in debug mode
  debug = true
  ## Run telegraf in quiet mode
  quiet = false
  ## Specify the log file name. The empty string means to log to stdout.
  logfile = "/Program Files/Telegraf/telegraf.log"

  ## Override default hostname, if empty use os.Hostname()
  hostname = ""```

I can’t see any obvious error. :thinking:
Can it be that some fields start with an underscore - that would not be allowed as fieldname.

Don’t see any fields with underscores at the beginning:

{'fields': {'12V_rail': 12.078,
            '3.3V_rail': 3.364,
            '5V_rail': 5.004,
            'Fan_1_speed': 673.0,
            'Fan_2_speed': 655.0,
            'Fan_3_speed': 694.0,
            'Fan_4_speed': 1401.0,
            'Fan_5_speed': 816.0,
            'Temperature_1': 26.31,
            'Temperature_2': 27.09,
            'Temperature_3': 22.19,
            'Temperature_4': 34.97},
 'measurement': 'corsair'}

I have solved it. Somehow the plugin only sees the 12V measurement when running the script by Telegraf. The other entries are simply not there. Might have been because of some HID interactions when running as a service. Solved it differently (running the script directly, not via Telegraf)