Documentation
¶
Overview ¶
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 RecordBanError(source, errorType string)
- func RecordFeedLoad(feedName string, durationSec float64, success bool)
- func RecordNFTCLI(operation string, durationSec float64, err error)
- 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 SetFeedIPsLoaded(feedName, family string, count float64)
- func SetModuleStatus(module string, enabled bool)
- 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()
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 RecordBanError ¶
func RecordBanError(source, errorType string)
RecordBanError records a ban operation error
func RecordFeedLoad ¶
RecordFeedLoad records a feed load operation with duration
func RecordNFTCLI ¶
RecordNFTCLI records an nft CLI command execution
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 SetFeedIPsLoaded ¶
SetFeedIPsLoaded sets the number of IPs loaded from a feed
func SetModuleStatus ¶
SetModuleStatus sets the enabled status of a module
Types ¶
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