async function getDiskIOPS()

in middleware/controllers/nodeExporter.js [78:114]


async function getDiskIOPS(req, res) {
    const { from = "now-12h", until = "now", step = 28 } = req.body;

    const baseUrl = buildUrl(getEnv("NODE_EXPORTER_BASE_URL"), {
        query: "rate(node_disk_writes_completed_total{device='vda',job='node_exporter'}[5m])",
        start: from,
        end: until,
        step,
    });

    const config = {
        method: 'get',
        maxBodyLength: Infinity,
        url: baseUrl,
    };

    try {
        const response = await axios.request(config);
        const data = response?.data?.data?.result.filter(
            (val) => val?.metric?.device === "vda" && val?.metric?.job === "node_exporter"
        );

        const formattedResponseData = data.length > 0
            ? data[0]?.values.map(([timestamp, value]) => ({
                time: new Date(Number(timestamp) * 1000).toISOString(),
                value: parseFloat(value).toFixed(2),
            }))
            : [];

        return res.send({ data: formattedResponseData });
    } catch (error) {
        logger.error(error);
        return res.status(400).send({
            error: error.message || "An error occurred while fetching the DiskIOPS data",
        });
    }
}