- Cargo workspace (core, plugins, tui, cli) with drop-in compatible CLI - Python-compatible config file handling, limits, views, rates, MMM, history - process collection via sysinfo + procfs, filters, thresholds, events, actions - 20 core plugins (cpu, percpu, mem, memswap, load, fs, network, diskio, ...) - stdout, stdout-csv, stdout-json, --issue, --modules-list output modes - differential test harness against the Python implementation
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Glances (Python) stats oracle.
|
|
|
|
Prints one JSON line per iteration with the raw stats of the requested
|
|
plugins. It uses the Python Glances plugin code directly so that the
|
|
comparison harness can observe the same number of iterations as the Rust
|
|
implementation (`--stdout-json` exits after one line in Glances 4.5.7).
|
|
|
|
Usage:
|
|
tools/glances_oracle.py --iterations N --refresh T --plugins cpu,mem
|
|
"""
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
import time
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--iterations", type=int, default=3)
|
|
parser.add_argument("--refresh", type=float, default=1.0)
|
|
parser.add_argument("--plugins", required=True)
|
|
parser.add_argument("--config", default=None)
|
|
args = parser.parse_args()
|
|
|
|
plugins = [p.strip() for p in args.plugins.split(",") if p.strip()]
|
|
|
|
sys.argv = ["glances", "-t", str(args.refresh), "--disable-plugin", "all", "--enable-plugin", args.plugins]
|
|
if args.config:
|
|
sys.argv += ["-C", args.config]
|
|
|
|
from glances.main import GlancesMain # noqa: E402
|
|
from glances.stats import GlancesStats # noqa: E402
|
|
|
|
core = GlancesMain()
|
|
stats = GlancesStats(config=core.get_config(), args=core.get_args())
|
|
|
|
for _ in range(args.iterations):
|
|
start = time.time()
|
|
stats.update()
|
|
line = {}
|
|
for name in plugins:
|
|
plugin = stats.get_plugin(name)
|
|
if plugin is not None:
|
|
line[name] = plugin.get_raw()
|
|
print(json.dumps(line), flush=True)
|
|
elapsed = time.time() - start
|
|
time.sleep(max(0.0, args.refresh - elapsed))
|