in middleware/controllers/nodeExporter.js [153:231]
value: parseFloat(value),
}));
return acc;
}, {});
return res.send({ data: formattedData });
} catch (error) {
logger.error(error);
return res.status(400).send({
error: error.message || "An error occurred while fetching Disk Wait Time data",
});
}
}
/**
* Fetches the time spent doing I/O operations from Node Exporter.
*
* @async
* @function getTimeSpentDoingIO
* @param {Object} req - The HTTP request object containing query parameters in the body.
* @param {Object} res - The HTTP response object.
* @returns {Promise<void>} Sends the formatted I/O time data or an error response.
*/
async function getTimeSpentDoingIO(req, res) {
const { from = "now-5m", until = "now", step = 28 } = req.body;
const query = "rate(node_disk_io_time_seconds_total{device='vda', job='node_exporter'}[5m])";
try {
const baseUrl = buildUrl(getEnv("NODE_EXPORTER_BASE_URL"), {
query,
start: from,
end: until,
step,
});
const config = {
method: 'get',
url: baseUrl,
};
const response = await axios.request(config);
const result = response?.data?.data?.result?.[0]?.values || [];
const formattedData = result.map(([timestamp, value]) => ({
time: new Date(timestamp * 1000).toISOString(),
value: parseFloat(value),
}));
return res.send({ data: formattedData });
} catch (error) {
logger.error("Error fetching Disk IO Time data:", error);
return res.status(400).send({
error: error.message || "Failed to fetch Disk IO Time data",
});
}
}
/**
* Fetches Disk Read and Write Merged data from Node Exporter.
*
* @async
* @function getDiskRWData
* @param {Object} req - The HTTP request object containing query parameters in the body.
* @param {Object} res - The HTTP response object.
* @returns {Promise<void>} Sends the formatted Disk Read and Write Merged data or an error response.
*/
async function getDiskRWData(req, res) {
const { from = "now-5m", until = "now", step = 28 } = req.body;
try {
const queries = {
readMerged: "rate(node_disk_reads_merged_total{device='vda'}[5m])",
writeMerged: "rate(node_disk_writes_merged_total{device='vda'}[5m])",
};
const responses = await Promise.all(
Object.entries(queries).map(async ([key, query]) => {
const baseUrl = buildUrl(getEnv("NODE_EXPORTER_BASE_URL"), {