PrismaGaming123
Cadet
- Joined
- Aug 16, 2023
- Messages
- 2
For background: I have Grafana running on a Linux server which is used to gather system metrics of all the servers in my network(the data is collected from servers via a Python script and data is stored in my Postgres DB). I recently wanted to add my true nas core system as a machine for which I could track the metrics. I have a Python script that at the moment is able to call the true nas API and get the uptime of my true nas machine, but I am running into an issue with figuring out which endpoint to call to get the CPU utilization and memory utilization. I have tried the /system and /stat endpoint to no avail. Does anyone know where I should look and maybe an example query to get this info from the API? My script so far:
import requests
import datetime
import json
from datetime import timedelta
def getTruenas(ip,api_key):
# Get current time
now = datetime.datetime.now()
url = f"http://{ip}/api/v2.0/system/info"
payload= {}
headers = {
'Authorization': f'Bearer {api_key}'
}
response = requests.request("GET", url, headers=headers, data=payload)
data = json.loads(response.content)
uptime = data['uptime_seconds']
host_name = data['hostname']
operating_system = data['version']
print(f"Uptime: {uptime}")
print(f"Name: {host_name}")
print(f"OS: {operating_system}")
print(f"IP: {ip}")
print(f"Time: {now}")
# This code obviously won't work but I was playing around here to see what happened
url = f"http://{ip}/api/v2.0/reporting/cpu"
response = requests.request("GET",url, headers=headers, data=payload)
#data = json.loads(response.content)
print(response)
# cpu = data['CPU Usage']
# print(f"CPU Utilization: {cpu}")
api_key = "..."
ip = '...'
getTruenas(ip,api_key)
import requests
import datetime
import json
from datetime import timedelta
def getTruenas(ip,api_key):
# Get current time
now = datetime.datetime.now()
url = f"http://{ip}/api/v2.0/system/info"
payload= {}
headers = {
'Authorization': f'Bearer {api_key}'
}
response = requests.request("GET", url, headers=headers, data=payload)
data = json.loads(response.content)
uptime = data['uptime_seconds']
host_name = data['hostname']
operating_system = data['version']
print(f"Uptime: {uptime}")
print(f"Name: {host_name}")
print(f"OS: {operating_system}")
print(f"IP: {ip}")
print(f"Time: {now}")
# This code obviously won't work but I was playing around here to see what happened
url = f"http://{ip}/api/v2.0/reporting/cpu"
response = requests.request("GET",url, headers=headers, data=payload)
#data = json.loads(response.content)
print(response)
# cpu = data['CPU Usage']
# print(f"CPU Utilization: {cpu}")
api_key = "..."
ip = '...'
getTruenas(ip,api_key)