//native
/**
* Get system metrics
* Get a Network Controller system metric: cpu, disk, diskIO and memory (averaged over the last 5 minutes), their *Usage variants (time series over a timespan, default 1h), or uptime (days). Returns one entry per Network Controller, or only node_id's when set. The timespan only applies to the *Usage metrics.
*/
export async function main(
auth: RT.EricssonEp5g,
metric:
| "cpu"
| "cpuUsage"
| "disk"
| "diskUsage"
| "diskIO"
| "diskIOUsage"
| "memory"
| "memoryUsage"
| "uptime",
node_id: string | undefined,
timespan: "1h" | "4h" | "8h" | "24h" | "72h" | "168h" | "336h" | undefined
) {
const base = auth.base_url.replace(/\/+$/, "")
const url = new URL(
`${base}/v1/organization/${encodeURIComponent(auth.organization)}/site/${encodeURIComponent(auth.site)}/system/metrics/${metric}`
)
if (node_id != null && node_id !== "") {
url.searchParams.append("nodeId", node_id)
}
if (metric.endsWith("Usage") && timespan) {
url.searchParams.append("timespan", timespan)
}
const response = await fetch(url, {
headers: {
"X-Api-Key": auth.api_key,
...(auth.user_role ? { "X-User-Role": auth.user_role } : {}),
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 6 hours ago