Files
OpenUniFi/src/sysinfo.h
T
opfr1andKoda 59274da4e5 Translated all files to ENG (#5)
Reviewed-on: #5
Co-authored-by: Finn <fwaggoner@nmfpgt.de>
Co-committed-by: Finn <fwaggoner@nmfpgt.de>
2026-07-12 01:45:38 +01:00

74 lines
2.6 KiB
C

#ifndef OPENUF_SYSINFO_H
#define OPENUF_SYSINFO_H
/*
* openuf - sysinfo.h
*
* Reads system statistics (CPU, RAM, interfaces, radios).
* All readings come directly from the Linux kernel:
*
* /proc/stat → CPU usage (deltas between two snapshots)
* /proc/meminfo → total/free/buffer/cache memory
* /proc/net/dev → rx/tx counters per interface
* /sys/class/net/ → speed, duplex, operstate, MAC
* iw dev <if> info → current channel, TX power
* iw dev <if> survey dump → channel utilization
*/
#include <stdbool.h>
/* ── Memoria ─────────────────────────────────────────────────────── */
typedef struct {
long total_kb;
long free_kb;
long buffer_kb;
long cached_kb;
} mem_stats_t;
int sysinfo_mem(mem_stats_t *out);
/* ── CPU ─────────────────────────────────────────────────────────── */
/* Returns % CPU usage (0-100). The first call returns 0 (takes a snapshot).
* Subsequent calls compute the delta relative to the previous one.
* With a 10s interval this gives a good average of usage. */
int sysinfo_cpu_percent(void);
/* ── Interfaz de red ─────────────────────────────────────────────── */
typedef struct {
char name[32];
char mac[32];
char ip[64];
bool up;
int speed; /* Mbps: 10/100/1000; -1 if not available */
bool full_duplex;
long long rx_bytes;
long long tx_bytes;
long long rx_packets;
long long tx_packets;
long long rx_errors;
long long tx_errors;
long long rx_dropped;
long long tx_dropped;
long long rx_multicast;
} iface_stats_t;
int sysinfo_iface(const char *ifname, iface_stats_t *out);
/* ── Radio WiFi ─────────────────────────────────────────────────── */
typedef struct {
char name[32];
char iface[32];
int channel;
int tx_power;
int cu_total; /* % total channel usage */
int cu_self_tx; /* % time spent transmitting */
int cu_self_rx; /* % time spent receiving */
int num_sta;
int noise; /* dBm */
} radio_stats_t;
/* iface: "wlan0", "wlan1" */
int sysinfo_radio(const char *iface, radio_stats_t *out);
#endif /* OPENUF_SYSINFO_H */