Course contentsShow
← Node.js
Lesson 1770 of 1,98015. Logging, Observability, and MetricsFree lesson

Standardizing Metric Naming Conventions

Implement strict naming hierarchies for metrics to facilitate easier dashboarding.

In this lesson, you will learn how to design structured naming hierarchies for your metrics to ensure your dashboards remain readable, searchable, and scalable across complex distributed systems.

The Problem with Ad-hoc Naming

As your Node.js application grows, the "Wild West" approach to naming—where developers choose names like api_calls, requests_total, or db_latency—leads to cognitive overload and broken dashboard queries. When metrics lack a standard structure, building a unified view of your system health becomes an impossible task of guessing and regex matching.

The Hierarchical Convention

To facilitate easier dashboarding, adopt a hierarchical naming convention that follows a domain.subdomain.resource.action.unit pattern. By enforcing this structure, you enable grouping, filtering, and aggregation at scale.

Consider a standard for a database query:

  • system: The source (e.g., app_server)
  • domain: The functional area (e.g., orders)
  • resource: The specific entity (e.g., pg_pool)
  • action: The operation (e.g., query)
  • unit: The metric type (e.g., duration_ms)

Implementation Example

When instrumenting your Node.js services, define a constant registry for these names rather than hardcoding strings inside your business logic. This ensures consistency across microservices:

const METRIC_NAMES = {
  ORDERS_DB_QUERY_DURATION: 'app_server.orders.pg_pool.query.duration_ms',
  ORDERS_DB_QUERY_COUNT: 'app_server.orders.pg_pool.query.total_count',
};

// Usage
metrics.histogram(METRIC_NAMES.ORDERS_DB_QUERY_DURATION, duration, { 
  table: 'checkout_items' 
});

Why This Matters for Dashboarding

With this convention, your monitoring tool’s auto-complete feature becomes a powerful tool rather than a source of confusion. You can instantly query all database-related metrics using a simple glob pattern: app_server.orders.*.query.*.

Furthermore, by standardizing the unit at the end of the string, you allow your observability platform to automatically apply the correct Y-axis formatting (e.g., ms, seconds, count) without manual configuration for every single chart.

Key Takeaway: Standardize your metrics using a rigid, hierarchical domain.resource.action.unit naming convention to turn chaotic telemetry into a clean, queryable, and self-documenting data set.