xiaohongshu
xiaohongshu
aggregating-gauge-metrics
Aggregate pre-computed metrics (gauge, counter, delta types) using OPAL. Use when analyzing request counts, error rates, resource utilization, or any numeric metrics over time. Covers align + m() + aggregate pattern, summary vs time-series output, and common aggregation functions. For percentile ...
Full skill instructions
Pre-computed metrics in Observe store aggregated measurements at regular intervals (typically every 5 minutes). This skill teaches how to query gauge, counter, and delta metric types using OPAL.
discover_context() to find and inspect metricsGauge metrics are pre-aggregated numeric measurements collected at regular intervals:
Pre-aggregated: Already summarized at collection time (typically 5-minute intervals)
Common Metric Types:
Examples:
span_call_count_5m - Number of requests per 5-minute intervalspan_error_count_5m - Number of errors per 5-minute intervalsystem_cpu_utilization_ratio - CPU utilization percentagek8s_pod_memory_available_bytes - Available memory in bytesUnlike datasets (Events/Intervals), metrics MUST use the align verb:
# WRONG - Will not work ❌
m("span_call_count_5m")
| statsby total:sum(metric)
# CORRECT - Must use align ✅
align options(bins: 1), rate:sum(m("span_call_count_5m"))
aggregate total_requests:sum(rate)
Why align is required: Metrics are stored as time-series data that must be aligned to a time grid before aggregation.
OPAL metrics queries can produce two different output types:
| Output Type | Pattern | Result | Use Case |
|---|---|---|---|
| Summary | options(bins: 1) | One row per group | Totals, overall statistics |
| Time-Series | 5m, 1h, or default | Many rows per group | Trending, dashboards, charts |
Summary pattern - Single statistics across entire time range:
align options(bins: 1), rate:sum(m("metric"))
aggregate total:sum(rate), group_by(service_name)
Output: One row per service
Time-series pattern - Values over time buckets:
align 5m, rate:sum(m("metric"))
| aggregate total:sum(rate), group_by(service_name)
Output: Multiple rows per service (one per 5-minute bucket)
CRITICAL Syntax Difference:
bins: 1): NO pipe | between align and aggregate5m): YES pipe | between align and aggregateStep 1: Search for metrics
discover_context("request count", result_type="metric")
discover_context("error", result_type="metric")
discover_context("cpu memory", result_type="metric")
Step 2: Get detailed metric schema
discover_context(metric_name="span_call_count_5m")
Step 3: Verify metric type
Look for: Type: gauge (or counter, delta)
Step 4: Note available dimensions
These are used for group_by():
service_name, service_namespaceenvironment, span_namek8s_namespace_name, k8s_pod_nameStep 5: Write query
Use align + m() + aggregate pattern with correct dimensions
Get overall totals (summary output):
align options(bins: 1), rate:sum(m("span_call_count_5m"))
aggregate total_requests:sum(rate)
Output: Single row with total count across entire time range.
No group_by: Aggregates everything together.
Get totals broken down by dimension:
align options(bins: 1), rate:sum(m("span_call_count_5m"))
aggregate total_requests:sum(rate), group_by(service_name)
Output: One row per service with total requests.
group_by: Use any dimension from metric schema.
Calculate averages across time range:
align options(bins: 1), cpu:avg(m("system_cpu_utilization_ratio"))
aggregate avg_cpu:avg(cpu), group_by(service_name)
Output: Average CPU utilization per service.
avg() function: Used twice - once in align, once in aggregate.
Compute several statistics together:
align options(bins: 1), rate:sum(m("span_call_count_5m"))
aggregate total:sum(rate),
average:avg(rate),
maximum:max(rate),
group_by(service_name)
Output: Multiple columns per service (total, average, maximum).
Track values over time buckets:
align 5m, rate:sum(m("span_call_count_5m"))
| aggregate requests_per_5min:sum(rate), group_by(service_name)
Output: Multiple rows per service (one per 5-minute interval).
Note: Pipe | required after align for time-series pattern.
Output columns:
_c_bucket - Time bucket identifiervalid_from, valid_to - Bucket boundariesalign options(bins: 1), rate:sum(m("span_call_count_5m"))
aggregate total_requests:sum(rate), group_by(service_name)
| sort desc(total_requests)
| limit 10
Use case: Identify top services by request volume.
align options(bins: 1), errors:sum(m("span_error_count_5m"))
aggregate total_errors:sum(errors), group_by(service_name)
fill total_errors:0
Use case: Show all services, even those with zero errors.
fill verb: Replaces null values with 0.
align 1h, rate:sum(m("span_call_count_5m"))
| aggregate requests_per_hour:sum(rate), group_by(service_name)
Use case: Hourly request trends for dashboards.
Output: Time-series data for charting.
align options(bins: 1),
requests:sum(m("span_call_count_5m")),
errors:sum(m("span_error_count_5m"))
aggregate total_requests:sum(requests),
total_errors:sum(errors),
group_by(service_name)
| make_col error_rate:float64(total_errors) / float64(total_requests)
Use case: Calculate error rate from two metrics.
make_col: Add derived column after aggregation.
align options(bins: 1), cpu:avg(m("system_cpu_utilization_ratio"))
aggregate avg_cpu:avg(cpu),
max_cpu:max(cpu),
group_by(k8s_pod_name)
| sort desc(avg_cpu)
| limit 20
Use case: Find pods with highest CPU usage.
Scenario: You want to analyze request and error rates for your microservices over the last 24 hours.
Step 1: Discover available metrics
discover_context("request error", result_type="metric")
Found metrics:
span_call_count_5m (type: gauge)span_error_count_5m (type: gauge)Step 2: Get metric details
discover_context(metric_name="span_call_count_5m")
Available dimensions: service_name, service_namespace, environment, span_name
Step 3: Query for summary statistics
align options(bins: 1),
requests:sum(m("span_call_count_5m")),
errors:sum(m("span_error_count_5m"))
aggregate total_requests:sum(requests),
total_errors:sum(errors),
group_by(service_name)
fill total_errors:0
| make_col error_rate:float64(total_errors) / float64(total_requests) * 100.0
| sort desc(total_requests)
Step 4: Interpret results
| service_name | total_requests | total_errors | error_rate |
|---|---|---|---|
| frontend-proxy | 15660 | 0 | 0.0 |
| frontend | 15263 | 35 | 0.23 |
| featureflagservice | 11693 | 0 | 0.0 |
| productcatalogservice | 8813 | 0 | 0.0 |
Insight: Frontend has a 0.23% error rate - investigate errors.
Step 5: Get hourly trends
align 1h,
requests:sum(m("span_call_count_5m")),
errors:sum(m("span_error_count_5m"))
| aggregate requests_per_hour:sum(requests),
errors_per_hour:sum(errors),
group_by(service_name)
| filter service_name = "frontend"
Output: Time-series showing frontend requests and errors per hour.
❌ Wrong:
m("span_call_count_5m")
| statsby total:sum(metric)
✅ Correct:
align options(bins: 1), rate:sum(m("span_call_count_5m"))
aggregate total:sum(rate)
Why: Metrics MUST use align verb - it's required, not optional.
❌ Wrong (pipe with bins:1):
align options(bins: 1), rate:sum(m("metric"))
| aggregate total:sum(rate)
❌ Wrong (no pipe with time duration):
align 5m, rate:sum(m("metric"))
aggregate total:sum(rate)
✅ Correct:
# Summary - NO pipe
align options(bins: 1), rate:sum(m("metric"))
aggregate total:sum(rate)
# Time-series - YES pipe
align 5m, rate:sum(m("metric"))
| aggregate total:sum(rate)
Why: Syntax differs between summary and time-series patterns.
❌ Wrong:
align options(bins: 1), rate:sum(m("metric"))
aggregate total:sum(rate), group_by(service_name)
Error: "field 'service_name' does not exist"
✅ Correct:
# First: discover_context(metric_name="metric") to see available dimensions
# Then: use only dimensions that exist
align options(bins: 1), rate:sum(m("metric"))
aggregate total:sum(rate), group_by(correct_dimension_name)
Why: Not all metrics have the same dimensions - always check first.
❌ Wrong:
align options(bins: 1), rate:sum(m("metric"))
statsby total:sum(rate)
✅ Correct:
align options(bins: 1), rate:sum(m("metric"))
aggregate total:sum(rate)
Why: After align, use aggregate (not statsby which is for datasets).
Common functions used with gauge metrics:
# Summing values
align options(bins: 1), metric:sum(m("metric_name"))
aggregate total:sum(metric)
# Averaging values
align options(bins: 1), metric:avg(m("metric_name"))
aggregate average:avg(metric)
# Maximum value
align options(bins: 1), metric:max(m("metric_name"))
aggregate maximum:max(metric)
# Minimum value
align options(bins: 1), metric:min(m("metric_name"))
aggregate minimum:min(metric)
# Count of samples
align options(bins: 1), metric:count(m("metric_name"))
aggregate sample_count:count(metric)
Pattern: Function used in both align and aggregate.
Common time durations for time-series queries:
align 1m, ... # 1-minute buckets
align 5m, ... # 5-minute buckets (common)
align 15m, ... # 15-minute buckets
align 1h, ... # 1-hour buckets
align 1d, ... # 1-day buckets
Default: align without duration uses automatic binning (300 bins).
bins: 1) for single statistics, reports, totals5m, 1h) for dashboards, trending, chartsGauge metrics are pre-aggregated measurements that require the align verb:
align + m() + aggregateoptions(bins: 1) → one row per group, NO pipe5m, 1h → many rows per group, YES pipediscover_context() to find metrics and dimensionsKey distinction: Metrics are pre-aggregated (use align), while Events/Intervals are raw data (use statsby/timechart).
Last Updated: November 14, 2025 Version: 1.0 Tested With: Observe OPAL (ServiceExplorer/Service Metrics)
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience