Documentation
¶
Overview ¶
Package metrics provides efficient metrics collection for NFTBan This collector replaces slow bash-based metrics with fast Go implementation
Package metrics provides Prometheus metrics for NFTBan operations This file contains application-level metrics for ban/unban operations, feed loading, sync operations, and authentication
Index ¶
- func RecordAPIRequest(endpoint, method string, statusCode int, durationSec float64)
- func RecordAuthAttempt(success bool)
- func RecordAuthFailure(reason string)
- func RecordBan(source, family string)
- func RecordBanByCountry(country string)
- func RecordBanError(source, errorType string)
- func RecordDDoSDetection(attackType string)
- func RecordDDoSMitigation(action string)
- func RecordDetectionByCountry(country, module string)
- func RecordError(module, errorType string)
- func RecordEventBusDrop()
- func RecordFeedLoad(feedName string, durationSec float64, success bool)
- func RecordIPCConnectionWait(waitSec float64)
- func RecordIPCRejection(reason string)
- func RecordIPCRequest(method string, success bool, latencySec float64)
- func RecordLoginmonBan(family, reason string)
- func RecordLoginmonDetection(reason, service string)
- func RecordLoginmonDetectionLatency(latencySec float64)
- func RecordLoginmonScoreAtBan(score float64)
- func RecordNFTCLI(operation string, durationSec float64, err error)
- func RecordOpQueueDrop(lane string)
- func RecordPortscanBan(family string)
- func RecordPortscanDetection(protocol string)
- func RecordReconciliationDuration(seconds float64)
- func RecordReconciliationRun()
- func RecordSuricataBan(category, family string)
- func RecordSuricataEvent(eventType string)
- func RecordSuricataProcessingLatency(latencySec float64)
- func RecordSync(operation string, durationSec float64, success bool)
- func RecordSyncIPChanges(added, removed int)
- func RecordUnban(source, family string)
- func RecordUnbanError(source, errorType string)
- func RegisterWithSampler()
- func SetActiveBans(family, banType string, count int)
- func SetCIDRCurrentTotal(count int)
- func SetCIDRLimitHard(limit int)
- func SetDDoSActiveMitigations(count int)
- func SetFeedIPsLoaded(feedName, family string, count float64)
- func SetIPCConnectionsActive(count int)
- func SetIPCConnectionsPeak(peak int)
- func SetIPCSemaphoreAvailable(available int)
- func SetLoginmonTrackedIPs(count int)
- func SetMemoryBudgetBytes(bytes int64)
- func SetMemoryPressureLevel(level int)
- func SetMemoryUsedPercent(percent float64)
- func SetModuleStatus(module string, enabled bool)
- func SetOpQueueUtilization(lane string, pending, capacity int64)
- func SetPermanentBansEvictable(count int)
- func SetPermanentBansProtected(count int)
- func SetPermanentBansTotal(count int)
- func SetPortscanTrackedIPs(count int)
- func SetProtectionActive(active bool)
- func SetProtectionFeedsSkipped(skipped bool)
- func SetProtectionGeobanSkipped(skipped bool)
- func SetReconciliationDrift(setName string, drift float64)
- func SetReconciliationLastTimestamp(ts float64)
- func SetSchemaErrorsTotal(count int)
- func SetSchemaValidationStatus(drifted bool)
- func SetSuricataAlertsActive(count int)
- func SetSuricataEveLag(lagSeconds float64)
- func SetWhitelistOverlapCount(count int)
- type Collector
- type ConnectionStats
- type InterfaceStats
- type Sample
- type Sampler
- func (s *Sampler) AddSession()
- func (s *Sampler) DisableMetrics()
- func (s *Sampler) EnableMetrics()
- func (s *Sampler) GetRecentSamples(count int) []Sample
- func (s *Sampler) GetStatus() map[string]interface{}
- func (s *Sampler) IsMetricsEnabled() bool
- func (s *Sampler) Registry() *prometheus.Registry
- func (s *Sampler) RemoveSession()
- type TCPStats
- type UDPStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RecordAPIRequest ¶
RecordAPIRequest records an API request
func RecordAuthAttempt ¶
func RecordAuthAttempt(success bool)
RecordAuthAttempt records an authentication attempt
func RecordAuthFailure ¶
func RecordAuthFailure(reason string)
RecordAuthFailure records an authentication failure with reason
func RecordBanByCountry ¶
func RecordBanByCountry(country string)
RecordBanByCountry records a ban for a specific country
func RecordBanError ¶
func RecordBanError(source, errorType string)
RecordBanError records a ban operation error
func RecordDDoSDetection ¶
func RecordDDoSDetection(attackType string)
RecordDDoSDetection records a DDoS attack detection
func RecordDDoSMitigation ¶
func RecordDDoSMitigation(action string)
RecordDDoSMitigation records a DDoS mitigation action
func RecordDetectionByCountry ¶
func RecordDetectionByCountry(country, module string)
RecordDetectionByCountry records a detection for a specific country and module
func RecordError ¶
func RecordError(module, errorType string)
RecordError records an error for a module
func RecordEventBusDrop ¶
func RecordEventBusDrop()
RecordEventBusDrop records a dropped event from the EventBus
func RecordFeedLoad ¶
RecordFeedLoad records a feed load operation with duration
func RecordIPCConnectionWait ¶
func RecordIPCConnectionWait(waitSec float64)
RecordIPCConnectionWait records time spent waiting for semaphore slot
func RecordIPCRejection ¶
func RecordIPCRejection(reason string)
RecordIPCRejection records an IPC connection rejection with reason Reasons: "at_capacity", "auth_failed", "read_error", "timeout"
func RecordIPCRequest ¶
RecordIPCRequest records an IPC request with its status
func RecordLoginmonBan ¶
func RecordLoginmonBan(family, reason string)
RecordLoginmonBan records a ban triggered by loginmon
func RecordLoginmonDetection ¶
func RecordLoginmonDetection(reason, service string)
RecordLoginmonDetection records a login failure detection
func RecordLoginmonDetectionLatency ¶
func RecordLoginmonDetectionLatency(latencySec float64)
RecordLoginmonDetectionLatency records detection processing latency
func RecordLoginmonScoreAtBan ¶
func RecordLoginmonScoreAtBan(score float64)
RecordLoginmonScoreAtBan records the score when a ban is triggered
func RecordNFTCLI ¶
RecordNFTCLI records an nft CLI command execution
func RecordOpQueueDrop ¶
func RecordOpQueueDrop(lane string)
RecordOpQueueDrop records a dropped operation due to queue backpressure lane should be "fast" (ban/unban) or "bulk" (feeds/geoban)
func RecordPortscanBan ¶
func RecordPortscanBan(family string)
RecordPortscanBan records a ban triggered by portscan detection
func RecordPortscanDetection ¶
func RecordPortscanDetection(protocol string)
RecordPortscanDetection records a port scan detection
func RecordReconciliationDuration ¶
func RecordReconciliationDuration(seconds float64)
RecordReconciliationDuration records the duration of a reconciliation cycle
func RecordReconciliationRun ¶
func RecordReconciliationRun()
RecordReconciliationRun increments the total reconciliation runs counter
func RecordSuricataBan ¶
func RecordSuricataBan(category, family string)
RecordSuricataBan records a ban triggered by Suricata alert
func RecordSuricataEvent ¶
func RecordSuricataEvent(eventType string)
RecordSuricataEvent records a Suricata event from eve.json
func RecordSuricataProcessingLatency ¶
func RecordSuricataProcessingLatency(latencySec float64)
RecordSuricataProcessingLatency records time from EVE event to ban action
func RecordSync ¶
RecordSync records a sync operation with duration
func RecordSyncIPChanges ¶
func RecordSyncIPChanges(added, removed int)
RecordSyncIPChanges records IPs added/removed during sync
func RecordUnban ¶
func RecordUnban(source, family string)
RecordUnban records a successful unban operation
func RecordUnbanError ¶
func RecordUnbanError(source, errorType string)
RecordUnbanError records an unban operation error
func RegisterWithSampler ¶
func RegisterWithSampler()
RegisterWithSampler registers all nftban metrics with the global sampler's registry This should be called once during application startup
func SetActiveBans ¶
SetActiveBans sets the current number of active bans
func SetCIDRCurrentTotal ¶
func SetCIDRCurrentTotal(count int)
SetCIDRCurrentTotal sets the current total CIDRs loaded
func SetCIDRLimitHard ¶
func SetCIDRLimitHard(limit int)
SetCIDRLimitHard sets the maximum CIDRs allowed for this server tier
func SetDDoSActiveMitigations ¶
func SetDDoSActiveMitigations(count int)
SetDDoSActiveMitigations sets the number of currently active mitigations
func SetFeedIPsLoaded ¶
SetFeedIPsLoaded sets the number of IPs loaded from a feed
func SetIPCConnectionsActive ¶
func SetIPCConnectionsActive(count int)
SetIPCConnectionsActive sets the current number of active IPC connections
func SetIPCConnectionsPeak ¶
func SetIPCConnectionsPeak(peak int)
SetIPCConnectionsPeak sets the peak concurrent connections (high water mark)
func SetIPCSemaphoreAvailable ¶
func SetIPCSemaphoreAvailable(available int)
SetIPCSemaphoreAvailable sets the number of available semaphore slots
func SetLoginmonTrackedIPs ¶
func SetLoginmonTrackedIPs(count int)
SetLoginmonTrackedIPs sets the current number of tracked IPs
func SetMemoryBudgetBytes ¶
func SetMemoryBudgetBytes(bytes int64)
SetMemoryBudgetBytes sets the configured memory budget in bytes
func SetMemoryPressureLevel ¶
func SetMemoryPressureLevel(level int)
SetMemoryPressureLevel sets the current memory pressure level Levels: 0=normal, 1=warning, 2=high, 3=critical
func SetMemoryUsedPercent ¶
func SetMemoryUsedPercent(percent float64)
SetMemoryUsedPercent sets the current memory usage as a percentage of budget
func SetModuleStatus ¶
SetModuleStatus sets the enabled status of a module
func SetOpQueueUtilization ¶
SetOpQueueUtilization sets the current queue utilization percentage pending = current pending operations, capacity = max queue size
func SetPermanentBansEvictable ¶
func SetPermanentBansEvictable(count int)
SetPermanentBansEvictable sets the number of bans eligible for cleanup
func SetPermanentBansProtected ¶
func SetPermanentBansProtected(count int)
SetPermanentBansProtected sets the number of bans marked as "never evict"
func SetPermanentBansTotal ¶
func SetPermanentBansTotal(count int)
SetPermanentBansTotal sets the total number of permanent bans tracked
func SetPortscanTrackedIPs ¶
func SetPortscanTrackedIPs(count int)
SetPortscanTrackedIPs sets the current number of IPs being tracked for port scanning
func SetProtectionActive ¶
func SetProtectionActive(active bool)
SetProtectionActive sets whether memory protection is currently triggered
func SetProtectionFeedsSkipped ¶
func SetProtectionFeedsSkipped(skipped bool)
SetProtectionFeedsSkipped sets whether feeds were skipped due to memory pressure
func SetProtectionGeobanSkipped ¶
func SetProtectionGeobanSkipped(skipped bool)
SetProtectionGeobanSkipped sets whether geoban was skipped due to memory pressure
func SetReconciliationDrift ¶
SetReconciliationDrift sets the drift count for a specific set
func SetReconciliationLastTimestamp ¶
func SetReconciliationLastTimestamp(ts float64)
SetReconciliationLastTimestamp sets the timestamp of the last reconciliation
func SetSchemaErrorsTotal ¶
func SetSchemaErrorsTotal(count int)
SetSchemaErrorsTotal sets the number of schema errors detected
func SetSchemaValidationStatus ¶
func SetSchemaValidationStatus(drifted bool)
SetSchemaValidationStatus sets whether schema validation passed or failed
func SetSuricataAlertsActive ¶
func SetSuricataAlertsActive(count int)
SetSuricataAlertsActive sets the number of IPs being tracked from alerts
func SetSuricataEveLag ¶
func SetSuricataEveLag(lagSeconds float64)
SetSuricataEveLag sets the EVE log freshness (seconds since last event)
func SetWhitelistOverlapCount ¶
func SetWhitelistOverlapCount(count int)
SetWhitelistOverlapCount sets the number of overlapping IPs
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector efficiently gathers NFTBan metrics for Prometheus export
func NewCollector ¶
NewCollector creates a new metrics collector
type ConnectionStats ¶
type ConnectionStats struct {
TCP int
}
ConnectionStats represents connection statistics
type InterfaceStats ¶
InterfaceStats represents network interface statistics
type Sample ¶
type Sample struct {
Timestamp time.Time `json:"timestamp"`
Version string `json:"version"`
BlockedIPs int `json:"blocked_ips"`
RuleCount int `json:"rule_count"`
HealthOK bool `json:"health_ok"`
FeedsActive int `json:"feeds_active"`
NetworkRxMbps float64 `json:"network_rx_mbps"`
NetworkTxMbps float64 `json:"network_tx_mbps"`
RawData map[string]interface{} `json:"raw_data,omitempty"`
}
Sample represents a single metrics snapshot
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler manages global metrics collection
func GetSampler ¶
func GetSampler() *Sampler
GetSampler returns the global sampler instance (singleton)
func (*Sampler) AddSession ¶
func (s *Sampler) AddSession()
AddSession increments active session count and starts sampling if needed
func (*Sampler) DisableMetrics ¶
func (s *Sampler) DisableMetrics()
DisableMetrics disables continuous sampling (back to session-based logic)
func (*Sampler) EnableMetrics ¶
func (s *Sampler) EnableMetrics()
EnableMetrics enables continuous sampling (overrides session-based logic)
func (*Sampler) GetRecentSamples ¶
GetRecentSamples returns the most recent N samples
func (*Sampler) IsMetricsEnabled ¶
IsMetricsEnabled returns whether continuous metrics mode is enabled
func (*Sampler) Registry ¶
func (s *Sampler) Registry() *prometheus.Registry
Registry returns the Prometheus registry
func (*Sampler) RemoveSession ¶
func (s *Sampler) RemoveSession()
RemoveSession decrements active session count and stops sampling if needed