Documentation
¶
Index ¶
- Constants
- Variables
- func AddCommonLabels(labels map[string]string, common *CommonLabels) map[string]string
- func CopyLabels(labels map[string]string) map[string]string
- func FilterReservedLabels(tags map[string]string) map[string]string
- func FormatLabelsInflux(labels map[string]string) string
- func FormatLabelsJSON(labels map[string]string) map[string]string
- func FormatLabelsPrometheus(labels map[string]string) string
- func MergeTags(tagMaps ...map[string]string) map[string]string
- func NormalizeMetricName(name string) string
- func ParseTags(tags ...string) map[string]string
- func SanitizeLabelForInflux(key, value string) (string, string)
- func SanitizeLabelForPrometheus(key, value string) (string, string)
- func SanitizeLabelForStatsD(key, value string) (string, string)
- func SanitizeLabelKey(key string) string
- func SanitizeLabelValue(value string) string
- func TagsToString(tags map[string]string) string
- func ValidateAndSanitizeTags(tags map[string]string) (map[string]string, error)
- func ValidateLabelKey(key string) error
- func ValidateLabelValue(key, value string) error
- func ValidateMetricName(name string) bool
- type CollectorStats
- type CommonLabels
- type Counter
- type CustomCollector
- type ExportFormat
- type Exporter
- type Gauge
- type Histogram
- type HistogramSample
- type LabelCardinality
- type LabelMetadata
- type LabelRegistry
- type LabelValidationError
- type MetricMetadata
- type MetricSample
- type MetricType
- type MetricValue
- type Metrics
- type MetricsConfig
- type Timer
- type TimerSample
Constants ¶
const ( MetricTypeCounter = shared.MetricTypeCounter MetricTypeGauge = shared.MetricTypeGauge MetricTypeHistogram = shared.MetricTypeHistogram MetricTypeTimer = shared.MetricTypeTimer )
const ( ExportFormatPrometheus = shared.ExportFormatPrometheus ExportFormatJSON = shared.ExportFormatJSON ExportFormatInflux = shared.ExportFormatInflux ExportFormatStatsD = shared.ExportFormatStatsD )
const ( // MaxLabelsPerMetric limits labels per metric to prevent cardinality explosion MaxLabelsPerMetric = 20 // MaxLabelKeyLength limits label key length MaxLabelKeyLength = 128 // MaxLabelValueLength limits label value length MaxLabelValueLength = 256 // MaxLabelCardinality limits unique label combinations MaxLabelCardinality = 10000 )
Variables ¶
var DefaultBuckets = []float64{
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 25, 50, 100, 250, 500, 1000,
}
DefaultBuckets provides default histogram buckets Values in seconds for latency measurements
var ReservedLabels = map[string]bool{ "__name__": true, "__instance__": true, "__job__": true, "__replica__": true, "__tenant__": true, "job": true, "instance": true, "le": true, "quantile": true, }
ReservedLabels are protected system labels
Functions ¶
func AddCommonLabels ¶
func AddCommonLabels(labels map[string]string, common *CommonLabels) map[string]string
AddCommonLabels adds common production labels to existing labels
func CopyLabels ¶
CopyLabels creates a deep copy of labels map
func FilterReservedLabels ¶
FilterReservedLabels removes reserved labels from a tag map
func FormatLabelsInflux ¶
FormatLabelsInflux formats labels for InfluxDB export
func FormatLabelsJSON ¶
FormatLabelsJSON formats labels for JSON export (no special formatting needed)
func FormatLabelsPrometheus ¶
FormatLabelsPrometheus formats labels for Prometheus export
func NormalizeMetricName ¶
NormalizeMetricName normalizes metric name
func SanitizeLabelForInflux ¶
SanitizeLabelForInflux sanitizes labels for InfluxDB format
func SanitizeLabelForPrometheus ¶
SanitizeLabelForPrometheus sanitizes labels for Prometheus format
func SanitizeLabelForStatsD ¶
SanitizeLabelForStatsD sanitizes labels for StatsD format
func SanitizeLabelKey ¶
SanitizeLabelKey sanitizes a label key for safe use
func SanitizeLabelValue ¶
SanitizeLabelValue sanitizes a label value for safe use
func TagsToString ¶
TagsToString converts tags map to string representation
func ValidateAndSanitizeTags ¶
ValidateAndSanitizeTags validates and sanitizes tags for production use
func ValidateLabelKey ¶
ValidateLabelKey validates a label key
func ValidateLabelValue ¶
ValidateLabelValue validates a label value
func ValidateMetricName ¶
ValidateMetricName validates metric name format
Types ¶
type CollectorStats ¶
type CollectorStats = shared.CollectorStats
type CommonLabels ¶
type CommonLabels struct {
Service string
Environment string
Version string
Instance string
Region string
Zone string
}
CommonLabels provides standard labels for production metrics
func (*CommonLabels) ToMap ¶
func (cl *CommonLabels) ToMap() map[string]string
ToMap converts CommonLabels to map
type Counter ¶
Counter represents a counter metric
func NewCounterWithLabels ¶
NewCounterWithLabels creates a new counter with labels
type CustomCollector ¶
type CustomCollector = shared.CustomCollector
CustomCollector defines interface for custom metrics collectors
type ExportFormat ¶
type ExportFormat = shared.ExportFormat
ExportFormat represents the format for metrics export
type Gauge ¶
Gauge represents a gauge metric
func NewGaugeWithLabels ¶
NewGaugeWithLabels creates a new gauge with labels
type Histogram ¶
Histogram represents a histogram metric
func NewHistogram ¶
func NewHistogram() Histogram
NewHistogram creates a new histogram with default buckets
func NewHistogramWithBuckets ¶
NewHistogramWithBuckets creates a new histogram with custom buckets
type HistogramSample ¶
type HistogramSample struct {
Name string `json:"name"`
Count uint64 `json:"count"`
Sum float64 `json:"sum"`
Buckets map[float64]uint64 `json:"buckets"`
Tags map[string]string `json:"tags"`
Timestamp time.Time `json:"timestamp"`
}
HistogramSample represents a histogram sample
type LabelCardinality ¶
type LabelCardinality struct {
// contains filtered or unexported fields
}
LabelCardinality tracks label cardinality to prevent metric explosion
func NewLabelCardinality ¶
func NewLabelCardinality(maxCardinality int) *LabelCardinality
NewLabelCardinality creates a new label cardinality tracker
func (*LabelCardinality) Check ¶
func (lc *LabelCardinality) Check(metricName string, labels map[string]string) bool
Check checks if adding this label combination would exceed cardinality limits
func (*LabelCardinality) GetCardinality ¶
func (lc *LabelCardinality) GetCardinality() int
GetCardinality returns current cardinality count
func (*LabelCardinality) Record ¶
func (lc *LabelCardinality) Record(metricName string, labels map[string]string) error
Record records a label combination
func (*LabelCardinality) Reset ¶
func (lc *LabelCardinality) Reset()
Reset resets the cardinality tracker
type LabelMetadata ¶
type LabelMetadata struct {
Key string `json:"key"`
ValueCount int `json:"value_count"` // Number of unique values seen
LastSeen time.Time `json:"last_seen"` // Last time this label was used
IsHighCardinality bool `json:"is_high_cardinality"` // Flag if cardinality > threshold
SampleValues []string `json:"sample_values"` // Sample of values for debugging
}
LabelMetadata tracks metadata about labels for production observability
type LabelRegistry ¶
type LabelRegistry struct {
// contains filtered or unexported fields
}
LabelRegistry tracks label usage for production monitoring
func NewLabelRegistry ¶
func NewLabelRegistry() *LabelRegistry
NewLabelRegistry creates a new label registry
func (*LabelRegistry) GetHighCardinalityLabels ¶
func (lr *LabelRegistry) GetHighCardinalityLabels() []string
GetHighCardinalityLabels returns labels with high cardinality
func (*LabelRegistry) GetLabelStats ¶
func (lr *LabelRegistry) GetLabelStats() map[string]*LabelMetadata
GetLabelStats returns statistics about labels
func (*LabelRegistry) RecordLabel ¶
func (lr *LabelRegistry) RecordLabel(key, value string)
RecordLabel records usage of a label
type LabelValidationError ¶
LabelValidationError represents a label validation error
func (*LabelValidationError) Error ¶
func (e *LabelValidationError) Error() string
type MetricMetadata ¶
type MetricMetadata struct {
Name string `json:"name"`
Type MetricType `json:"type"`
Description string `json:"description"`
Tags map[string]string `json:"tags"`
Unit string `json:"unit"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
MetricMetadata contains metadata about a metric
type MetricSample ¶
type MetricSample struct {
Name string `json:"name"`
Type MetricType `json:"type"`
Value float64 `json:"value"`
Tags map[string]string `json:"tags"`
Timestamp time.Time `json:"timestamp"`
Unit string `json:"unit"`
}
MetricSample represents a single metric sample
type MetricValue ¶
type MetricValue struct {
Metadata *MetricMetadata `json:"metadata"`
Value interface{} `json:"value"`
Timestamp time.Time `json:"timestamp"`
}
MetricValue represents a metric value with metadata
type MetricsConfig ¶
type MetricsConfig = shared.MetricsConfig
type Timer ¶
Timer represents a timer metric
func NewTimerWithLabels ¶
NewTimerWithLabels creates a new timer with labels
type TimerSample ¶
type TimerSample struct {
Name string `json:"name"`
Count uint64 `json:"count"`
Mean time.Duration `json:"mean"`
Min time.Duration `json:"min"`
Max time.Duration `json:"max"`
P50 time.Duration `json:"p50"`
P95 time.Duration `json:"p95"`
P99 time.Duration `json:"p99"`
Tags map[string]string `json:"tags"`
Timestamp time.Time `json:"timestamp"`
}
TimerSample represents a timer sample