Files
glances-rs/crates/glances-plugins/src/plugins/programlist.rs
T
glances-rs 975385da5d M1: core engine, config, plugin model and core plugins
- 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
2026-10-09 23:25:35 +00:00

71 lines
2.5 KiB
Rust

//! Program list plugin (processes aggregated by program name).
use crate::fields;
use glances_core::plugin::{Field, Plugin, PluginModel, UpdateContext};
use glances_core::processes::processes;
use glances_core::{Args, Config};
use serde_json::Value;
pub struct ProgramListPlugin {
pub model: PluginModel,
}
impl ProgramListPlugin {
pub fn new(config: &Config, args: &Args) -> Self {
let fields = fields! {
"name" => Field::new("Process name").unit("string"),
"cmdline" => Field::new("Command line with arguments").unit("list"),
"username" => Field::new("Process owner").unit("string"),
"nprocs" => Field::new("Number of children processes").unit("number"),
"num_threads" => Field::new("Number of threads").unit("number"),
"cpu_percent" => Field::new("Process CPU consumption").unit("percent"),
"memory_percent" => Field::new("Process memory consumption").unit("percent"),
"memory_info" => Field::new("Process memory information (dict with rss, vms, shared, text, lib, data, dirty keys)").unit("byte"),
"status" => Field::new("Process status").unit("string"),
"nice" => Field::new("Process nice value").unit("number"),
"cpu_times" => Field::new("Process CPU times (dict with user, system, iowait keys)").unit("second"),
"gids" => Field::new("Process group IDs (dict with real, effective, saved keys)").unit("number"),
"io_counters" => Field::new("Process IO counters (list with read_count, write_count, read_bytes, write_bytes, io_tag keys)").unit("byte"),
};
let mut model = PluginModel::new(
"programlist",
fields,
Vec::new(),
Value::Array(Vec::new()),
config,
args.time.unwrap_or(2.0),
args.disable_history,
args.disable_config_exec,
);
model.set_item_key("name");
Self { model }
}
}
impl Plugin for ProgramListPlugin {
fn name(&self) -> &str {
"programlist"
}
fn model(&self) -> &PluginModel {
&self.model
}
fn model_mut(&mut self) -> &mut PluginModel {
&mut self.model
}
fn get_key(&self) -> Option<&'static str> {
Some("name")
}
fn collect(&mut self, _ctx: &mut UpdateContext) -> anyhow::Result<Value> {
let mut procs = processes().lock().unwrap();
Ok(Value::Array(procs.get_list_as_programs().to_vec()))
}
fn display_curse(&self) -> bool {
true
}
}