2024-12-01 03:54:43 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
void print_datetime(time_t now) {
|
|
|
|
struct tm *local = localtime(&now);
|
|
|
|
char buffer[20];
|
|
|
|
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M", local);
|
|
|
|
printf("%s", buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_load() {
|
|
|
|
double loadavg[3];
|
|
|
|
if (getloadavg(loadavg, 3) == -1) {
|
|
|
|
perror("getloadavg failed");
|
|
|
|
return;
|
|
|
|
}
|
2024-12-11 20:06:49 +00:00
|
|
|
if(loadavg[0] > 1.0){
|
2024-12-11 20:04:49 +00:00
|
|
|
int result = system("ps aux | awk '$3 > 1.0' | sort -k3 -nr");
|
2024-12-11 19:51:27 +00:00
|
|
|
(void)result;
|
|
|
|
}
|
2024-12-01 03:54:43 +00:00
|
|
|
printf("%.2f %.2f %.2f", loadavg[0], loadavg[1], loadavg[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
time_t start_time = time(NULL);
|
|
|
|
while (true) {
|
|
|
|
for(int i = 1; i < argc; i++){
|
|
|
|
printf("%s ", argv[i]);
|
|
|
|
}
|
|
|
|
if(argc == 1){
|
|
|
|
printf("%s", "\rUpdate ");
|
|
|
|
}
|
|
|
|
print_datetime(time(NULL));
|
|
|
|
printf("%s", " since ");
|
|
|
|
print_datetime(start_time);
|
|
|
|
printf("%s", ". ");
|
|
|
|
printf("%s", "Load: ");
|
|
|
|
print_load();
|
|
|
|
printf(".%s", "\n");
|
|
|
|
fflush(stdout);
|
2024-12-01 03:58:35 +00:00
|
|
|
usleep(59 * 1000 * 1000);
|
2024-12-01 03:54:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|