code:
#include <stdio.h>
#include <unistd.h> /* usleep() */
#include <stdlib.h>
#include <iostream>
#include <fstream>
class SystemRuntimeInfo {
public:
void GetSysStatInfo()
{
system("top -bn 1 -i -c >> sys.txt");
}
void GetCpuInfo()
{
system("sar -P ALL -u 1 5 >> cpu.txt");
// system("");
// system("mpstat 1 5 >> cpu.txt");
// system("dstat -c >> cpu.txt");
}
void GetDiskInfo()
{
system("df -lh >> disk.txt");
}
void GetMemoryInfo()
{
system("vmstat 1 5 >> memroy.txt");
}
void GetIoInfo()
{
system("iostat 1 5 >> io.txt");
}
};
int main()
{
unsigned count = 5;
while (count --> 0)
{
SystemRuntimeInfo aInfo;
std::ofstream outfile;
outfile.open("sys.txt", std::ios::app | std::ios::trunc);
outfile << '\n';
aInfo.GetSysStatInfo();
outfile << '\n' << std::endl;
outfile.close();
outfile.open("cpu.txt", std::ios::app | std::ios::trunc);
outfile << '\n';
aInfo.GetCpuInfo();
outfile << '\n' << std::endl;
outfile.close();
outfile.open("disk.txt", std::ios::app | std::ios::trunc);
outfile << '\n';
aInfo.GetDiskInfo();
outfile << '\n' << std::endl;
outfile.close();
outfile.open("memory.txt", std::ios::app | std::ios::trunc);
outfile << '\n';
aInfo.GetMemoryInfo();
outfile << '\n' << std::endl;
outfile.close();
usleep(1000);
}
return 0;
}
#include <stdio.h>
#include <unis