metrics

package
v0.9.23 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package metrics collects and reports job metrics.

Index

Constants

View Source
const (
	StatusLabel   = `status`
	StatusSuccess = `success`
	StatusFail    = `fail`
)

common values for prometheus metrics

View Source
const (
	DNSBlastRootDomainLabel = `root_domain`
	DNSBlastSeedDomainLabel = `seed_domain`
	DNSBlastProtocolLabel   = `protocol`
)

DNS Blast related values and labels for prometheus metrics

View Source
const (
	HTTPDestinationHostLabel = `destination_host`
	HTTPMethodLabel          = `method`
)

HTTP related values and labels

View Source
const (
	PacketgenHostLabel        = `host`
	PacketgenDstHostPortLabel = `dst_host_port`
	PacketgenProtocolLabel    = `protocol`
)

Packetgen related values and labels

View Source
const (
	SlowlorisAddressLabel  = `address`
	SlowlorisProtocolLabel = `protocol`
)

Slowloris related values and labels

View Source
const (
	RawnetAddressLabel  = `address`
	RawnetProtocolLabel = `protocol`
)

Rawnet related values and labels

View Source
const (
	ClientIDLabel = `id`
	CountryLabel  = `country`
)

Client related values and labels

Variables

This section is empty.

Functions

func ExportPrometheusMetrics

func ExportPrometheusMetrics(ctx context.Context, logger *zap.Logger, clientID, listen string)

ExportPrometheusMetrics starts http server and export metrics at address <ip>:9090/metrics, also pushes metrics to gateways randomly

func IncClient added in v0.7.10

func IncClient()

IncClient increments counter of calls from the current client ID

func IncDNSBlast

func IncDNSBlast(rootDomain, seedDomain, protocol, status string)

IncDNSBlast increments counter of sent dns queries

func IncHTTP

func IncHTTP(host, method, status string)

IncHTTP increments counter of sent http queries

func IncPacketgen

func IncPacketgen(host, hostPort, protocol, status, id string)

IncPacketgen increments counter of sent raw packets

func IncRawnetTCP

func IncRawnetTCP(address, status string)

IncRawnetTCP increments counter of sent raw tcp packets

func IncRawnetUDP

func IncRawnetUDP(address, status string)

IncRawnetUDP increments counter of sent raw tcp packets

func IncSlowLoris

func IncSlowLoris(address, protocol, status string)

IncSlowLoris increments counter of sent raw ethernet+ip+tcp/udp packets

func Init added in v0.8.4

func Init(clientID, country string)

Init prometheus counters.

func InitOrFail added in v0.8.4

func InitOrFail(ctx context.Context, logger *zap.Logger, prometheusOn bool, prometheusListenAddress, clientID, country string)

func NewOptionsWithFlags added in v0.8.4

func NewOptionsWithFlags() (prometheusOn *bool, prometheusListenAddress *string)

NewOptionsWithFlags returns metrics options initialized with command line flags.

Types

type Accumulator added in v0.8.23

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

Accumulator for statistical metrics for use in a single job. Requires Flush()-ing to Reporter. Not concurrency-safe.

func (*Accumulator) Add added in v0.8.23

func (a *Accumulator) Add(target string, s Stat, n uint64) *Accumulator

Add n to the Accumulator Stat value. Returns self for chaining.

func (*Accumulator) Clone added in v0.8.23

func (a *Accumulator) Clone(jobID string) *Accumulator

Clone a new, blank metrics Accumulator with the same Reporter as the original.

func (*Accumulator) Flush added in v0.8.23

func (a *Accumulator) Flush()

Flush Accumulator contents to the Reporter.

func (*Accumulator) Inc added in v0.8.23

func (a *Accumulator) Inc(target string, s Stat) *Accumulator

Inc increases Accumulator Stat value by 1. Returns self for chaining.

type ConsoleReporter added in v0.8.32

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

func (*ConsoleReporter) WriteSummary added in v0.8.32

func (r *ConsoleReporter) WriteSummary(tracker *StatsTracker)

type Metrics added in v0.8.32

type Metrics [NumStats]sync.Map // Array of metrics by Stat. Each metric is a map of uint64 values by dimensions.

func (*Metrics) NewAccumulator added in v0.8.32

func (m *Metrics) NewAccumulator(jobID string) *Accumulator

NewAccumulator returns a new metrics Accumulator for the Reporter.

func (*Metrics) Sum added in v0.8.32

func (m *Metrics) Sum(s Stat) uint64

Sum returns a total sum of metric s.

func (*Metrics) SumAllStats added in v0.8.32

func (m *Metrics) SumAllStats(groupTargets bool) (stats PerTargetStats, totals Stats)

Calculates all targets and total stats

type PerTargetStats added in v0.8.23

type PerTargetStats map[string]Stats

PerTargetStats is a map of Stats per target.

func (PerTargetStats) Diff added in v0.9.14

func (PerTargetStats) MarshalLogObject added in v0.8.31

func (ts PerTargetStats) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject is required to log PerTargetStats objects to zap

type Reporter added in v0.8.23

type Reporter interface {
	// WriteSummary dumps Reporter contents into the target.
	WriteSummary(*StatsTracker)
}

Reporter gathers metrics across jobs and reports them. Concurrency-safe.

func NewConsoleReporter added in v0.8.32

func NewConsoleReporter(target io.Writer, groupTargets bool) Reporter

NewConsoleReporter creates a new Reporter which outputs straight to the console

func NewZapReporter added in v0.8.32

func NewZapReporter(logger *zap.Logger, groupTargets bool) Reporter

NewZapReporter creates a new Reporter using a zap logger.

type Stat added in v0.8.23

type Stat int

Stat is the type of statistical metrics.

const (
	RequestsAttemptedStat Stat = iota
	RequestsSentStat
	ResponsesReceivedStat
	BytesSentStat
	BytesReceivedStat

	NumStats
)

type Stats added in v0.8.23

type Stats [NumStats]uint64

Stats contains all metrics packed as an array.

func Diff added in v0.9.14

func Diff(lhs, rhs Stats) Stats

func (*Stats) MarshalLogObject added in v0.8.31

func (stats *Stats) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject is required to log Stats objects to zap

type StatsTracker added in v0.9.16

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

StatsTracker generalizes tracking stats changes between reports

func NewStatsTracker added in v0.9.16

func NewStatsTracker(metrics *Metrics) *StatsTracker

type ZapReporter added in v0.8.32

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

func (*ZapReporter) WriteSummary added in v0.8.32

func (r *ZapReporter) WriteSummary(tracker *StatsTracker)

Jump to

Keyboard shortcuts

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