fix(truenas): report usable dataset space
This commit is contained in:
1 parent
527e911eef
commit
425dd90871
3 files changed
+53
-7
No files matched your search
@@ -27,6 +27,8 @@ import Alert from '@theme/Admonition';
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
The storage values shown by these widgets use the root ZFS dataset's usable `used` and `available` space, including RAIDZ parity overhead and dataset limits.
|
||||||
|
|
||||||
### Adding the integration
|
### Adding the integration
|
||||||
<AddingIntegration />
|
<AddingIntegration />
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,14 @@ const happyResponder = (method: string) => {
|
|||||||
];
|
];
|
||||||
case "pool.query":
|
case "pool.query":
|
||||||
return [{ name: "tank", status: "ONLINE", healthy: true, free: 500, size: 1000, allocated: 500 }];
|
return [{ name: "tank", status: "ONLINE", healthy: true, free: 500, size: 1000, allocated: 500 }];
|
||||||
|
case "pool.dataset.query":
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: "tank",
|
||||||
|
used: { parsed: 200 },
|
||||||
|
available: { parsed: 300 },
|
||||||
|
},
|
||||||
|
];
|
||||||
case "interface.query":
|
case "interface.query":
|
||||||
return [{ id: "eth0", name: "eth0" }];
|
return [{ id: "eth0", name: "eth0" }];
|
||||||
case "reporting.netdata_get_data":
|
case "reporting.netdata_get_data":
|
||||||
@@ -204,8 +212,8 @@ describe("TrueNasIntegration", () => {
|
|||||||
loadAverage: null,
|
loadAverage: null,
|
||||||
gpu: [],
|
gpu: [],
|
||||||
network: { up: 20_000, down: 10_000 },
|
network: { up: 20_000, down: 10_000 },
|
||||||
// `available` is the free space left on the pool (free = 500), not its total size.
|
// `available` and `used` come from the root dataset, not the physical pool.
|
||||||
fileSystem: [{ deviceName: "tank", available: "500", used: "500", percentage: 50 }],
|
fileSystem: [{ deviceName: "tank", available: "300", used: "200", percentage: 40 }],
|
||||||
smart: [{ deviceName: "tank", healthy: true, overallStatus: "ONLINE", temperature: null }],
|
smart: [{ deviceName: "tank", healthy: true, overallStatus: "ONLINE", temperature: null }],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ export class TrueNasIntegration extends Integration implements ISystemHealthMoni
|
|||||||
memUsedInBytes,
|
memUsedInBytes,
|
||||||
fileSystem: datasets.map((dataset) => ({
|
fileSystem: datasets.map((dataset) => ({
|
||||||
deviceName: dataset.name,
|
deviceName: dataset.name,
|
||||||
available: `${dataset.free}`, // free space left on the pool
|
available: `${dataset.available}`,
|
||||||
used: `${dataset.allocated}`,
|
used: `${dataset.used}`,
|
||||||
percentage: (dataset.allocated / dataset.size) * 100,
|
percentage: (dataset.used / (dataset.used + dataset.available)) * 100,
|
||||||
})),
|
})),
|
||||||
availablePkgUpdates: 0,
|
availablePkgUpdates: 0,
|
||||||
network: {
|
network: {
|
||||||
@@ -117,12 +117,40 @@ export class TrueNasIntegration extends Integration implements ISystemHealthMoni
|
|||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
.filter((pool) => pool !== null);
|
.filter((pool) => pool !== null);
|
||||||
|
|
||||||
|
if (activePools.length === 0) return [];
|
||||||
|
|
||||||
|
const datasets = await this.requestAsync("pool.dataset.query", [
|
||||||
|
[["id", "IN", activePools.map((pool) => pool.name)]],
|
||||||
|
{
|
||||||
|
extra: {
|
||||||
|
properties: ["used", "available"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
const parsedDatasets = await poolDatasetSchema.parseAsync(datasets);
|
||||||
|
|
||||||
|
const poolsWithUsableSpace = activePools
|
||||||
|
.map((pool) => {
|
||||||
|
const dataset = parsedDatasets.find((candidate) => candidate.id === pool.name);
|
||||||
|
if (!dataset || dataset.used.parsed === null || dataset.available.parsed === null) return null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: pool.name,
|
||||||
|
status: pool.status,
|
||||||
|
healthy: pool.healthy,
|
||||||
|
used: dataset.used.parsed,
|
||||||
|
available: dataset.available.parsed,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter((pool) => pool !== null);
|
||||||
|
|
||||||
logger.debug("Retrieved pools", {
|
logger.debug("Retrieved pools", {
|
||||||
url: this.integration.url,
|
url: this.integration.url,
|
||||||
totalCount: result.length,
|
totalCount: result.length,
|
||||||
activeCount: activePools.length,
|
activeCount: poolsWithUsableSpace.length,
|
||||||
});
|
});
|
||||||
return activePools;
|
return poolsWithUsableSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,6 +291,14 @@ const poolSchema = z.array(
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const poolDatasetSchema = z.array(
|
||||||
|
z.object({
|
||||||
|
id: z.string(),
|
||||||
|
used: z.object({ parsed: z.number().min(0).nullable() }),
|
||||||
|
available: z.object({ parsed: z.number().min(0).nullable() }),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const reportingNetDataSchema = z.array(
|
const reportingNetDataSchema = z.array(
|
||||||
z.object({
|
z.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
|
|||||||
Reference in new issue
Block a user