/** * Cmon (c'mon) is a simple system resource monitor * Copyright (C) 2022 Aaron Ball * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include "status.h" #include "meminfo.h" #include "netinfo.h" #include "cpuinfo.h" #include "diskinfo.h" #include "proc.h" int main(int argc, char* argv[]) { struct meminfo minfo; // Struct for relevant data from /proc/meminfo struct status status; // Struct for tracking measurement statuses if(! status_init(&status)) return 1; status.count += 1; if(! meminfo_init(&minfo)) { fprintf(stderr, "ERROR: Could not read meminfo\n"); return 1; } // Calculate max memory usage and average memory usage if(status.memusedmax < (minfo.used)) status.memusedmax = minfo.used; status.memusedavg = (((status.count - 1) * status.memusedavg) + minfo.used) / status.count; status.memtotal = minfo.total; // Calculate load max and incremental load average double load = cpuinfo_load1m(); if(status.loadmax < load) status.loadmax = load; status.loadavg = (((status.count - 1) * status.loadavg) + load) / status.count; // Store number of processors to make load values more useful status.nprocs = get_nprocs(); // Store disk io metrics char* diskdev = "sda"; if(getenv("CMON_DISKDEV") != NULL) diskdev = getenv("CMON_DISKDEV"); disk_io_kb(diskdev, &status.diskreadkb, &status.diskwritekb); // Store number of processors to make load values more useful char* netdev = "wlan0"; if(getenv("CMON_NETDEV") != NULL) netdev = getenv("CMON_NETDEV"); status.nettx = net_x_bytes(netdev, 't'); status.netrx = net_x_bytes(netdev, 'r'); // Store uptime status.uptime = proc_uptime(); // Cleanup! status_write(&status); return 0; }