-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Summary
Enhance the existing alert plugin with an optional LLM-based reporting feature. Instead of (or in addition to) the current event history display, Glances would periodically collect key system metrics and send them to a Large Language Model to receive a human-readable, contextual health report of the machine.
Motivation
The current alert plugin logs WARNING and CRITICAL events with structured data (state, type, min/avg/max values, top processes). However, interpreting these events still requires the user to mentally correlate multiple signals — high CPU, memory pressure, specific processes — to understand the overall health situation.
A well-prompted LLM can synthesize all these signals into a concise, actionable narrative:
"Your system is under sustained memory pressure caused by process X. Swap usage is increasing. Consider restarting the service or increasing available RAM."
This is particularly valuable for less experienced users or for periodic automated reporting (e.g. scheduled digests, incident summaries).
Proposed Implementation
New optional module: glances/plugins/alert/llm_reporter.py
A lightweight, optional module (activated only when configured) that:
- When an alert is raised, Collects a snapshot of key stats from the existing Glances data pipeline: CPU, load average, memory, swap, active alert events, and top processes.
- Builds a structured prompt summarizing the machine state.
- Sends the prompt to the configured LLM provider via an abstraction layer.
- Returns a plain-text report that can be displayed in the TUI, logged, or sent via a notification channel.
LLM abstraction
The recommended library for the abstraction layer is [LiteLLM](https://github.com/BerriAI/litellm), which provides a unified interface across 100+ providers (Anthropic Claude, OpenAI, Mistral, Google Gemini, local models via Ollama/LM Studio, etc.) using a single consistent API. This avoids hard-coding any specific vendor SDK and lets users plug in their own preferred provider.
import litellm
response = litellm.completion(
model=self.model, # e.g. "claude-haiku-4-5", "gpt-4o-mini", "ollama/llama3.2"
messages=[{"role": "user", "content": prompt}],
api_key=self.api_key,
)
report = response.choices[0].message.content
litellmis optional and should only be required if the feature is enabled inglances.conf.
Configuration (glances.conf)
[alert]
# Existing options
disable=False
max_events=10
min_duration=6
min_interval=6
# New LLM reporting options (all optional, feature disabled if not set)
llm_enable=True
llm_provider=claude # claude | openai | mistral | ollama | ...
llm_model=claude-haiku-4-5 # Any model string supported by LiteLLM
llm_api_key=YOUR_API_KEY_HERE # Not needed for local modelsPrompt design (draft)
You are a system monitoring expert. Analyze the following real-time snapshot
of a machine and produce a concise health report (3-5 sentences max).
Timestamp: {timestamp}
CPU usage: {cpu}%
Load average (1m/5m/15m): {load_1}/{load_5}/{load_15}
Memory: {mem_used} / {mem_total} ({mem_percent}% used)
Swap: {swap_used} / {swap_total} ({swap_percent}% used)
Active alerts: {alert_list}
Top processes by CPU: {top_processes}
Provide:
1. Overall health status (OK / Degraded / Critical)
2. Root cause analysis if any issue is detected
3. Recommended action if applicable
Considered Alternatives
| Approach | Verdict |
|---|---|
Direct vendor SDKs (anthropic, openai, mistral) |
Rejected — requires maintaining multiple code paths |
| LangChain | Rejected — too heavy for a simple prompt/completion pattern |
| Local-only LLMs (Ollama) | Fully supported via LiteLLM — no API key, privacy-preserving, free |
Out of Scope (for this issue)
- Sending the report via email, Slack, or other notification channels (could leverage the existing
actionmechanism already in the plugin model). - Multi-turn conversation or interactive Q&A with the LLM.
- Fine-tuning or training a model on Glances data.
Acceptance Criteria
- The feature is entirely opt-in via
glances.conf— zero impact on users who do not configure it. -
litellmis an optional dependency, not added to the core requirements. - The module works with at least: Anthropic Claude, OpenAI, Mistral, and Ollama (local).
- The generated report is accessible via the existing Glances REST API in addition to the TUI.
- A graceful fallback message is shown if the LLM call fails or times out.
- Documentation is updated with configuration examples for each supported provider.
Additional Context
- LiteLLM GitHub: https://github.com/BerriAI/litellm
- For privacy-conscious users, running a local model via [Ollama](https://ollama.com/) requires zero external API calls and zero cost.
- For cloud providers, cost is negligible: a report using
claude-haiku-4-5orgpt-4o-minicosts roughly $0.001 per generation.