Update to Netdata API V3
This commit is contained in:
@@ -171,23 +171,23 @@ async function getNetdataMetrics() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const charts = [
|
const charts = [
|
||||||
{ key: 'cpu', url: `${NETDATA_URL}/api/v1/data?chart=system.cpu&after=-60&points=30`, map: d => ({ time: d[0], user: d[6], system: d[7] }) },
|
{ key: 'cpu', url: `${NETDATA_URL}/api/v3/data?contexts=system.cpu&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], user: d[6], system: d[7] }) },
|
||||||
{ key: 'ram', url: `${NETDATA_URL}/api/v1/data?chart=system.ram&after=-60&points=30`, map: d => ({ time: d[0], used: d[2], free: d[3] }) },
|
{ key: 'ram', url: `${NETDATA_URL}/api/v3/data?contexts=system.ram&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], used: d[2], free: d[3] }) },
|
||||||
{ key: 'net', url: `${NETDATA_URL}/api/v1/data?chart=system.net&after=-60&points=30`, map: d => ({ time: d[0], received: d[1], sent: d[2] }) },
|
{ key: 'net', url: `${NETDATA_URL}/api/v3/data?contexts=system.net&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], received: d[1], sent: d[2] }) },
|
||||||
{ key: 'disk', url: `${NETDATA_URL}/api/v1/data?chart=system.io&after=-60&points=30`, map: d => ({ time: d[0], in: d[1], out: d[2] }) },
|
{ key: 'disk', url: `${NETDATA_URL}/api/v3/data?contexts=system.io&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], in: d[1], out: d[2] }) },
|
||||||
{ key: 'disk_space', url: `${NETDATA_URL}/api/v1/data?chart=disk_space./&format=json&after=-60&points=30`, map: d => ({ time: d[0], avail: d[1], used: d[2], reserved: d[3] }) },
|
{ key: 'disk_space', url: `${NETDATA_URL}/api/v3/data?contexts=disk.space&families=%2F&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], avail: d[1], used: d[2], reserved: d[3] }) },
|
||||||
{ key: 'anomaly', url: `${NETDATA_URL}/api/v1/data?chart=anomaly_detection.dimensions_on_mchost&format=json&after=-60&points=30`, map: d => ({ time: d[0], anomalous: d[1], normal: d[2] }) }
|
{ key: 'anomaly', url: `${NETDATA_URL}/api/v3/data?contexts=anomaly_detection.dimensions&scope_nodes=mchost&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], anomalous: d[1], normal: d[2] }) }
|
||||||
];
|
];
|
||||||
|
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
charts.map(async ({ key, url, map }) => {
|
charts.map(async ({ key, url, map }) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url, { timeout: 5000 });
|
const response = await axios.get(url, { timeout: 5000 });
|
||||||
if (!response.data || !response.data.data) {
|
if (!response.data || !response.data.result || !response.data.result.data) {
|
||||||
console.warn(`No data returned for Netdata chart ${key} from ${url}`);
|
console.warn(`No data returned for Netdata chart ${key} from ${url}`);
|
||||||
return { key, data: [] };
|
return { key, data: [] };
|
||||||
}
|
}
|
||||||
const data = response.data.data.map(map);
|
const data = response.data.result.data.map(map);
|
||||||
return { key, data };
|
return { key, data };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(`Failed to fetch Netdata chart ${key} from ${url}:`, error.message, error.response ? `Status: ${error.response.status}` : '');
|
console.warn(`Failed to fetch Netdata chart ${key} from ${url}:`, error.message, error.response ? `Status: ${error.response.status}` : '');
|
||||||
@@ -217,23 +217,23 @@ async function getJumpNodeMetrics() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const charts = [
|
const charts = [
|
||||||
{ key: 'cpu', url: `${NETDATA_JUMP_URL}/api/v1/data?chart=system.cpu&after=-60&points=30`, map: d => ({ time: d[0], user: d[6], system: d[7] }) },
|
{ key: 'cpu', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=system.cpu&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], user: d[6], system: d[7] }) },
|
||||||
{ key: 'net', url: `${NETDATA_JUMP_URL}/api/v1/data?chart=system.net&after=-60&points=30`, map: d => ({ time: d[0], received: d[1], sent: d[2] }) },
|
{ key: 'net', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=system.net&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], received: d[1], sent: d[2] }) },
|
||||||
{ key: 'disk', url: `${NETDATA_JUMP_URL}/api/v1/data?chart=system.io&after=-60&points=30`, map: d => ({ time: d[0], in: d[1], out: d[2] }) },
|
{ key: 'disk', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=system.io&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], in: d[1], out: d[2] }) },
|
||||||
{ key: 'anomaly', url: `${NETDATA_JUMP_URL}/api/v1/data?chart=anomaly_detection.dimensions_on_my-mc-link&format=json&after=-60&points=30`, map: d => ({ time: d[0], anomalous: d[1], normal: d[2] }) },
|
{ key: 'anomaly', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=anomaly_detection.dimensions&scope_nodes=my-mc-link&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], anomalous: d[1], normal: d[2] }) },
|
||||||
{ key: 'disk_space', url: `${NETDATA_JUMP_URL}/api/v1/data?chart=disk_space./&format=json&after=-60&points=30`, map: d => ({ time: d[0], avail: d[1], used: d[2], reserved: d[3] }) },
|
{ key: 'disk_space', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=disk.space&families=%2F&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], avail: d[1], used: d[2], reserved: d[3] }) },
|
||||||
{ key: 'uptime', url: `${NETDATA_JUMP_URL}/api/v1/data?chart=system.uptime&format=json&after=-60&points=30`, map: d => ({ time: d[0], uptime: d[1] }) }
|
{ key: 'uptime', url: `${NETDATA_JUMP_URL}/api/v3/data?contexts=system.uptime&group_by=dimension&group=average&after=-60&points=30&format=json`, map: d => ({ time: d[0], uptime: d[1] }) }
|
||||||
];
|
];
|
||||||
|
|
||||||
const results = await Promise.all(
|
const results = await Promise.all(
|
||||||
charts.map(async ({ key, url, map }) => {
|
charts.map(async ({ key, url, map }) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url, { timeout: 10000 });
|
const response = await axios.get(url, { timeout: 10000 });
|
||||||
if (!response.data || !response.data.data) {
|
if (!response.data || !response.data.result || !response.data.result.data) {
|
||||||
console.warn(`No data returned for Jump Node chart ${key} from ${url}`);
|
console.warn(`No data returned for Jump Node chart ${key} from ${url}`);
|
||||||
return { key, data: [] };
|
return { key, data: [] };
|
||||||
}
|
}
|
||||||
const data = response.data.data.map(map);
|
const data = response.data.result.data.map(map);
|
||||||
return { key, data };
|
return { key, data };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(`Failed to fetch Jump Node chart ${key} from ${url}:`, error.message, error.response ? `Status: ${error.response.status}` : '');
|
console.warn(`Failed to fetch Jump Node chart ${key} from ${url}:`, error.message, error.response ? `Status: ${error.response.status}` : '');
|
||||||
|
Reference in New Issue
Block a user