summaryrefslogtreecommitdiff
path: root/src/main.c
blob: 19e94652645b7bb790bea581650310a456c81a9c (plain)
    1 /**
    2  * Cmon (c'mon) is a simple system resource monitor
    3  * Copyright (C) 2022  Aaron Ball <nullspoon@oper.io>
    4  * 
    5  * This program is free software: you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License as published by
    7  * the Free Software Foundation, either version 3 of the License, or
    8  * (at your option) any later version.
    9  * 
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  * 
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
   17  */
   18 #include <stdio.h>
   19 #include <stdlib.h>
   20 #include <string.h>
   21 #include <sys/sysinfo.h>
   22 
   23 #include "status.h"
   24 #include "meminfo.h"
   25 #include "netinfo.h"
   26 #include "cpuinfo.h"
   27 #include "proc.h"
   28 
   29 int main(int argc, char* argv[]) {
   30   struct meminfo* m = meminfo_init();
   31   struct status* status = status_init();
   32   if(!status)
   33     return 1;
   34 
   35   status->count += 1;
   36 
   37   // Calculate max memory usage and average memory usage
   38   if(status->memmax < (m->used))
   39     status->memmax = m->used;
   40   status->memavg = (((status->count - 1) * status->memavg) + m->used) / status->count;
   41 
   42   // Calculate load max and incremental load average
   43   double load = cpuinfo_load1m();
   44   if(status->loadmax < load)
   45     status->loadmax = load;
   46   status->loadavg = (((status->count - 1) * status->loadavg) + load) / status->count;
   47 
   48   // Store number of processors to make load values more useful
   49   status->nprocs = get_nprocs();
   50 
   51   // Store number of processors to make load values more useful
   52   status->nettx = net_x_bytes("wlan0", 't');
   53   status->netrx = net_x_bytes("wlan0", 'r');
   54 
   55   // Store uptime
   56   status->uptime = proc_uptime();
   57 
   58   // Cleanup!
   59   status_write(status);
   60   status_free(status);
   61   meminfo_free(m);
   62   return 0;
   63 }

Generated by cgit