Download dev/tests/cqt/analysis_test.cpp from mchuca/ServerMonitor: direct link, hf CLI and curl.
- Browser
- Download file 2.54 kB
-
https://huggingface.co/mchuca/ServerMonitor/resolve/main/dev/tests/cqt/analysis_test.cpp
- Command line
-
hf download hf://mchuca/ServerMonitor/dev/tests/cqt/analysis_test.cpp
-
curl -L -o analysis_test.cpp https://huggingface.co/mchuca/ServerMonitor/resolve/main/dev/tests/cqt/analysis_test.cpp
2.54 kB
| // Synthetic 3-day history -> store reload + analyzer. Expected output: analysis_expected.txt (availability may differ by 0.05). | |
| int main(int argc, char **argv) { | |
| QCoreApplication app(argc, argv); | |
| const QString dir = argv[1]; | |
| QDir(dir).removeRecursively(); | |
| const qint64 now = QDateTime::currentSecsSinceEpoch(), start = now - 3 * 86400; | |
| { | |
| HistoryStore st(dir); | |
| for (qint64 t = start; t <= now; t += 30) { | |
| float v[H_COUNT] = {}; | |
| const double days = (t - start) / 86400.0; | |
| v[H_CPU] = 20 + 10 * ((t / 3600) % 24 > 8 && (t / 3600) % 24 < 18); | |
| v[H_DISK] = 70 + 5 * days; | |
| v[H_MEM] = (now - t < 6 * 3600) ? 50 + 2.0 * (6 - (now - t) / 3600.0) : 50; | |
| v[H_LOAD] = 1; v[H_RX] = 1e6; v[H_TX] = 5e5; | |
| st.add(t, v, !(t > now - 86400 && t < now - 86400 + 1800)); | |
| } | |
| } | |
| HistoryStore st(dir); | |
| printf("reloaded raw=%d minute=%d hour=%d day=%d bytes=%lld\n", st.tier(Tier::Raw).size(), st.tier(Tier::Minute).size(), st.tier(Tier::Hour).size(), st.tier(Tier::Day).size(), st.diskBytes()); | |
| Tier used; auto r = st.range(now - 7 * 86400, now, &used); | |
| printf("range 7d -> %s, %d pts\n", qPrintable(tierName(used)), r.size()); | |
| Metrics m; m.valid = true; m.cpuCount = 4; m.memPct = 62; m.maxDiskPct = 85; m.fullestMount = "/"; | |
| AutopilotConfig ap; ap.diskCleanup = true; ap.diskForecastDays = 5; | |
| ProcTrend p; p.pid = 4242; p.name = "leaky"; p.minutesTracked = 45; p.rssNow = 900e6; p.rssGrowth = 400e6; p.rssGrowthPct = 80; p.rssMonotonic = 0.95; | |
| ProcTrend q; q.pid = 777; q.name = "spinner"; q.cpuNow = 99; q.highCpuMinutes = 12; | |
| ServiceTrend s1{"web.service", true, false, 1, 0}, s2{"old.service", true, true, 0, 0}; | |
| Analysis a = analyze(st, m, ap, {p, q}, {s1, s2}, true); | |
| printf("health=%d grade=%s diskFullDays=%.2f slope/day=%.2f memSlope/h=%.2f r2=%.2f up24=%.2f up7=%.2f\n", a.health, qPrintable(a.grade), a.diskFullDays, a.diskSlopePerDay, a.memSlopePerHour, a.memTrendR2, a.up[0], a.up[1]); | |
| for (const auto &f : a.findings) printf(" [%s] %s | auto=%d action=%s %s\n", qPrintable(f.severity), qPrintable(f.title), f.autoEligible, qPrintable(f.action), qPrintable(f.actionArg)); | |
| Stats s = stats(r, H_DISK); | |
| printf("disk stats min=%.1f avg=%.1f p95=%.1f max=%.1f n=%d; capacity: %s\n", s.min, s.avg, s.p95, s.max, s.count, qPrintable(a.capacity.join(" | "))); | |
| } | |