$ show MrQianjinsi/agentic-metric
Agentic Metric is a local-only monitoring tool for AI coding agents that tracks token usage and costs across Claude Code, Codex, OpenCode, Qwen Code, and VS Code (Copilot Chat). It features a TUI dashboard and CLI for real-time monitoring, historical trends, and cost estimation. The architecture uses a plugin-based collector system for each agent type, incremental file parsing for efficient live updates, and a SQLite database for data aggregation. Key design strengths include smart session upsert logic to prevent metric regression, cross-platform process detection, and a flexible pricing system with family-based fallbacks.
The LLM identified 5 files worth highlighting for reuse:
Defines an extensible plugin system for agent collectors using an abstract base class (BaseCollector) and registry (CollectorRegistry). Each agent collector implements get_live_sessions() and sync_history() methods, allowing new agents to be added without modifying core logic. Demonstrates clean separation of concerns and reuse potential for any monitoring system requiring pluggable data sources.
Contains the _SessionAccum class that tracks file offsets to parse only newly appended data in JSONL session files, enabling efficient live updates with minimal I/O. This pattern is reused across collectors (with agent-specific variations) and exemplifies optimized incremental processing of log-like files for real-time monitoring.
Provides cross-platform (Linux/macOS) functions to find process IDs by name and get the working directory of a PID. Uses /proc on Linux and lsof on macOS, with robust error handling. This low-level utility is safely reusable in any system monitoring tool and demonstrates solid understanding of platform-specific process introspection.
Implements a multi-layer pricing lookup system: user overrides → builtin prefix match → family-based fallback (e.g., claude-sonnet-*) → default. Includes model aliasing and warnings for unknown models to encourage configuration. This flexible pricing approach is reusable in any cost estimation tool and shows foresight in handling model variant proliferation.
The upsert_session method uses a conditional ON CONFLICT clause to only update fields if new values are greater than existing (using CASE WHEN excluded.value > 0 THEN excluded.value ELSE sessions.value END). This ensures monotonic growth of metrics like token counts and prevents overwrites with zero or stale data, a critical pattern for accumulating metrics from incremental sources.