Telegraf writes multiple datapoints to influxdb with different tag values

telegraf

#1

I cant get it done :-(((

My python code generates this:

{
	"metrics": [{
			"fields": {
				"state": 1
			},
			"name": "vpnikestatus",
			"timestamp": 1541682407,
			"tags": {
				"peerip": "217.16.206.38",
				"cmapname": "mycompanies",
				"aclname": "tun-audi",
				"mygateway": "1.1.1.1"
			}
		}, {
			"fields": {
				"state": 3
			},
			"name": "vpnikestatus",
			"timestamp": 1541682407,
			"tags": {
				"ikeversion": 2,
				"usedip": "18.196.91.186",
				"mygateway": "1.1.1.1",
				"countrycode": "DE",
				"peerip": "18.196.91.186",
				"cmapname": "mycompanies",
				"longitude": 8.6842,
				"aclname": "tun-skoda",
				"latitude": 50.1155,
				"city": "Frankfurt am Main"
			}
		}, {
			"fields": {
				"state": 2
			},
			"name": "vpnikestatus",
			"timestamp": 1541682407,
			"tags": {
				"ikeversion": 1,
				"usedip": "80.152.197.230",
				"mygateway": "1.1.1.1",
				"countrycode": "DE",
				"peerip": "80.152.197.230",
				"cmapname": "mycompanies",
				"longitude": 7.75,
				"aclname": "tun-trabant",
				"latitude": 49.9667,
				"city": "Daxweiler"
			}
		},
		...
	]
}	

it is exact the same as the telegraf json batch output format like in the link below:

in the cli in influx I see that:
> show field keys from exec_vpnikestatus
name: exec_vpnikestatus
fieldKey fieldType
-------- ---------
metrics_0_fields_state float
metrics_0_timestamp float
metrics_100_fields_state float
metrics_100_timestamp float
metrics_101_fields_state float
metrics_101_tags_ikeversion float
metrics_101_tags_latitude float
metrics_101_tags_longitude float
metrics_101_timestamp float
metrics_102_fields_state float
metrics_102_timestamp float
metrics_103_fields_state float
metrics_103_tags_ikeversion float
metrics_103_tags_latitude float
metrics_103_tags_longitude float
metrics_103_timestamp float
metrics_104_fields_state float
metrics_104_timestamp float
metrics_105_fields_state float

for each datapoints it generates a new fieldname??? What the hell is this?
My aim is to write multiple datapoints with the same timestamp to the same measurement but with different tag values (the tag and field names are all the same in the python script output). I am deadly tired now, cannot sleep for days because of this shit… :frowning:

telegraf.conf:

[[inputs.exec]]
  command = "C:/Python27/python.exe C:/Python27/check_restapi_asavpn.py -d 172.156.144.234 -p fsfd"
  data_format = "json"
  name_suffix = "_vpnikestatus"
  interval = "300s"
  timeout = "30s"

#2

The telegraf can only add one data point at a time to a measurement?


#3

Add json_query = "metrics" to your config file. Read more in the docs


#4

I had to change the output of my script to this:

{
	"metrics": [{
			"peerip": "17.160.206.58",
			"usedip": "12.125.98.26",
			"name": "vpnikestatus",
			"countrycode": "DE",
			"ikeversion": 2,
			"cmapname": "mycompany",
			"state": 3,
			"longitude": 9.491,
			"aclname": "tun-3wgroup",
			"latitude": 51.2993,
			"city": null,
			"mygateway": "1.1.1.1"
		}, {
			"peerip": "109.70.39.12",
			"usedip": "212.15.98.226",
			"name": "vpnikestatus",
			"countrycode": "DE",
			"ikeversion": 2,
			"cmapname": "mycompany",
			"state": 3,
			"longitude": 9.491,
			"aclname": "tun-chartax",
			"latitude": 51.2993,
			"city": null,
			"mygateway": "1.1.1.1"
		}, 
...

as you see the keys with “fields” and “tags” and “name” has been deleted.
And with that config it looks realy good:

[[inputs.exec]]
  command = "C:/Python27/python.exe C:/Python27/check_restapi_asavpn.py -d 1.1.1.1 -p fsfd"
  data_format = "json"
  name_suffix = "_vpnikestatus"
  interval = "300s"
  timeout = "30s"
  json_query = "metrics"
  json_string_fields = [
      "ikeversion",
      "usedip",
      "mygateway",
      "countrycode",
      "city",
      "peerip",
      "cmapname",
      "longitude",
      "latitude",
	  "aclname"
  ]
  tag_keys = [
      "ikeversion",
      "usedip",
      "mygateway",
      "countrycode",
      "city",
      "peerip",
      "cmapname",
      "longitude",
      "latitude",
      "aclname"
  ]

Thanks for the help!