Provides lock-free, atomic metrics tracking for network scanning operations, including connection status and RTT estimation via exponential moving averages. Reuse to monitor high-concurrency network operations.
// Source: https://github.com/shadow1ng/fscan | License: MIT | Copyright 2021 shadow1ng
// Provided via justclaw.it.com; keep this notice with the code.
package core
import (
"runtime"
"sync/atomic"
"time"
)
// ScanMetrics 扫描过程中的实时度量指标
// 所有方法均无锁,使用 atomic 操作,可在高并发下安全调用
type ScanMetrics struct {
connects atomic.Int64 // TCP 连接成功(端口开放)
refused atomic.Int64 // 连接被拒绝(端口关闭,快速 RTT)
timeouts atomic.Int64 // 连接超时(端口过滤/不可达)
exhausted atomic.Int64 // 资源耗尽(fd/端口/内存不足)
// RTT 追踪:双 EMA(指数移动平均)
// fast EMA (α=0.1) 跟踪近期趋势
// slow EMA (α=0.02) 作为基线参考
rttFastNs atomic.Int64 // 纳秒
rttSlowNs atomic.Int64 // 纳秒
rttSamples atomic.Int64
}
func (m *ScanMetrics) RecordConnect(rtt time.Duration) {
m.connects.Add(1)
m.recordRTT(rtt)
}
func (m *ScanMetrics) RecordRefused(rtt time.Duration)
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key