metricx-knowledge

Implements Go service metrics instrumentation using the metricx library with predefined Metric Models.

Updated Apr 30, 2026
One-click install
npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill metricx-knowledge-yuezhen-huang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: metricx-knowledge
Source: https://github.com/yuezhen-huang/my-bytedance-skillhub/tree/main/metricx-knowledge
Command: npx skills add https://github.com/yuezhen-huang/my-bytedance-skillhub --skill metricx-knowledge-yuezhen-huang

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go developers at ByteDance need a standardized way to add monitoring instrumentation to services without misusing the underlying metrics v3 library. This Skill provides complete knowledge of the metricx library, which centralizes metric definitions through predefined Metric Models and enforces correct usage via struct tags and lint tooling. ## Core Features & Use Cases - Metric Model Definition: Define all metrics in one struct using Counter, RateCounter, Gauge, Timer, and Histogram types with metric, prefix, tags, and tnames field tags. - Multi-Sink Reporting: Configure simultaneous reporting to ByteDance metrics and InfluxDB via WithFactories, plus global tags, custom namespaces, and time units. - Best Practices & Lint Guidance: Learn DB/cache instrumentation patterns, tag inheritance in nested structs, and how golintx and bytecheck prevent tag misuse. - Use Case: When building a new Go microservice, use this Skill to design a Metric Model for database throughput, latency, and cache hit rates, then initialize metricx with environment tags for production monitoring. ## Quick Start Ask the AI to show how to define a metricx Metric Model with Counter and Timer fields and initialize it with metricx.MustInit for a Go service.

Frequently Asked Questions about metricx-knowledge

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add metrics instrumentation to a Go service with metricx?

Define a struct with metricx field types like Counter, Timer, or Gauge, annotate fields with metric and tnames tags, then call metricx.MustInit with the model. Report metrics at runtime using methods like Inc, Record, and Update with tag values.

What is the difference between metricx Counter, Timer, and Gauge?

Counter tracks cumulative event counts via Inc, Timer records operation durations with min/max/avg/percentile statistics via Record, and Gauge stores instantaneous values via Update. RateCounter measures per-unit-time accumulation and Histogram records value distributions.

Can metricx report metrics to both metrics v3 and InfluxDB?

Yes, metricx supports multiple output sinks through the WithFactories option. Pass influxdb.Factory with connection details alongside metricx.BytedMetrics to report every measurement to both stores simultaneously.

What happens if a metricx tag value is missing or undefined?

If a tag name is declared in tnames but not passed at report time, or its value is empty, metricx fills it with the default value '-'. Passing an undefined tag name causes the report to fail, matching metrics v3 behavior.

How do I change the default metric name prefix in metricx?

By default metricx uses env.PSM() as the metric name prefix. Override it by passing metricx.WithNamespace with a custom string to MustInit, or use the prefix struct tag to add prefixes to nested struct fields.

How do I prevent metricx tag misuse in my codebase?

Install golintx in your repository so CI checks catch tag misuse at merge request stage, and install the bytecheck IDE plugin for earlier detection during coding. These tools validate that reported tags match tnames declarations.