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
import { HistogramBucketConfigSchema, MetricAggregationConfigSchema, MetricAggregationType, MetricDataPointSchema, MetricDefinitionSchema, MetricExportConfigSchema, MetricLabelsSchema, MetricType, MetricUnit, MetricsConfigSchema, ServiceLevelIndicatorSchema, ServiceLevelObjectiveSchema, TimeSeriesSchema, TimeSeriesDataPointSchema } 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 = HistogramBucketConfigSchema.parse(data);
Histogram bucket configuration
| Property | Type | Required | Description |
|---|
| type | Enum<'linear' | 'exponential' | 'explicit'> | ✅ | Bucket type |
| linear | { start: number; width: number; count: integer } | optional | |
| exponential | { start: number; factor: number; count: integer } | optional | |
| explicit | { boundaries: number[] } | optional | |
| Property | Type | Required | Description |
|---|
| start | number | ✅ | Start value |
| width | number | ✅ | Bucket width |
| count | integer | ✅ | Number of buckets |
| Property | Type | Required | Description |
|---|
| start | number | ✅ | Start value |
| factor | number | ✅ | Growth factor |
| count | integer | ✅ | Number of buckets |
| Property | Type | Required | Description |
|---|
| boundaries | number[] | ✅ | Bucket boundaries |
Metric aggregation configuration
| Property | Type | Required | Description |
|---|
| type | Enum<'sum' | 'avg' | 'min' | 'max' | 'count' | 'p50' | 'p75' | 'p90' | 'p95' | 'p99' | 'p999' | 'rate' | 'stddev'> | ✅ | Aggregation type |
| window | { size: integer; sliding: boolean; slideInterval?: integer } | optional | |
| groupBy | string[] | optional | Group by label names |
| filters | Record<string, any> | optional | Filter criteria |
| Property | Type | Required | Description |
|---|
| size | integer | ✅ | Window size in seconds |
| sliding | boolean | optional (default: false) | |
| slideInterval | integer | optional | |
Metric aggregation type
sum
avg
min
max
count
p50
p75
p90
p95
p99
p999
rate
stddev
Metric data point
| 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 | { count: integer; sum: number; buckets: object[] } | optional | |
| summary | { count: integer; sum: number; quantiles: object[] } | optional | |
| Property | Type | Required | Description |
|---|
| count | integer | ✅ | Total count |
| sum | number | ✅ | Sum of all values |
| buckets | { upperBound: number; count: integer }[] | ✅ | Histogram buckets |
| Property | Type | Required | Description |
|---|
| count | integer | ✅ | Total count |
| sum | number | ✅ | Sum of all values |
| quantiles | { quantile: number; value: number }[] | ✅ | Summary quantiles |
Metric definition
| 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' | … +8 more> | optional | Metric unit |
| description | string | optional | Metric description |
| labelNames | string[] | optional (default: []) | Label names |
| histogram | { type: Enum<'linear' | 'exponential' | 'explicit'>; linear?: object; exponential?: object; explicit?: object } | optional | Histogram bucket configuration |
| summary | { quantiles: number[]; maxAge: integer; ageBuckets: integer } | optional | |
| enabled | boolean | optional (default: true) | |
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
| Property | Type | Required | Description |
|---|
| type | Enum<'linear' | 'exponential' | 'explicit'> | ✅ | Bucket type |
| linear | { start: number; width: number; count: integer } | optional | |
| exponential | { start: number; factor: number; count: integer } | optional | |
| explicit | { boundaries: number[] } | optional | |
Metric export configuration
| 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 | optional (default: 60) | |
| batch | { enabled: boolean; size: integer } | optional | |
| auth | { type: Enum<'none' | 'basic' | 'bearer' | 'api_key'>; username?: string; password?: string; token?: string; … } | optional | |
| config | Record<string, any> | optional | Additional configuration |
| Property | Type | Required | Description |
|---|
| type | Enum<'none' | 'basic' | 'bearer' | 'api_key'> | ✅ | Auth type |
| username | string | optional | |
| password | string | optional | |
| token | string | optional | |
| apiKey | string | optional | |
Metric labels
Type: Record<string, string>
Metric type
counter
gauge
histogram
summary
Metric unit
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
Metrics configuration
| Property | Type | Required | Description |
|---|
| name | string | ✅ | Configuration name (snake_case, max 64 chars) |
| label | string | ✅ | Display label |
| enabled | boolean | optional (default: true) | |
| metrics | { name: string; label?: string; type: Enum<'counter' | 'gauge' | 'histogram' | 'summary'>; unit?: Enum<'nanoseconds' | 'microseconds' | 'milliseconds' | 'seconds' | 'minutes' | …>; … }[] | optional (default: []) | |
| defaultLabels | Record<string, string> | optional (default: {}) | Metric labels |
| aggregations | { type: Enum<'sum' | 'avg' | 'min' | 'max' | 'count' | 'p50' | 'p75' | 'p90' | 'p95' | 'p99' | …>; window?: object; groupBy?: string[]; filters?: Record<string, any> }[] | optional (default: []) | |
| slis | { name: string; label: string; description?: string; metric: string; … }[] | optional | |
| slos | { name: string; label: string; description?: string; sli: string; … }[] | optional (default: []) | |
| exports | { type: Enum<'prometheus' | 'openmetrics' | 'graphite' | 'statsd' | 'influxdb' | 'datadog' | …>; endpoint?: string; interval?: integer; batch?: object; … }[] | optional (default: []) | |
| collectionInterval | integer | optional (default: 15) | |
| retention | { period?: integer; downsampling?: object[] } | optional | |
| cardinalityLimits | { maxLabelCombinations?: integer; onLimitExceeded?: Enum<'drop' | 'sample' | 'alert'> } | optional | |
Metric definition
| 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' | …> | optional | Metric unit |
| description | string | optional | Metric description |
| labelNames | string[] | optional (default: []) | Label names |
| histogram | { type: Enum<'linear' | 'exponential' | 'explicit'>; linear?: object; exponential?: object; explicit?: object } | optional | Histogram bucket configuration |
| summary | { quantiles?: number[]; maxAge?: integer; ageBuckets?: integer } | optional | |
| enabled | boolean | optional (default: true) | |
Metric aggregation configuration
| Property | Type | Required | Description |
|---|
| type | Enum<'sum' | 'avg' | 'min' | 'max' | 'count' | 'p50' | 'p75' | 'p90' | 'p95' | 'p99' | …> | ✅ | Aggregation type |
| window | { size: integer; sliding?: boolean; slideInterval?: integer } | optional | |
| groupBy | string[] | optional | Group by label names |
| filters | Record<string, any> | optional | Filter criteria |
Service Level Indicator
| 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 | { threshold: number; operator: Enum<'lt' | 'lte' | 'gt' | 'gte' | 'eq'>; percentile?: number } | string | { dialect: Enum<'cel' | 'cron' | 'template'>; source?: string; ast?: any; meta?: object } | ✅ | Success criteria — structured or CEL predicate |
| window | { size: integer; rolling?: boolean } | ✅ | Measurement window |
| enabled | boolean | optional (default: true) | |
Service Level Objective
| 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 | { type: Enum<'rolling' | 'calendar'>; duration?: integer; calendar?: Enum<'daily' | 'weekly' | 'monthly' | 'quarterly' | 'yearly'> } | ✅ | Time period |
| errorBudget | { enabled?: boolean; alertThreshold?: number; burnRateWindows?: object[] } | optional | |
| alerts | { name: string; severity: Enum<'info' | 'warning' | 'critical'>; condition: object }[] | optional (default: []) | |
| enabled | boolean | optional (default: true) | |
Metric export configuration
| Property | Type | Required | Description |
|---|
| type | Enum<'prometheus' | 'openmetrics' | 'graphite' | 'statsd' | 'influxdb' | 'datadog' | …> | ✅ | Export type |
| endpoint | string | optional | Export endpoint |
| interval | integer | optional (default: 60) | |
| batch | { enabled?: boolean; size?: integer } | optional | |
| auth | { type: Enum<'none' | 'basic' | 'bearer' | 'api_key'>; username?: string; password?: string; token?: string; … } | optional | |
| config | Record<string, any> | optional | Additional configuration |
Service Level Indicator
| 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 | { threshold: number; operator: Enum<'lt' | 'lte' | 'gt' | 'gte' | 'eq'>; percentile?: number } | string | { dialect: Enum<'cel' | 'cron' | 'template'>; source?: string; ast?: any; meta?: object } | ✅ | Success criteria — structured or CEL predicate |
| window | { size: integer; rolling?: boolean } | ✅ | Measurement window |
| enabled | boolean | optional (default: true) | |
| Property | Type | Required | Description |
|---|
| threshold | number | ✅ | Threshold value |
| operator | Enum<'lt' | 'lte' | 'gt' | 'gte' | 'eq'> | ✅ | Comparison operator |
| percentile | number | optional | Percentile (0-1) |
| Property | Type | Required | Description |
|---|
| size | integer | ✅ | Window size in seconds |
| rolling | boolean | optional (default: true) | |
Service Level Objective
| 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 | { type: Enum<'rolling' | 'calendar'>; duration?: integer; calendar?: Enum<'daily' | 'weekly' | 'monthly' | 'quarterly' | 'yearly'> } | ✅ | Time period |
| errorBudget | { enabled: boolean; alertThreshold: number; burnRateWindows?: object[] } | optional | |
| alerts | { name: string; severity: Enum<'info' | 'warning' | 'critical'>; condition: object }[] | optional (default: []) | |
| enabled | boolean | optional (default: true) | |
| Property | Type | Required | Description |
|---|
| type | Enum<'rolling' | 'calendar'> | ✅ | Period type |
| duration | integer | optional | Duration in seconds |
| calendar | Enum<'daily' | 'weekly' | 'monthly' | 'quarterly' | 'yearly'> | optional | |
| Property | Type | Required | Description |
|---|
| name | string | ✅ | Alert name |
| severity | Enum<'info' | 'warning' | 'critical'> | ✅ | Alert severity |
| condition | { type: Enum<'slo_breach' | 'error_budget' | 'burn_rate'>; threshold?: number } | ✅ | Alert condition |
Time series
| Property | Type | Required | Description |
|---|
| name | string | ✅ | Series name |
| labels | Record<string, string> | optional | Series labels |
| dataPoints | { timestamp: string; value: number; labels?: Record<string, string> }[] | ✅ | Data points |
| startTime | string | optional | Start time |
| endTime | string | optional | End time |
Time series data point
| Property | Type | Required | Description |
|---|
| timestamp | string | ✅ | Timestamp |
| value | number | ✅ | Value |
| labels | Record<string, string> | optional | Labels |
Time series data point
| Property | Type | Required | Description |
|---|
| timestamp | string | ✅ | Timestamp |
| value | number | ✅ | Value |
| labels | Record<string, string> | optional | Labels |