Download Server Monitor(cqt-linux)/src/core/Model.h from mchuca/ServerMonitor: direct link, hf CLI and curl.
- Browser
- Download file 4.87 kB
-
https://huggingface.co/mchuca/ServerMonitor/resolve/main/Server%20Monitor(cqt-linux)/src/core/Model.h
- Command line
-
hf download 'hf://mchuca/ServerMonitor/Server Monitor(cqt-linux)/src/core/Model.h'
-
curl -L -o Model.h 'https://huggingface.co/mchuca/ServerMonitor/resolve/main/Server%20Monitor(cqt-linux)/src/core/Model.h'
4.87 kB
| // Data model: server config, rules, autopilot policy, parsed metrics, formatting. | |
| namespace Fmt { | |
| QString bytes(double b, int prec = 1); | |
| inline QString rate(double b) { return bytes(b) + "/s"; } | |
| inline QString pct(double p, int prec = 1) { return QString::number(p, 'f', prec) + "%"; } | |
| inline QString temp(double c) { return QString::number(c, 'f', 0) + " °C"; } | |
| QString count(double v); | |
| QString duration(double s); | |
| } | |
| enum class Transport { Local, SSH }; | |
| inline QString transportName(Transport t) { return t == Transport::Local ? "Local" : "SSH"; } | |
| const QVector<Def> &ruleMetrics(); | |
| QString defLabel(const QVector<Def> &d, const QString &k, bool unit = false); | |
| // "When <metric> <op> <value> for <duration> s -> <action>(<arg>)" | |
| struct Rule { | |
| QString id, metric = "cpu", op = ">", action = "notify", arg, severity = "warning"; | |
| bool enabled = true; | |
| double value = 90; | |
| int duration = 60, cooldown = 300; | |
| QString conditionText() const; | |
| QString actionText() const; | |
| }; | |
| // History-driven automatic control (evaluated by the Analyzer every minute). | |
| struct AutopilotConfig { | |
| bool enabled = true, dryRun = false, restartFailed = true, diskCleanup = false, anomalyAlerts = true; | |
| int maxRestartsPerHour = 3, runawayMinutes = 10, diskForecastDays = 3; | |
| double runawayCpu = 90, diskCleanupAt = 92, leakMemPressure = 90, anomalyZ = 3; | |
| QString runawayMode = "renice", leakMode = "notify"; // none|renice|terminate, none|notify|terminate | |
| QString diskCleanupCommand = P::cleanup; | |
| }; | |
| struct ServerConfig { | |
| QString id, name, group, host, user, keyFile, password, notes; | |
| Transport transport = Transport::SSH; | |
| int port = 22, interval = P::interval; | |
| bool useSudo = false, enabled = true; | |
| QVector<Rule> rules = defaultRules(); | |
| AutopilotConfig autopilot; | |
| QString address() const; | |
| QJsonObject toJson() const; | |
| static ServerConfig fromJson(const QJsonObject &o); | |
| static QVector<Rule> defaultRules(); | |
| static QString newId(); | |
| }; | |
| // ---- one parsed sample ------------------------------------------------------ | |
| struct CoreStat { double usage = 0, mhz = 0; }; | |
| struct MountInfo { QString device, type, mount; double total = 0, used = 0, avail = 0, pct = 0; }; | |
| struct DiskIO { QString name; double readBps = 0, writeBps = 0, readIops = 0, writeIops = 0, util = 0, totalRead = 0, totalWritten = 0; }; | |
| struct NetIf { | |
| QString name, state; | |
| int speed = -1; | |
| bool virt = false; | |
| double rxBps = 0, txBps = 0, rxPps = 0, txPps = 0, rxBytes = 0, txBytes = 0, errors = 0, drops = 0; | |
| }; | |
| struct ProcInfo { | |
| int pid = 0, ppid = 0, threads = 0, nice = 0; | |
| QString name, user; | |
| QChar state; | |
| double cpu = 0, memPct = 0, rss = 0, vsz = 0, age = 0; // cpu: % of one core | |
| }; | |
| struct ServiceInfo { QString unit, load, active, sub, description; }; | |
| struct TempSensor { QString name; double celsius = 0; }; | |
| struct GpuInfo { int index = 0; QString name; double util = 0, memUsed = 0, memTotal = 0, temp = 0, power = 0, fan = 0; }; | |
| struct Metrics { | |
| bool valid = false; | |
| qint64 timestamp = 0; | |
| QString hostname, os, kernel, arch, cpuModel, virt; | |
| int cpuCount = 0, loggedUsers = 0, procsRunning = 0, procsBlocked = 0, threadsTotal = 0, socketsUsed = 0; | |
| int servicesFailed = 0, servicesRunning = 0; | |
| double uptime = 0, load1 = 0, load5 = 0, load15 = 0; | |
| double cpuUsage = 0, cpuUser = 0, cpuSystem = 0, cpuIowait = 0, cpuSteal = 0, cpuIrq = 0; | |
| double ctxtPerSec = 0, intrPerSec = 0, forksPerSec = 0, avgMhz = 0; | |
| double memTotal = 0, memFree = 0, memAvailable = 0, memUsed = 0, buffers = 0, cached = 0, shared = 0, slab = 0, dirty = 0; | |
| double swapTotal = 0, swapUsed = 0, memPct = 0, swapPct = 0; | |
| double diskReadBps = 0, diskWriteBps = 0, maxDiskPct = 0, maxDiskUtil = 0, netRxBps = 0, netTxBps = 0, maxTemp = 0; | |
| QString fullestMount, busiestDisk; | |
| QVector<CoreStat> cores; | |
| QVector<MountInfo> mounts; | |
| QVector<DiskIO> disks; | |
| QVector<NetIf> nets; | |
| QMap<QString, int> tcp; // ESTABLISHED -> n | |
| QVector<ProcInfo> procs; | |
| QVector<ServiceInfo> services; | |
| QVector<TempSensor> temps; | |
| QVector<GpuInfo> gpus; | |
| double gpuMax(bool temp) const; | |
| }; | |
| // Turns raw collector frames into Metrics; keeps counters for rates. process() is in Platform.cpp. | |
| class MetricsEngine { | |
| public: | |
| Metrics process(const QByteArray &raw, qint64 nowMs); | |
| void reset() { *this = MetricsEngine(); } | |
| private: | |
| double m_upt = 0; | |
| QVector<QVector<double>> m_cpu; | |
| QHash<QString, QVector<double>> m_ctr; // misc counters: "stat", "disk:sda", "net:eth0" | |
| QHash<int, double> m_ticks; | |
| QHash<QString, QString> m_info; | |
| QHash<int, QString> m_users; | |
| QVector<ServiceInfo> m_services; | |
| QVector<GpuInfo> m_gpus; | |
| }; | |