How to use /stats/get_data api

majerus

Contributor
Joined
Dec 21, 2012
Messages
126
Anyone know how to use the /stat/get_data api call? I cannot figure it out and have messed around with this for the last couple days on and off. I get nothing but 400 errors, so I am sure my formatting is incorrect.. See screenshots

https://imgur.com/a/ter6xJ3
Snag_1f6e6745.png
Snag_1f6e72af.png
Snag_1f6e8608.png
Snag_1f6e8d2c.png
Snag_1f6e950c.png
Snag_1f6e9a9a.png
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
First point: you have two open curly braces, but only one close in more than half the examples.

Second, the docs seem to indicate you need to supply stats-filter object with the step (how often to take measurements) and the start and end period for measurements you want back.
 

ClassicGOD

Contributor
Joined
Jul 28, 2011
Messages
145
I believe already responded to you on Reddit but I will paste it here for anyone that is looking for this in the future.

if you click "Try it out" it will show you example of expected input. The correct json for this input looks something like this:

Code:
{
  "stats_list": [
    {
      "source": "cputemp-10",
      "type": "temperature",
      "dataset": "value",
      "cf": "AVERAGE"
    }
  ],
  "stats-filter": {
    "step": 10,
    "start": "now-60s",
    "end": "now"
  }
}


You can find list of available values for source by listing folders in /var/db/collectd/rrd/localhost

type are files inside those folders (for example temperature.rrd in /var/db/collectd/rrd/localhost/cputemp-10 in above example)

dataset is I think always value but you can verify that by executing rrdinfo on file in question

cf is AVERAGE, MIN or MAX depending on what data you are looking for.

This was tested and working on Scale but the API on Core is identical for many endpoints.
 
Last edited:

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
if you click "Try it out" it will show you example of expected input.
I'm not familiar with this tool and the picture doesn't show where it's from... can anyone point me at it?
 

ClassicGOD

Contributor
Joined
Jul 28, 2011
Messages
145
I'm not familiar with this tool and the picture doesn't show where it's from... can anyone point me at it?
The "Try it out" button I was mentioning is in the API documentation that is available on your TrueNas install. To access it jus go to http://your_nas_ip/api/docs
There is documentation for both Websocket and REST APIs - you switch between them using tabs on the top of the page. On top of the REST API documentation page you'll find an "Authorize" button. If you click it and log in using your TrueNas admin credentials you can use the "Try it out" functionality that allows you to query the endpoint right from the documentations web interface.

The other tool he is using (I'm also using it both at work and at home) to test the API is Postman - https://www.postman.com/
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
To access it jus go to http://your_nas_ip/api/docs
Well, now I feel really stupid.

I've been looking at that page the whole time and wondering why the docs were so appallingly bad, all the while having scripts blocked, thinking that I was only looking at local content, so no need to check... now with scripts allowed for jquery, swagger and bootstrapcdn, it lets me visit the REST page, which I had previously thought was just a link to the same page... kicking myself.

Thanks for spelling out to me what apparently I was incapable of working out on my own and apologies to the devs for bad-mouthing their work.
 
Top