metrics

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Counter

func Counter(name string, value float64, labels map[string]string)

Counter records a counter metric

func Gauge

func Gauge(name string, value float64, labels map[string]string)

Gauge records a gauge metric

func Histogram

func Histogram(name string, value float64, labels map[string]string)

Histogram records a histogram metric

func Timer

func Timer(name string, labels map[string]string) func()

Timer starts a timer and returns a function to stop it

Types

type CloudWatchExporter

type CloudWatchExporter struct {
	// contains filtered or unexported fields
}

CloudWatchExporter exports metrics to AWS CloudWatch

func (*CloudWatchExporter) Export

func (c *CloudWatchExporter) Export(ctx context.Context, metrics []*Metric) error

func (*CloudWatchExporter) Name

func (c *CloudWatchExporter) Name() string

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector collects and aggregates metrics

func GetGlobalCollector

func GetGlobalCollector() *Collector

GetGlobalCollector returns the global metrics collector

func NewCollector

func NewCollector(bufferSize int, flushInterval time.Duration) *Collector

NewCollector creates a new metrics collector

func (*Collector) AddExporter

func (c *Collector) AddExporter(exporter Exporter)

AddExporter adds a metric exporter

func (*Collector) Counter

func (c *Collector) Counter(name string, value float64, labels map[string]string)

Counter increments a counter metric

func (*Collector) Gauge

func (c *Collector) Gauge(name string, value float64, labels map[string]string)

Gauge sets a gauge metric

func (*Collector) Histogram

func (c *Collector) Histogram(name string, value float64, labels map[string]string)

Histogram records a histogram metric

func (*Collector) Stop

func (c *Collector) Stop()

Stop stops the collector

func (*Collector) Summary

func (c *Collector) Summary(name string, value float64, labels map[string]string)

Summary records a summary metric

func (*Collector) Timer

func (c *Collector) Timer(name string, labels map[string]string) func()

Timer records the duration of an operation

type DatadogExporter

type DatadogExporter struct {
	// contains filtered or unexported fields
}

DatadogExporter exports metrics to Datadog

func (*DatadogExporter) Export

func (d *DatadogExporter) Export(ctx context.Context, metrics []*Metric) error

func (*DatadogExporter) Name

func (d *DatadogExporter) Name() string

type Exporter

type Exporter interface {
	Export(ctx context.Context, metrics []*Metric) error
	Name() string
}

Exporter interface for metric exporters

type HTTPClient

type HTTPClient interface {
	Post(ctx context.Context, url string, data []byte) error
}

type HistogramMetric added in v1.1.0

type HistogramMetric struct {
	// contains filtered or unexported fields
}

HistogramMetric provides histogram functionality

func NewHistogramMetric added in v1.1.0

func NewHistogramMetric() *HistogramMetric

NewHistogramMetric creates a new histogram metric

func (*HistogramMetric) Percentile added in v1.1.0

func (h *HistogramMetric) Percentile(p float64) float64

Percentile calculates a percentile

func (*HistogramMetric) Record added in v1.1.0

func (h *HistogramMetric) Record(value float64)

Record records a value

type Metric

