function filterVdaLines(logString) {
// Split the log string into an array of lines
const lines = logString.trim().split("\n");
// Filter the lines to only include those for vda
const vdaLines = lines.filter((line) => line.includes("vda"));
// Return the filtered array of vda lines with only one space in between
return vdaLines.toString().replace(/ +/g, ' ').split(',');
}
// Paste iostat log data
let logString = ``;
//Filtering header from every log
const lines = filterVdaLines(logString)
// Initialize variables for storing the sum of each field
let tpsSum = 0;
let kbReadsSum = 0;
let kbWritesSum = 0;
let kbDiscardSum = 0;
let kbReadSum = 0;
let kbWriteSum = 0;
// Looping through each line of log data
for (const line of lines) {
// Spliting the line into an array of fields
const fields = line.trim().split(" ");
// Extracting the field values and converting them to numbers
const tps = Number(fields[1]);
const kbReads = Number(fields[2]);
const kbWrites = Number(fields[3]);
const kbDiscard = Number(fields[4]);
const kbRead = Number(fields[5]);
const kbWrite = Number(fields[6]);
// Adding the field values to their respective sum variables
tpsSum += tps;
kbReadsSum += kbReads;
kbWritesSum += kbWrites;
kbDiscardSum += kbDiscard;
kbReadSum += kbRead;
kbWriteSum += kbWrite;
}
// Calculating the mean of each field
const numLines = lines.length;
const tpsMean = tpsSum / numLines;
const kbReadsMean = kbReadsSum / numLines;
const kbWritesMean = kbWritesSum / numLines;
const kbDiscardMean = kbDiscardSum / numLines;
const kbReadMean = kbReadSum / numLines;
const kbWriteMean = kbWriteSum / numLines;
// Printing the mean of each field
console.log(`tps mean: ${tpsMean}`);
console.log(`kB_read/s mean: ${kbReadsMean}`);
console.log(`kB_wrtn/s mean: ${kbWritesMean}`);
console.log(`kB_dscd/s mean: ${kbDiscardMean}`);
console.log(`kB_read mean: ${kbReadMean}`);
console.log(`kB_wrtn mean: ${kbWriteMean}`);
console.log(`kB_dscd mean: ${kbDiscardMean}`);