Telgraf json -= first attempt


#1

I’m looking at moving some of my collection scripts for various apis to telegraf.

I have a json api that I pull, and I’d like to get some stats off it. Initially I’m getting everything…which includes history…all as fields. This isn’t needed.

Here’s teh json.

{  
   "week":13572129426,
   "total":6120460648188,
   "day":10737434940,
   "servers":{  
      "server1":{  
         "week":4887999375,
         "total":2351316601317,
         "day":2053517969,
         "daily":{  
            "2018-05-24":100:
            "2018-05-26":0
         },
         "month":52044101954
      },
      "server2":{  
         "week":0,
         "total":17262848955,
         "day":0,
         "daily":{  
            "2018-05-24":0,
            "2018-05-24":0
        },
        "month": 87387234
     },
     "month": 4284972934
}

So ideally , I’d like to pull the totals ($.week, $.day, $.total, $.month) as a whole (to one table), and then for each server: $.servers['server1'].week/day/total/month etc to another table.

I guess my main points is I need a way of excluding $.servers['serverx'].daily as the rest of the information would be fine.

Any pointers for this newbie?


#2

So like a dog with a bone I think I’ve managed to get something:

[[inputs.http]]
  ## One or more URLs from which to read formatted metrics
  interval = "5m"
  urls = [
    "http://sabnznd:8080/sabnzbd/api?apikey=apikey&output=json&mode=server_stats"
  ]
  #HTTP method
  method = "GET"
  timeout = "15s"
  data_format = "json"
  json_query = "servers"
  name_override = "sabnzbd_server_stats"
  tag_keys = [
     "week",
     "total",
     "month",
     "day"
  ]
  fielddrop = ["daily", "daily_*", "*_daily_*"]

which gives me:

time               server1_day server2_day server1_month server2_month etc.....
----                --------------------- --------------------- ------------------------------- -------------------------------
1551126300000000000 0                     8683916971            2053517969                      0

Great!!

Can I get the main totals in there as well…if I remove that json_query I don’t get any data. If it’s in this one table, thats ok, I wouldn’t mind knowing what the config would look like for populating a 2nd table.