type Metric struct {
	Name        string                 `json:"name"`
	Type        MetricType             `json:"type"`
	Value       float64                `json:"value"`
	Labels      map[string]string      `json:"labels,omitempty"`
	Timestamp   time.Time              `json:"timestamp"`
	Description string                 `json:"description,omitempty"`
	Unit        string                 `json:"unit,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

Metric represents a single metric

type MetricType

type MetricType string

MetricType represents the type of metric

const (
	MetricTypeCounter   MetricType = "counter"
	MetricTypeGauge     MetricType = "gauge"
	MetricTypeHistogram MetricType = "histogram"
	MetricTypeSummary   MetricType = "summary"
)

type MetricsTracker

type MetricsTracker struct {
	// contains filtered or unexported fields
}

MetricsTracker tracks various application metrics

func GetGlobalTracker

func GetGlobalTracker() *MetricsTracker

GetGlobalTracker returns the global metrics tracker instance

func (*MetricsTracker) DecrementActiveDetections

func (mt *MetricsTracker) DecrementActiveDetections()

DecrementActiveDetections decrements the active detections counter

func (*MetricsTracker) GetAPIMetrics

func (mt *MetricsTracker) GetAPIMetrics() (requests, errors, avgLatencyMs int64)

GetAPIMetrics returns API metrics

func (*MetricsTracker) GetActiveDetections

func (mt *MetricsTracker) GetActiveDetections() int64

GetActiveDetections returns the current number of active detections

func (*MetricsTracker) GetAllMetrics

func (mt *MetricsTracker) GetAllMetrics() map[string]interface{}

GetAllMetrics returns all metrics as a map

func (*MetricsTracker) GetCacheEvictions

func (mt *MetricsTracker) GetCacheEvictions() int64

GetCacheEvictions returns the total number of cache evictions

func (*MetricsTracker) GetCacheHits

func (mt *MetricsTracker) GetCacheHits() int64

GetCacheHits returns the total number of cache hits

func (*MetricsTracker) GetCacheMisses

func (mt *MetricsTracker) GetCacheMisses() int64

GetCacheMisses returns the total number of cache misses

func (*MetricsTracker) GetCompletedDetections

func (mt *MetricsTracker) GetCompletedDetections() int64

GetCompletedDetections returns the total number of completed detections

func (*MetricsTracker) GetDiscoveryMetrics

func (mt *MetricsTracker) GetDiscoveryMetrics() (runs, errors, resources int64, lastRun *time.Time)

GetDiscoveryMetrics returns discovery metrics

func (*MetricsTracker) GetFailedDetections

func (mt *MetricsTracker) GetFailedDetections() int64

GetFailedDetections returns the total number of failed detections

func (*MetricsTracker) GetMessagesQueued

func (mt *MetricsTracker) GetMessagesQueued() int64

GetMessagesQueued returns the current number of queued messages

func (*MetricsTracker) GetMessagesReceived

func (mt *MetricsTracker) GetMessagesReceived() int64

GetMessagesReceived returns the total number of messages received

func (*MetricsTracker) GetMessagesSent

func (mt *MetricsTracker) GetMessagesSent() int64

GetMessagesSent returns the total number of messages sent

func (*MetricsTracker) GetRemediationMetrics

func (mt *MetricsTracker) GetRemediationMetrics() (runs, success, failures int64)

GetRemediationMetrics returns remediation metrics

func (*MetricsTracker) IncrementActiveDetections

func (mt *MetricsTracker) IncrementActiveDetections()

IncrementActiveDetections increments the active detections counter

func (*MetricsTracker) IncrementCacheEviction

func (mt *MetricsTracker) IncrementCacheEviction()

IncrementCacheEviction increments the cache eviction counter

func (*MetricsTracker) IncrementCacheHit

func (mt *MetricsTracker) IncrementCacheHit()

IncrementCacheHit increments the cache hit counter

func (*MetricsTracker) IncrementCacheMiss

func (mt *MetricsTracker) IncrementCacheMiss()

IncrementCacheMiss increments the cache miss counter

func (*MetricsTracker) IncrementCompletedDetections

func (mt *MetricsTracker) IncrementCompletedDetections()

IncrementCompletedDetections increments the completed detections counter

func (*MetricsTracker) IncrementFailedDetections

func (mt *MetricsTracker) IncrementFailedDetections()

IncrementFailedDetections increments the failed detections counter

func (*MetricsTracker) IncrementMessagesReceived

func (mt *MetricsTracker) IncrementMessagesReceived()

IncrementMessagesReceived increments the messages received counter

func (*MetricsTracker) IncrementMessagesSent

func (mt *MetricsTracker) IncrementMessagesSent()

IncrementMessagesSent increments the messages sent counter

func (*MetricsTracker) RecordAPIRequest

func (mt *MetricsTracker) RecordAPIRequest(latencyMs int64, isError bool)

RecordAPIRequest records an API request with latency

func (*MetricsTracker) RecordDiscoveryRun

func (mt *MetricsTracker) RecordDiscoveryRun(resourcesFound int, isError bool)

RecordDiscoveryRun records a discovery run

func (*MetricsTracker) RecordRemediationRun

func (mt *MetricsTracker) RecordRemediationRun(success bool)

RecordRemediationRun records a remediation run

func (*MetricsTracker) Reset

func (mt *MetricsTracker) Reset()

Reset resets all metrics (useful for testing)

func (*MetricsTracker) SetMessagesQueued

func (mt *MetricsTracker) SetMessagesQueued(count int64)

SetMessagesQueued sets the current number of queued messages

type PrometheusExporter

type PrometheusExporter struct {
	// contains filtered or unexported fields
}

PrometheusExporter exports metrics in Prometheus format

func NewPrometheusExporter

func NewPrometheusExporter(endpoint string, client HTTPClient) *PrometheusExporter

NewPrometheusExporter creates a Prometheus exporter

func (*PrometheusExporter) Export

func (p *PrometheusExporter) Export(ctx context.Context, metrics []*Metric) error

func (*PrometheusExporter) Name

func (p *PrometheusExporter) Name() string

type RateLimitMetrics

type RateLimitMetrics struct {
	// contains filtered or unexported fields
}

RateLimitMetrics tracks rate limiting metrics

func (*RateLimitMetrics) GetStats

func (r *RateLimitMetrics) GetStats() map[string]int64

GetStats returns rate limit statistics

func (*RateLimitMetrics) RecordRequest

func (r *RateLimitMetrics) RecordRequest(allowed bool, throttled bool)

RecordRequest records a rate limit request

type ResourceMetrics

type ResourceMetrics struct {
	// contains filtered or unexported fields
}

ResourceMetrics tracks resource-specific metrics

func NewResourceMetrics

func NewResourceMetrics(provider string) *ResourceMetrics

NewResourceMetrics creates resource-specific metrics

func (*ResourceMetrics) RecordAPICall

func (r *ResourceMetrics) RecordAPICall(operation string, success bool, duration time.Duration)

RecordAPICall records API call metrics

func (*ResourceMetrics) RecordDiscovery

func (r *ResourceMetrics) RecordDiscovery(resourceType string, count int, duration time.Duration)

RecordDiscovery records discovery metrics

func (*ResourceMetrics) RecordDrift

func (r *ResourceMetrics) RecordDrift(resourceType string, driftCount int, duration time.Duration)

RecordDrift records drift detection metrics

func (*ResourceMetrics) RecordRemediation

func (r *ResourceMetrics) RecordRemediation(resourceType string, success bool, duration time.Duration)

RecordRemediation records remediation metrics

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL