From 88db624127e11d4a1d1000a5ebcfb6757a05f3a4 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Fri, 24 Dec 2010 20:31:28 +0300 Subject: cli: show cpu and memory utilization in statistics --- accel-pptpd/cli/std_cmd.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'accel-pptpd/cli/std_cmd.c') diff --git a/accel-pptpd/cli/std_cmd.c b/accel-pptpd/cli/std_cmd.c index 127e7a2..0d168e5 100644 --- a/accel-pptpd/cli/std_cmd.c +++ b/accel-pptpd/cli/std_cmd.c @@ -16,6 +16,17 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, { time_t dt; int day,hour; + char statm_fname[128]; + FILE *f; + unsigned long vmsize = 0, vmrss = 0; + unsigned long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; + + sprintf(statm_fname, "/proc/%i/statm", getpid()); + f = fopen(statm_fname, "r"); + if (f) { + fscanf(f, "%lu %lu", &vmsize, &vmrss); + fclose(f); + } time(&dt); dt -= triton_stat.start_time; @@ -25,6 +36,8 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, dt %= 60 * 60; cli_sendv(client, "uptime: %i.%02i:%02i:%02i\r\n", day, hour, dt / 60, dt % 60); + cli_sendv(client, "cpu: %i%% (%i/%i)\r\n", triton_stat.ru_utime + triton_stat.ru_stime, triton_stat.ru_utime, triton_stat.ru_stime); + cli_sendv(client, "mem: %lu/%lu kB\r\n", vmrss / page_size_kb, vmsize / page_size_kb); cli_send(client, "core:\r\n"); cli_sendv(client, " mempool_allocated: %u\r\n", triton_stat.mempool_allocated); cli_sendv(client, " mempool_available: %u\r\n", triton_stat.mempool_available); -- cgit v1.2.3