metrics

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecordAPIRequest

func RecordAPIRequest(endpoint, method string, statusCode int, durationSec float64)

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 RecordBan

func RecordBan(source, family string)

RecordBan records a successful ban operation

func RecordBanByCountry added in v1.0.31

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 added in v1.0.31

func RecordDDoSDetection(attackType string)

RecordDDoSDetection records a DDoS attack detection

func RecordDDoSMitigation added in v1.0.31

func RecordDDoSMitigation(action string)

RecordDDoSMitigation records a DDoS mitigation action

func RecordDetectionByCountry added in v1.0.31

func RecordDetectionByCountry(country, module string)

RecordDetectionByCountry records a detection for a specific country and module

func RecordError added in v1.0.31

func RecordError(module, errorType string)

RecordError records an error for a module

func RecordFeedLoad

func RecordFeedLoad(feedName string, durationSec float64, success bool)

RecordFeedLoad records a feed load operation with duration

func RecordIPCRequest added in v1.0.31

func RecordIPCRequest(method string, success bool, latencySec float64)

RecordIPCRequest records an IPC request with its status

func RecordLoginmonBan added in v1.0.31

func RecordLoginmonBan(family, reason string)

RecordLoginmonBan records a ban triggered by loginmon

func RecordLoginmonDetection added in v1.0.31

func RecordLoginmonDetection(reason, service string)

RecordLoginmonDetection records a login failure detection

func RecordLoginmonDetectionLatency added in v1.0.31

func RecordLoginmonDetectionLatency(latencySec float64)

RecordLoginmonDetectionLatency records detection processing latency

func RecordLoginmonScoreAtBan added in v1.0.31

func RecordLoginmonScoreAtBan(score float64)

RecordLoginmonScoreAtBan records the score when a ban is triggered

func RecordNFTCLI

func RecordNFTCLI(operation string, durationSec float64, err error)

RecordNFTCLI records an nft CLI command execution

func RecordPortscanBan added in v1.0.31

func RecordPortscanBan(family string)

RecordPortscanBan records a ban triggered by portscan detection

func RecordPortscanDetection added in v1.0.31

func RecordPortscanDetection(protocol string)

RecordPortscanDetection records a port scan detection

func RecordSync

func RecordSync(operation string, durationSec float64, success bool)

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 added in v1.0.31

func SetActiveBans(family, banType string, count int)

SetActiveBans sets the current number of active bans

func SetDDoSActiveMitigations added in v1.0.31

func SetDDoSActiveMitigations(count int)

SetDDoSActiveMitigations sets the number of currently active mitigations

func SetFeedIPsLoaded

func SetFeedIPsLoaded(feedName, family string, count float64)

SetFeedIPsLoaded sets the number of IPs loaded from a feed

func SetLoginmonTrackedIPs added in v1.0.31

func SetLoginmonTrackedIPs(count int)

SetLoginmonTrackedIPs sets the current number of tracked IPs

func SetModuleStatus

func SetModuleStatus(module string, enabled bool)

SetModuleStatus sets the enabled status of a module

func SetPortscanTrackedIPs added in v1.0.31

func SetPortscanTrackedIPs(count int)

SetPortscanTrackedIPs sets the current number of IPs being tracked for port scanning

Types

type Collector added in v1.0.22

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

Collector efficiently gathers NFTBan metrics for Prometheus export

func NewCollector added in v1.0.22

func NewCollector(outputFile, stateDir, logDir string) *Collector

NewCollector creates a new metrics collector

func (*Collector) Collect added in v1.0.22

func (c *Collector) Collect() error

Collect gathers and writes all metrics to the Prometheus textfile

type ConnectionStats added in v1.0.22

type ConnectionStats struct {
	TCP int
}

ConnectionStats represents connection statistics

type InterfaceStats added in v1.0.22

type InterfaceStats struct {
	RxBytes   uint64
	RxPackets uint64
	TxBytes   uint64
	TxPackets uint64
}

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

func (s *Sampler) GetRecentSamples(count int) []Sample

GetRecentSamples returns the most recent N samples

func (*Sampler) GetStatus

func (s *Sampler) GetStatus() map[string]interface{}

GetStatus returns current sampler status

func (*Sampler) IsMetricsEnabled

func (s *Sampler) IsMetricsEnabled() bool

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

type TCPStats added in v1.0.22

type TCPStats struct {
	InSegs  uint64
	OutSegs uint64
}

TCPStats represents TCP protocol statistics

type UDPStats added in v1.0.22

type UDPStats struct {
	InDatagrams  uint64
	OutDatagrams uint64
}

UDPStats represents UDP protocol statistics

Jump to

Keyboard shortcuts

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