Files
lislgosms/api/src/infrastructure-monitoring/filesystem-metrics.ts
T

16 lines
1.1 KiB
TypeScript

// A bind mount is another path to the same filesystem, not another disk.
export const FILESYSTEM_LABELS = 'instance, device, fstype';
export const FILESYSTEM_SELECTOR = '{device=~"/dev/.+",fstype!~"tmpfs|devtmpfs|overlay|squashfs|ramfs"}';
export const FILESYSTEM_USAGE_PERCENT = `max by (${FILESYSTEM_LABELS}) ((1 - node_filesystem_avail_bytes${FILESYSTEM_SELECTOR} / node_filesystem_size_bytes${FILESYSTEM_SELECTOR}) * 100)`;
export const FILESYSTEM_INODE_USAGE_PERCENT = `max by (${FILESYSTEM_LABELS}) ((1 - node_filesystem_files_free${FILESYSTEM_SELECTOR} / node_filesystem_files${FILESYSTEM_SELECTOR}) * 100)`;
export function filesystemIdentity(metric: Record<string, string>) {
return JSON.stringify([metric.instance ?? '', metric.device ?? '', metric.fstype ?? '']);
}
// Prefer the filesystem's shallowest visible path; tie-breaking is deterministic.
export function compareMountpoints(left: string, right: string) {
return left.split('/').filter(Boolean).length - right.split('/').filter(Boolean).length
|| left.length - right.length || left.localeCompare(right);
}