diff --git a/src/probes/system_infos.probe/system_infos.c b/src/probes/system_infos.probe/system_infos.c index b79a2923d1dbdbbc6a0279c2b8bf2a513e6ab5eb..4f8b4501f92a2fb664b17c2a717100226224a6d7 100644 --- a/src/probes/system_infos.probe/system_infos.c +++ b/src/probes/system_infos.probe/system_infos.c @@ -81,7 +81,7 @@ int main(struct probe_params * params) } for (;;) { - ret = system_meminfo_probe(); + ret = system_meminfo_probe(params); if (ret < 0) { ERROR("[SYSTEM_PROBE] system meminfo probe fail.\n"); goto err; diff --git a/src/probes/system_infos.probe/system_meminfo.c b/src/probes/system_infos.probe/system_meminfo.c index 583b723ab6c920a7d4507455af034c818056fbcb..999dd43b29d721dc166c043c0c410260019fe563 100644 --- a/src/probes/system_infos.probe/system_meminfo.c +++ b/src/probes/system_infos.probe/system_meminfo.c @@ -17,6 +17,7 @@ #include #include #include "common.h" +#include "event.h" #include "nprobe_fprintf.h" #include "system_meminfo.h" @@ -71,8 +72,39 @@ static int set_meminfosp_fileds(const char* line, const int cur_index) return -1; } +static void report_meminfo_status(struct probe_params *params, double mem_util, double swap_util) +{ + char entityId[INT_LEN]; + char entityName[INT_LEN]; + if (params->logs == 0) { + return; + } + + entityId[0] = 0; + entityName[0] = 0; + (void)strcpy(entityId, "/proc/meminfo"); + (void)strcpy(entityName, "mem"); + // mem util + if (mem_util > params->res_percent_upper) { + report_logs(entityName, + entityId, + "util", + EVT_SEC_WARN, + "Too high mem utilization(%.2f%%).", + mem_util); + } + // swap util + if (swap_util > params->res_percent_upper) { + report_logs(entityName, + entityId, + "swap_util", + EVT_SEC_WARN, + "Too high swap utilization(%.2f%%).", + swap_util); + } +} -static void output_info(void) +static void output_info(struct probe_params *params) { // v3.2.8 used = total - free; v3.3.10 used = total - free - cache - buffers; cur_ver=v5.10 // alculate memusage @@ -87,6 +119,7 @@ static void output_info(void) swap_usage = (double)(meminfo_fields[SWAP_TOTAL].value - meminfo_fields[SWAP_FREE].value); swap_usage /= meminfo_fields[SWAP_TOTAL].value * 100.0; } + report_meminfo_status(params, mem_usage, swap_usage); // report data (void)nprobe_fprintf(stdout, "|%s|%s|%llu|%llu|%llu|%.2f|%llu|%llu|%llu|%llu|%llu|%llu|%.2f|\n", METRICS_MEMINFO_NAME, @@ -105,7 +138,7 @@ static void output_info(void) } // probes -int system_meminfo_probe() +int system_meminfo_probe(struct probe_params *params) { FILE* f = NULL; char line[LINE_BUF_LEN]; @@ -133,6 +166,7 @@ int system_meminfo_probe() } (void)fclose(f); - output_info(); + + output_info(params); return 0; } diff --git a/src/probes/system_infos.probe/system_meminfo.h b/src/probes/system_infos.probe/system_meminfo.h index b3682b852fd198d747d084efa25b20e9558ad373..49a9f10596f099dd4c9e4318d776ef201fd8403f 100644 --- a/src/probes/system_infos.probe/system_meminfo.h +++ b/src/probes/system_infos.probe/system_meminfo.h @@ -17,9 +17,10 @@ #pragma once +#include "common.h" +#include "args.h" #define KEY_BUF_LEN 256 - struct system_meminfo_field { char key[KEY_BUF_LEN]; unsigned long long value; @@ -42,7 +43,7 @@ enum mem_infos { int system_meminfo_init(void); void system_meminfo_destroy(void); -int system_meminfo_probe(void); +int system_meminfo_probe(struct probe_params *params); #endif