akin-ozer/cc-devops-skills/logql-generator
Claude Code and agent skill by akin-ozer/cc-devops-skills
- community
Checking that the SKILL.md file is still in the repository.
Generate LogQL queries, log stream selectors, metric queries, and alerting rules for Grafana Loki.
Install
npx vskill@latest install akin-ozer/cc-devops-skills/logql-generatorSKILL.md
LogQL Query Generator
Overview
Interactive workflow for generating production-ready LogQL queries. LogQL is Grafana Loki's query language with indexed label selection, line filtering, parsing, and metric aggregation.
Trigger Hints
- "Write a LogQL query for error rate by service."
- "Help me build a Loki alert query."
- "Convert this troubleshooting requirement into LogQL."
- "I need step-by-step LogQL query construction."
Use this skill for query generation, dashboard queries, alerting expressions, and troubleshooting with Loki logs.
Execution Flow (Deterministic)
Always run stages in order. Do not skip required stages.
Stage 1 (Required): Capture Intent
Use AskUserQuestion to collect goal and use case.
Template:
- "What is your primary goal: debugging, alerting, dashboard metric, or investigation?"
- "Do you need a log query (raw lines) or a metric query (numeric output)?"
- "What time window should this cover (example: last 15m, 1h, 24h)?"
Fallback if AskUserQuestion is unavailable:
- Ask the same questions in plain text and continue.
Stage 2 (Required): Capture Log Source Details
Collect:
- Labels for stream selectors (
job,namespace,app,service_name,cluster) - Log format (JSON, logfmt, plain text, mixed)
- Known fields to filter/aggregate (
status,level,duration,path,trace_id)
Ambiguity and partial-answer handling:
- If a required field is missing, ask one focused follow-up question.
- If still missing, proceed with explicit assumptions.
- Prefix assumptions with
Assumptions:in the output so the user can correct them quickly.
Stage 3 (Required): Discover Loki and Grafana Versions
Collect or infer:
- Loki version (example:
2.9.x,3.0+, unknown) - Grafana version (example:
10.x,11.x, unknown) - Deployment context (self-hosted Loki, Grafana Cloud, unknown)
Version compatibility policy:
- If versions are known, use the newest compatible syntax only.
- If versions are unknown, use compatibility-first syntax and avoid 3.x-only features by default.
- For unknown versions, provide an optional "3.x optimized variant" separately.
Avoid by default when version is unknown:
- Pattern match operators
|>and!> approx_topk- Structured metadata specific behavior (
detected_level, accelerated metadata filtering assumptions)
Stage 4 (Required): Plan Confirmation and Output Mode
Present a plain-English plan, then ask the user to choose output mode.
Plan template:
Mode selection template:
- "Do you want
final query only(default) orincremental build(step-by-step)?"
If user does not choose, default to final query only.
Stage 5 (Conditional, Blocking): Reference Checkpoint for Complex Queries
Complex query triggers:
- Nested aggregations (
topk(sum by(...)), multiplesum by, percentiles) - Performance-sensitive queries (high volume streams, long ranges)
- Alerting expressions
- Template functions (
line_format,label_format) - Regex-heavy extraction, IP matching, pattern parsing
- Loki 3.x feature usage
Blocking checkpoint rule:
- Read relevant files before generation using explicit file-open/read actions.
- Minimum file set:
examples/common_queries.logqlfor syntax and query patternsreferences/best_practices.mdfor performance and alerting guidance
- Do not generate the final query until this checkpoint is complete.
Fallback when file-read tools are unavailable:
- State that reference files could not be read in this environment.
- Generate a conservative query (compatibility-first, simpler operators).
- Mark result as
Unverified against local references.
Stage 6 (Conditional): External Docs Lookup Policy (Context7 Before WebSearch)
Use external lookup only for version-specific behavior, unclear syntax, or advanced features not covered in local references.
Decision order:
- Context7 first:
mcp__context7__resolve-library-idwithlibraryName="grafana loki"mcp__context7__query-docsfor the exact topic
- WebSearch second (fallback only) when:
- Context7 is unavailable
- Context7 does not provide required version-specific detail
- You need latest release/deprecation confirmation
WebSearch fallback constraints:
- Prefer official Grafana/Loki docs and release notes.
- Note which statement came from fallback search.
Stage 7 (Required): Generate Query
Stage 7A (Default): Final Query Only
Return one production-ready query plus short explanation.
Stage 7B (Optional): Incremental Build Mode
Use this when requested or when debugging complex pipelines.
Step-by-step template:
- Stream selector
- Line filter
- Parser
- Parsed-field filter
- Aggregation/window
Stage 8 (Required): Deliver Usage and Checks
Always include:
- Final query or incremental sequence
- How to run it (Grafana Explore/panel or
logcli) - Tunables (labels, thresholds, range)
- Any assumptions and compatibility notes
AskUserQuestion Templates
Intake Template
- "What system/service should this query target?"
- "Which labels are reliable for stream selection?"
- "What defines a match (error text, status code, latency threshold, user path)?"
- "Should output be raw logs or a metric for alert/dashboard?"
Version Template
- "What Loki version are you running?"
- "What Grafana version are you using?"
- "If unknown, should I generate a compatibility-first query and add an optional 3.x variant?"
Ambiguity Follow-up Template
- "I am missing
<field>. Should I assume<default>so I can continue?"
Core Patterns
Stream Selection and Filtering
Parsing
Metric Aggregation
Formatting and IP Matching
Query Construction Rules
- Use specific stream selectors (indexed labels first).
- Prefer filter order: line filter -> parse -> parsed-field filter.
- Prefer parser cost order:
pattern>logfmt>json>regexp. - For unknown Loki version, stay on compatibility-first syntax.
- For complex/critical queries, complete Stage 5 checkpoint before final output.
Advanced Techniques
Multiple Parsers
Unwrap for Numeric Metrics
Pattern Match Operators (Loki 3.0+, 10x faster than regex)
Logical Operators
Offset Modifier
Label Operations
Note: LogQL has nodedupordistinctoperators. Use metric aggregations likesum by (field)for programmatic deduplication.
Loki 3.x Key Features
Structured Metadata
High-cardinality data without indexing (trace_id, user_id, request_id):
Query Acceleration (Bloom Filters)
Place structured metadata filters BEFORE parsers:
approx_topk (Probabilistic)
vector() for Alerting
Automatic Labels
- service_name: Auto-populated from container name
- detected_level: Auto-detected when
discover_log_levels: true(stored as structured metadata)
Function Reference
Log Range Aggregations
| Function | Description | |
|---|---|---|
rate(log-range) | Entries per second | |
count_over_time(log-range) | Count entries | |
bytes_rate(log-range) | Bytes per second | |
bytes_over_time(log-range) | Total bytes in time range | |
absent_over_time(log-range) | Returns 1 if no logs |
Rule:
- Use
bytes_over_time(<log-range>)for raw log-byte volume. - Use
| unwrap bytes(field)with unwrapped range aggregations for numeric byte fields extracted from log content.
Unwrapped Range Aggregations
| Function | Description | |
|---|---|---|
sum_over_time, avg_over_time, max_over_time, min_over_time | Aggregate numeric values | |
quantile_over_time(φ, range) | φ-quantile (0 ≤ φ ≤ 1) | |
first_over_time, last_over_time | First/last value in interval | |
stddev_over_time | Population standard deviation of unwrapped values | |
stdvar_over_time | Population variance of unwrapped values | |
rate_counter | Per-second rate treating values as a monotonically increasing counter |
Aggregation Operators
sum, avg, min, max, count, stddev, topk, bottomk, approx_topk, sort, sort_desc
With grouping: sum by (label1, label2) or sum without (label1)
Conversion Functions
| Function | Description | |
|---|---|---|
duration_seconds(label) | Convert duration string | |
bytes(label) | Convert byte string (KB, MB) |
label_replace()
Parser Reference
logfmt
--strict: Error on malformed entries--keep-empty: Keep standalone keys
JSON
pattern
Named placeholders become extracted labels; <_> discards a field.
regexp
Uses named capture groups (?P<name>). Slower than pattern/logfmt/json.
decolorize
Strips ANSI color escape codes. Apply before parsing when logs come from terminal output.
unpack
Unpacks log entries that were packed by Promtail's pack pipeline stage. Restores the original log line and any embedded labels.
Template Functions
Common functions for line_format and label_format:
String: trim, upper, lower, replace, trunc, substr, printf, contains, hasPrefix Math: add, sub, mul, div, addf, subf, floor, ceil, round Date: date, now, unixEpoch, toDate, duration_seconds Regex: regexReplaceAll, count Other: fromJson, default, int, float64, __line__, __timestamp__
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingdevops-skills-plugin/skills/logql-generator/SKILL.md
Popularity
- Repository stars
- 294
- Repository forks
- 32
- 7-day trend score
- 28
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 19 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/akin-ozer/cc-devops-skills/logql-generator)