feat: add Loki log query support to lab-monitoring

Add 3 opt-in Loki tools (query_logs, list_labels, list_label_values)
that are registered when LOKI_URL is configured. Includes Loki HTTP
client, CLI commands (logs, labels), NixOS module option, formatting,
and tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 20:55:39 +01:00
parent f4f859fefa
commit 859e35ab5c
13 changed files with 1014 additions and 20 deletions

View File

@@ -21,9 +21,10 @@ Search and query NixOS configuration options. Uses nixpkgs as source.
Search and query Home Manager configuration options. Uses home-manager repository as source.
### Lab Monitoring (`lab-monitoring`)
Query Prometheus metrics and Alertmanager alerts. Unlike other servers, this queries live HTTP APIs — no database or indexing needed.
- 8 tools: list/get alerts, search metrics, get metadata, PromQL query, list targets, list/create silences
- Configurable Prometheus and Alertmanager URLs via flags or environment variables
Query Prometheus metrics, Alertmanager alerts, and Loki logs. Unlike other servers, this queries live HTTP APIs — no database or indexing needed.
- 8 core tools: list/get alerts, search metrics, get metadata, PromQL query, list targets, list/create silences
- 3 optional Loki tools (when `LOKI_URL` is set): query_logs, list_labels, list_label_values
- Configurable Prometheus, Alertmanager, and Loki URLs via flags or environment variables
The nixpkgs/options/hm servers share a database-backed architecture:
- Full-text search across option/package names and descriptions
@@ -43,9 +44,9 @@ The nixpkgs/options/hm servers share a database-backed architecture:
## Project Status
**Complete and maintained** - All core features implemented:
- Full MCP servers (6 tools each for nixpkgs/options, 8 tools for monitoring)
- Full MCP servers (6 tools each for nixpkgs/options, 8-11 tools for monitoring)
- PostgreSQL and SQLite backends with FTS (for nixpkgs/options servers)
- Live API queries for Prometheus/Alertmanager (monitoring server)
- Live API queries for Prometheus/Alertmanager/Loki (monitoring server)
- NixOS modules for deployment
- CLI for manual operations
- Comprehensive test suite
@@ -96,9 +97,10 @@ labmcp/
│ │ ├── types.go # Package types, channel aliases
│ │ └── *_test.go # Parser tests
│ └── monitoring/
│ ├── types.go # Prometheus/Alertmanager API types
│ ├── types.go # Prometheus/Alertmanager/Loki API types
│ ├── prometheus.go # Prometheus HTTP client
│ ├── alertmanager.go # Alertmanager HTTP client
│ ├── loki.go # Loki HTTP client
│ ├── handlers.go # MCP tool definitions + handlers
│ ├── format.go # Markdown formatting utilities
│ └── *_test.go # Tests (httptest-based)
@@ -152,6 +154,9 @@ labmcp/
| `list_targets` | List scrape targets with health status |
| `list_silences` | List active/pending silences |
| `create_silence` | Create a silence (confirms with user first) |
| `query_logs` | Execute a LogQL range query against Loki (requires `LOKI_URL`) |
| `list_labels` | List available label names from Loki (requires `LOKI_URL`) |
| `list_label_values` | List values for a specific label from Loki (requires `LOKI_URL`) |
## Key Implementation Details
@@ -250,6 +255,10 @@ lab-monitoring alerts --state active # Filter by state
lab-monitoring query 'up' # Instant PromQL query
lab-monitoring targets # List scrape targets
lab-monitoring metrics node # Search metric names
lab-monitoring logs '{job="varlogs"}' # Query logs (requires LOKI_URL)
lab-monitoring logs '{job="nginx"} |= "error"' --start 2h --limit 50
lab-monitoring labels # List Loki labels
lab-monitoring labels --values job # List values for a label
```
### Channel Aliases