Truenas API
Get Stats
To use /api/v2.0/stats/get_stats
we need to know available title and type of stats. Use this endpoint to see all available stats (GET without body, Authorization: Token <TOKEN>
in header):
http://<TRUENAS_SERVER>/api/v2.0/stats/get_sources
Get stats of storage
To get stats of storage use this endpoint (POST with body, Authorization: Token <TOKEN>
in header):
http://<TRUENAS_SERVER>/api/v2.0/stats/get_data
To validate your request, you can use this body:
{
"stats_list": [
{
"source": "cputemp-10",
"type": "temperature",
"dataset": "value",
"cf": "AVERAGE"
}
],
"stats-filter": {
"step": 10,
"start": "now-60s",
"end": "now"
}
}
Body query filters
I need to use api/v2.0/pool/dataset
to retrieve size of volumes, but, i only have the mountpoint name to find my pool.
After lot of research and test i have found something in the rest api source code, truenas got a syntax of query available in body request:
{
"query-filters": [
[
"id",
"~",
".*\/my-mount"
]
],
"query-options": {
"extra": {
"properties": [
"type",
"id"
]
}
}
}
I haven't found any documentation about this syntax, but here is where i found it: https://github.com/truenas/middleware/blob/master/src/middlewared/middlewared/restful.py#L630
On this row, we can see all available options to compare, like ~
for regex, =
for equal etc.
Both query-filters
and query-options
are required to use theses requests, for example to only use query-options
you need to do this:
"query-filters": []
"query-options": {
"extra": {
"properties": [
"type",
"id"
]
}
}
Get Stats of pool
To get pool data, use this endpoint (GET without body, Authorization: Token <TOKEN>
in header):
http://<TRUENAS_SERVER>/api/v2.0/pool/dataset
Get Smart result
To get smart result use this endpoint (GET without body, Authorization: Token <TOKEN>
in header):
http://10.95.100.5/api/v2.0/smart/test/results