feat: implement rtop system monitoring tool
feat: add basic system information display feat: implement cpu monitoring feat: implement memory monitoring feat: implement process monitoring feat: implement network monitoring feat: implement disk monitoring feat: implement filesystem monitoring feat: add terminal control handling feat: create initial project structure feat: add build system with makefile feat: add readme documentation
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef CPU_H
|
||||
#define CPU_H
|
||||
|
||||
#define MAX_CPUS 256
|
||||
|
||||
typedef struct {
|
||||
unsigned long long user;
|
||||
unsigned long long nice;
|
||||
unsigned long long system;
|
||||
unsigned long long idle;
|
||||
unsigned long long iowait;
|
||||
unsigned long long irq;
|
||||
unsigned long long softirq;
|
||||
unsigned long long steal;
|
||||
unsigned long long guest;
|
||||
unsigned long long guest_nice;
|
||||
double usage_percent;
|
||||
} CpuCore;
|
||||
|
||||
typedef struct {
|
||||
int num_cores;
|
||||
CpuCore total;
|
||||
CpuCore cores[MAX_CPUS];
|
||||
CpuCore prev_total;
|
||||
CpuCore prev_cores[MAX_CPUS];
|
||||
double frequency_mhz;
|
||||
double min_freq_mhz;
|
||||
double max_freq_mhz;
|
||||
double temperature;
|
||||
unsigned long context_switches;
|
||||
unsigned long prev_context_switches;
|
||||
double context_switches_per_sec;
|
||||
unsigned long interrupts;
|
||||
unsigned long prev_interrupts;
|
||||
double interrupts_per_sec;
|
||||
} CpuInfo;
|
||||
|
||||
int cpu_info_init(CpuInfo *info);
|
||||
int cpu_info_update(CpuInfo *info, double interval);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef DISK_H
|
||||
#define DISK_H
|
||||
|
||||
#define MAX_DISKS 64
|
||||
#define MAX_DISK_NAME 64
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_DISK_NAME];
|
||||
unsigned long reads;
|
||||
unsigned long writes;
|
||||
unsigned long read_sectors;
|
||||
unsigned long write_sectors;
|
||||
unsigned long prev_reads;
|
||||
unsigned long prev_writes;
|
||||
unsigned long prev_read_sectors;
|
||||
unsigned long prev_write_sectors;
|
||||
double reads_per_sec;
|
||||
double writes_per_sec;
|
||||
double read_bytes_per_sec;
|
||||
double write_bytes_per_sec;
|
||||
} DiskStats;
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
DiskStats disks[MAX_DISKS];
|
||||
double io_wait_percent;
|
||||
} DiskInfo;
|
||||
|
||||
int disk_info_init(DiskInfo *info);
|
||||
int disk_info_update(DiskInfo *info, double interval);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
#include "terminal.h"
|
||||
#include "system.h"
|
||||
#include "cpu.h"
|
||||
#include "memory.h"
|
||||
#include "process.h"
|
||||
#include "network.h"
|
||||
#include "disk.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
void display_header(Terminal *term, SystemInfo *sys);
|
||||
void display_tabs(Terminal *term, int current_tab);
|
||||
void display_footer(Terminal *term, double refresh_rate);
|
||||
|
||||
void display_cpu_detail(Terminal *term, CpuInfo *cpu);
|
||||
void display_memory_detail(Terminal *term, MemoryInfo *mem, ProcessList *procs);
|
||||
void display_network_detail(Terminal *term, NetworkInfo *net);
|
||||
void display_disk_detail(Terminal *term, DiskInfo *disk, FilesystemInfo *fs);
|
||||
void display_process_detail(Terminal *term, ProcessList *procs);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef FILESYSTEM_H
|
||||
#define FILESYSTEM_H
|
||||
|
||||
#define MAX_FILESYSTEMS 64
|
||||
#define MAX_MOUNT_LEN 256
|
||||
#define MAX_FS_TYPE_LEN 64
|
||||
#define MAX_DEVICE_LEN 256
|
||||
|
||||
typedef struct {
|
||||
char device[MAX_DEVICE_LEN];
|
||||
char mount_point[MAX_MOUNT_LEN];
|
||||
char fs_type[MAX_FS_TYPE_LEN];
|
||||
unsigned long total;
|
||||
unsigned long used;
|
||||
unsigned long available;
|
||||
double used_percent;
|
||||
} FilesystemStats;
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
FilesystemStats filesystems[MAX_FILESYSTEMS];
|
||||
} FilesystemInfo;
|
||||
|
||||
int filesystem_info_init(FilesystemInfo *info);
|
||||
int filesystem_info_update(FilesystemInfo *info);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
typedef struct {
|
||||
unsigned long total;
|
||||
unsigned long free;
|
||||
unsigned long available;
|
||||
unsigned long buffers;
|
||||
unsigned long cached;
|
||||
unsigned long used;
|
||||
double used_percent;
|
||||
unsigned long swap_total;
|
||||
unsigned long swap_free;
|
||||
unsigned long swap_used;
|
||||
double swap_percent;
|
||||
unsigned long page_faults;
|
||||
unsigned long prev_page_faults;
|
||||
double page_faults_per_sec;
|
||||
unsigned long page_in;
|
||||
unsigned long prev_page_in;
|
||||
double page_in_per_sec;
|
||||
unsigned long page_out;
|
||||
unsigned long prev_page_out;
|
||||
double page_out_per_sec;
|
||||
} MemoryInfo;
|
||||
|
||||
int memory_info_init(MemoryInfo *info);
|
||||
int memory_info_update(MemoryInfo *info, double interval);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
|
||||
#define MAX_INTERFACES 32
|
||||
#define MAX_IF_NAME 32
|
||||
#define MAX_IP_LEN 46
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_IF_NAME];
|
||||
char ip[MAX_IP_LEN];
|
||||
int up;
|
||||
unsigned long rx_bytes;
|
||||
unsigned long tx_bytes;
|
||||
unsigned long rx_packets;
|
||||
unsigned long tx_packets;
|
||||
unsigned long rx_errors;
|
||||
unsigned long tx_errors;
|
||||
unsigned long rx_dropped;
|
||||
unsigned long tx_dropped;
|
||||
unsigned long prev_rx_bytes;
|
||||
unsigned long prev_tx_bytes;
|
||||
double rx_rate;
|
||||
double tx_rate;
|
||||
} NetworkInterface;
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
NetworkInterface interfaces[MAX_INTERFACES];
|
||||
} NetworkInfo;
|
||||
|
||||
int network_info_init(NetworkInfo *info);
|
||||
int network_info_update(NetworkInfo *info, double interval);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef PROCESS_H
|
||||
#define PROCESS_H
|
||||
|
||||
#define MAX_PROCESSES 4096
|
||||
#define MAX_CMD_LEN 256
|
||||
#define MAX_USER_LEN 64
|
||||
|
||||
typedef struct {
|
||||
int pid;
|
||||
int ppid;
|
||||
int uid;
|
||||
char user[MAX_USER_LEN];
|
||||
char state;
|
||||
char cmd[MAX_CMD_LEN];
|
||||
int threads;
|
||||
int priority;
|
||||
int nice;
|
||||
unsigned long vsize;
|
||||
unsigned long rss;
|
||||
unsigned long utime;
|
||||
unsigned long stime;
|
||||
unsigned long prev_utime;
|
||||
unsigned long prev_stime;
|
||||
double cpu_percent;
|
||||
double mem_percent;
|
||||
} ProcessInfo;
|
||||
|
||||
typedef struct {
|
||||
int total;
|
||||
int running;
|
||||
int sleeping;
|
||||
int stopped;
|
||||
int zombie;
|
||||
int count;
|
||||
ProcessInfo processes[MAX_PROCESSES];
|
||||
} ProcessList;
|
||||
|
||||
int process_list_init(ProcessList *list);
|
||||
int process_list_update(ProcessList *list, unsigned long total_mem, double interval, int num_cpus);
|
||||
void process_list_sort_by_cpu(ProcessList *list);
|
||||
void process_list_sort_by_mem(ProcessList *list);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef SYSTEM_H
|
||||
#define SYSTEM_H
|
||||
|
||||
#define MAX_HOSTNAME_LEN 256
|
||||
#define MAX_KERNEL_LEN 256
|
||||
#define MAX_OS_LEN 256
|
||||
#define MAX_ARCH_LEN 64
|
||||
|
||||
typedef struct {
|
||||
char hostname[MAX_HOSTNAME_LEN];
|
||||
char kernel[MAX_KERNEL_LEN];
|
||||
char os_name[MAX_OS_LEN];
|
||||
char arch[MAX_ARCH_LEN];
|
||||
long uptime_seconds;
|
||||
int uptime_days;
|
||||
int uptime_hours;
|
||||
int uptime_minutes;
|
||||
double load_1;
|
||||
double load_5;
|
||||
double load_15;
|
||||
} SystemInfo;
|
||||
|
||||
int system_info_init(SystemInfo *info);
|
||||
int system_info_update(SystemInfo *info);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
/* retoor <retoor@molodetz.nl> */
|
||||
#ifndef TERMINAL_H
|
||||
#define TERMINAL_H
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
#define COLOR_RESET "\033[0m"
|
||||
#define COLOR_BOLD "\033[1m"
|
||||
#define COLOR_RED "\033[31m"
|
||||
#define COLOR_GREEN "\033[32m"
|
||||
#define COLOR_YELLOW "\033[33m"
|
||||
#define COLOR_BLUE "\033[34m"
|
||||
#define COLOR_MAGENTA "\033[35m"
|
||||
#define COLOR_CYAN "\033[36m"
|
||||
#define COLOR_WHITE "\033[37m"
|
||||
#define COLOR_BOLD_RED "\033[1;31m"
|
||||
#define COLOR_BOLD_GREEN "\033[1;32m"
|
||||
#define COLOR_BOLD_YELLOW "\033[1;33m"
|
||||
#define COLOR_BOLD_BLUE "\033[1;34m"
|
||||
#define COLOR_BOLD_CYAN "\033[1;36m"
|
||||
#define COLOR_BOLD_WHITE "\033[1;37m"
|
||||
#define COLOR_BG_RED "\033[41m"
|
||||
#define COLOR_BG_GREEN "\033[42m"
|
||||
#define COLOR_BG_BLUE "\033[44m"
|
||||
|
||||
typedef struct {
|
||||
int rows;
|
||||
int cols;
|
||||
struct termios orig_termios;
|
||||
char *buffer;
|
||||
size_t buffer_size;
|
||||
size_t buffer_pos;
|
||||
} Terminal;
|
||||
|
||||
int terminal_init(Terminal *term);
|
||||
void terminal_cleanup(Terminal *term);
|
||||
void terminal_get_size(Terminal *term);
|
||||
void terminal_clear(Terminal *term);
|
||||
void terminal_move_cursor(Terminal *term, int row, int col);
|
||||
void terminal_hide_cursor(Terminal *term);
|
||||
void terminal_show_cursor(Terminal *term);
|
||||
void terminal_buffer_clear(Terminal *term);
|
||||
void terminal_buffer_append(Terminal *term, const char *str);
|
||||
void terminal_buffer_flush(Terminal *term);
|
||||
void terminal_set_raw_mode(Terminal *term);
|
||||
void terminal_restore_mode(Terminal *term);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user