Metrics
Metrics protocol schemas
Metrics Protocol - Performance and Operational Metrics
Comprehensive metrics collection and monitoring:
-
Counter, Gauge, Histogram, Summary metric types
-
Time-series data collection
-
SLI/SLO definitions
-
Metric aggregation and export
-
Integration with monitoring systems (Prometheus, etc.)
Source: packages/spec/src/system/metrics.zod.ts
TypeScript Usage
import { HistogramBucketConfig, MetricAggregationConfig, MetricAggregationType, MetricDataPoint, MetricDefinition, MetricExportConfig, MetricLabels, MetricType, MetricUnit, MetricsConfig, ServiceLevelIndicator, ServiceLevelObjective, TimeSeries, TimeSeriesDataPoint } from '@objectstack/spec/system';
import type { HistogramBucketConfig, MetricAggregationConfig, MetricAggregationType, MetricDataPoint, MetricDefinition, MetricExportConfig, MetricLabels, MetricType, MetricUnit, MetricsConfig, ServiceLevelIndicator, ServiceLevelObjective, TimeSeries, TimeSeriesDataPoint } from '@objectstack/spec/system';
// Validate data
const result = HistogramBucketConfig.parse(data);HistogramBucketConfig
Histogram bucket configuration
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| type | Enum<'linear' | 'exponential' | 'explicit'> | ✅ | Bucket type |
| linear | Object | optional | |
| exponential | Object | optional | |
| explicit | Object | optional |
MetricAggregationConfig
Metric aggregation configuration
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| type | Enum<'sum' | 'avg' | 'min' | 'max' | 'count' | 'p50' | 'p75' | 'p90' | 'p95' | 'p99' | 'p999' | 'rate' | 'stddev'> | ✅ | Aggregation type |
| window | Object | optional | |
| groupBy | string[] | optional | Group by label names |
| filters | Record<string, any> | optional | Filter criteria |
MetricAggregationType
Metric aggregation type
Allowed Values
sumavgminmaxcountp50p75p90p95p99p999ratestddev
MetricDataPoint
Metric data point
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Metric name |
| type | Enum<'counter' | 'gauge' | 'histogram' | 'summary'> | ✅ | Metric type |
| timestamp | string | ✅ | Observation timestamp |
| value | number | optional | Metric value |
| labels | Record<string, string> | optional | Metric labels |
| histogram | Object | optional | |
| summary | Object | optional |
MetricDefinition
Metric definition
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Metric name (snake_case) |
| label | string | optional | Display label |
| type | Enum<'counter' | 'gauge' | 'histogram' | 'summary'> | ✅ | Metric type |
| unit | Enum<'nanoseconds' | 'microseconds' | 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'bytes' | 'kilobytes' | 'megabytes' | 'gigabytes' | 'terabytes' | 'requests_per_second' | 'events_per_second' | 'bytes_per_second' | 'percent' | 'ratio' | 'count' | 'operations' | 'custom'> | optional | Metric unit |
| description | string | optional | Metric description |
| labelNames | string[] | ✅ | Label names |
| histogram | Object | optional | Histogram bucket configuration |
| summary | Object | optional | |
| enabled | boolean | ✅ |
MetricExportConfig
Metric export configuration
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| type | Enum<'prometheus' | 'openmetrics' | 'graphite' | 'statsd' | 'influxdb' | 'datadog' | 'cloudwatch' | 'stackdriver' | 'azure_monitor' | 'http' | 'custom'> | ✅ | Export type |
| endpoint | string | optional | Export endpoint |
| interval | integer | ✅ | |
| batch | Object | optional | |
| auth | Object | optional | |
| config | Record<string, any> | optional | Additional configuration |
MetricType
Metric type
Allowed Values
countergaugehistogramsummary
MetricUnit
Metric unit
Allowed Values
nanosecondsmicrosecondsmillisecondssecondsminuteshoursdaysbyteskilobytesmegabytesgigabytesterabytesrequests_per_secondevents_per_secondbytes_per_secondpercentratiocountoperationscustom
MetricsConfig
Metrics configuration
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Configuration name (snake_case, max 64 chars) |
| label | string | ✅ | Display label |
| enabled | boolean | ✅ | |
| metrics | Object[] | ✅ | |
| defaultLabels | Record<string, string> | ✅ | Metric labels |
| aggregations | Object[] | ✅ | |
| slis | Object[] | ✅ | |
| slos | Object[] | ✅ | |
| exports | Object[] | ✅ | |
| collectionInterval | integer | ✅ | |
| retention | Object | optional | |
| cardinalityLimits | Object | optional |
ServiceLevelIndicator
Service Level Indicator
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | SLI name (snake_case) |
| label | string | ✅ | Display label |
| description | string | optional | SLI description |
| metric | string | ✅ | Base metric name |
| type | Enum<'availability' | 'latency' | 'throughput' | 'error_rate' | 'saturation' | 'custom'> | ✅ | SLI type |
| successCriteria | Object | ✅ | Success criteria |
| window | Object | ✅ | Measurement window |
| enabled | boolean | ✅ |
ServiceLevelObjective
Service Level Objective
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | SLO name (snake_case) |
| label | string | ✅ | Display label |
| description | string | optional | SLO description |
| sli | string | ✅ | SLI name |
| target | number | ✅ | Target percentage |
| period | Object | ✅ | Time period |
| errorBudget | Object | optional | |
| alerts | Object[] | ✅ | |
| enabled | boolean | ✅ |
TimeSeries
Time series
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| name | string | ✅ | Series name |
| labels | Record<string, string> | optional | Series labels |
| dataPoints | Object[] | ✅ | Data points |
| startTime | string | optional | Start time |
| endTime | string | optional | End time |
TimeSeriesDataPoint
Time series data point
Properties
| Property | Type | Required | Description |
|---|---|---|---|
| timestamp | string | ✅ | Timestamp |
| value | number | ✅ | Value |
| labels | Record<string, string> | optional | Labels |