-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.c
30 lines (25 loc) · 804 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "stdio.h"
#include "stdlib.h"
#include "kubemem.h"
int main(int argc, char **argv) {
struct kubemem_arguments args;
int arg_result = kubemem_arguments(argc, argv, &args);
if(arg_result != 0) {
exit(arg_result);
}
FILE *logfile = fopen(args.logfile_path, "a");
if(logfile == NULL) {
fprintf(stderr, "Failed to open %s\n", args.logfile_path);
return ERR_LOGFILE_FAILED;
}
double ratio = free_ram_ratio();
if(ratio >= args.failure_ratio) {
fprintf(logfile, "FAILURE: hit memory limit %F (at %F)\n", args.failure_ratio * 100.0, ratio * 100.0);
return ERR_MEMORY_LOW;
}
if(ratio >= args.warning_ratio) {
fprintf(logfile, "WARN: approaching memory limit %F (at %F)\n", args.failure_ratio * 100.0, ratio * 100.0);
}
fclose(logfile);
return 0;
}