Documentation
¶
Overview ¶
Package metrics provides interfaces for metrics collection and monitoring.
Package metrics provides basic monitoring and metrics collection for scanorama. It supports counters, gauges, and histograms with label support for tracking application performance and operational metrics.
Index ¶
- Constants
- func Counter(name string, labels Labels)
- func Gauge(name string, value float64, labels Labels)
- func GetMetrics() map[string]*Metric
- func Histogram(name string, value float64, labels Labels)
- func IncrementHostsDiscovered(network, method string, count int)
- func IncrementScanErrors(scanType, target, errorType string)
- func IncrementScanTotal(scanType, status string)
- func RecordDatabaseQuery(operation string, duration time.Duration, success bool)
- func RecordDiscoveryDuration(network, method string, duration time.Duration)
- func RecordScanDuration(scanType, target string, duration time.Duration)
- func Reset()
- func SetActiveConnections(count int)
- func SetDefault(registry *Registry)
- func SetEnabled(enabled bool)
- type Labels
- type Metric
- type MetricType
- type MetricsRegistry
- type Registry
- func (r *Registry) Counter(name string, labels Labels)
- func (r *Registry) Gauge(name string, value float64, labels Labels)
- func (r *Registry) GetMetrics() map[string]*Metric
- func (r *Registry) Histogram(name string, value float64, labels Labels)
- func (r *Registry) IsEnabled() bool
- func (r *Registry) Reset()
- func (r *Registry) SetEnabled(enabled bool)
- type Timer
Constants ¶
const ( // Scan metrics. MetricScanDuration = "scan_duration_seconds" MetricScanTotal = "scan_total" MetricScanErrors = "scan_errors_total" MetricPortsScanned = "ports_scanned_total" MetricHostsScanned = "hosts_scanned_total" // Discovery metrics. MetricDiscoveryDuration = "discovery_duration_seconds" MetricDiscoveryTotal = "discovery_total" MetricDiscoveryErrors = "discovery_errors_total" MetricHostsDiscovered = "hosts_discovered_total" // Database metrics. MetricDatabaseQueries = "database_queries_total" MetricDatabaseErrors = "database_errors_total" MetricDatabaseDuration = "database_query_duration_seconds" MetricDatabaseConnections = "database_connections_active" // System metrics. MetricMemoryUsage = "memory_usage_bytes" MetricGoroutines = "goroutines_active" MetricUptime = "uptime_seconds" )
Predefined metric names for common operations.
const ( LabelScanType = "scan_type" LabelTarget = "target" LabelNetwork = "network" LabelMethod = "method" LabelStatus = "status" LabelOperation = "operation" LabelError = "error" LabelComponent = "component" )
Common label keys.
Variables ¶
This section is empty.
Functions ¶
func GetMetrics ¶
GetMetrics returns all metrics from the default registry.
func IncrementHostsDiscovered ¶
IncrementHostsDiscovered increments the hosts discovered counter.
func IncrementScanErrors ¶
func IncrementScanErrors(scanType, target, errorType string)
IncrementScanErrors increments the scan error counter.
func IncrementScanTotal ¶
func IncrementScanTotal(scanType, status string)
IncrementScanTotal increments the total scan counter.
func RecordDatabaseQuery ¶
RecordDatabaseQuery records database query metrics.
func RecordDiscoveryDuration ¶
RecordDiscoveryDuration records the duration of a discovery operation.
func RecordScanDuration ¶
RecordScanDuration records the duration of a scan operation.
func SetActiveConnections ¶
func SetActiveConnections(count int)
SetActiveConnections sets the number of active database connections.
func SetEnabled ¶
func SetEnabled(enabled bool)
SetEnabled enables or disables metrics collection on the default registry.
Types ¶
type MetricType ¶
type MetricType string
MetricType represents the type of metric.
const ( TypeCounter MetricType = "counter" TypeGauge MetricType = "gauge" TypeHistogram MetricType = "histogram" )
type MetricsRegistry ¶
type MetricsRegistry interface { // SetEnabled enables or disables metrics collection. SetEnabled(enabled bool) // IsEnabled returns whether metrics collection is enabled. IsEnabled() bool // Counter increments a counter metric with the given name and labels. Counter(name string, labels Labels) // Gauge sets a gauge metric to the specified value with the given name and labels. Gauge(name string, value float64, labels Labels) // Histogram records a value in a histogram metric with the given name and labels. Histogram(name string, value float64, labels Labels) // GetMetrics returns a snapshot of all current metrics. GetMetrics() map[string]*Metric // Reset clears all metrics from the registry. Reset() }
MetricsRegistry defines the interface for metrics collection and management. This interface allows for easy mocking and testing of metrics functionality.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all metrics and provides collection functionality.
func (*Registry) GetMetrics ¶
GetMetrics returns a snapshot of all current metrics.
func (*Registry) SetEnabled ¶
SetEnabled enables or disables metrics collection.