attacker

package
v0.0.0-...-830f7db Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRate        = 50
	DefaultDuration    = 10 * time.Second
	DefaultTimeout     = 30 * time.Second
	DefaultMethod      = http.MethodGet
	DefaultWorkers     = 10
	DefaultMaxWorkers  = math.MaxUint64
	DefaultMaxBody     = int64(-1)
	DefaultConnections = 10000
)

Variables

View Source
var DefaultLocalAddr = net.IPAddr{IP: net.IPv4zero}

Functions

func NewResolver

func NewResolver(addrs []string) *net.Resolver

Types

type Attacker

type Attacker interface {
	// Attack keeps the request running for the specified period of time.
	// Results are sent to the given channel as soon as they arrive.
	// When the attack is over, it gives back final statistics.
	// TODO: Use storage instead of metricsCh
	Attack(ctx context.Context, metricsCh chan *Metrics)

	// Rate gives back the rate set to itself.
	Rate() int
	// Rate gives back the duration set to itself.
	Duration() time.Duration
	// Rate gives back the method set to itself.
	Method() string
}

func NewAttacker

func NewAttacker(storage storage.Writer, target string, opts *Options) (Attacker, error)

type ByteMetrics

type ByteMetrics struct {
	// Total is the total number of flowing bytes in an attack.
	Total uint64 `json:"total"`
	// Mean is the mean number of flowing bytes per hit.
	Mean float64 `json:"mean"`
}

ByteMetrics holds computed byte flow metrics.

type FakeAttacker

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

func (*FakeAttacker) Attack

func (f *FakeAttacker) Attack(ctx context.Context, metricsCh chan *Metrics)

func (*FakeAttacker) Duration

func (f *FakeAttacker) Duration() time.Duration

func (*FakeAttacker) Method

func (f *FakeAttacker) Method() string

func (*FakeAttacker) Rate

func (f *FakeAttacker) Rate() int

type LatencyMetrics

type LatencyMetrics struct {
	// Total is the total latency sum of all requests in an attack.
	Total time.Duration `json:"total"`
	// Mean is the mean request latency.
	Mean time.Duration `json:"mean"`
	// P50 is the 50th percentile request latency.
	P50 time.Duration `json:"50th"`
	// P90 is the 90th percentile request latency.
	P90 time.Duration `json:"90th"`
	// P95 is the 95th percentile request latency.
	P95 time.Duration `json:"95th"`
	// P99 is the 99th percentile request latency.
	P99 time.Duration `json:"99th"`
	// Max is the maximum observed request latency.
	Max time.Duration `json:"max"`
	// Min is the minimum observed request latency.
	Min time.Duration `json:"min"`
}

LatencyMetrics holds computed request latency metrics.

type Metrics

type Metrics struct {
	// Latencies holds computed request latency metrics.
	Latencies LatencyMetrics `json:"latencies"`
	// Histogram, only if requested
	// Histogram *vegeta.Histogram `json:"buckets,omitempty"`
	// BytesIn holds computed incoming byte metrics.
	BytesIn ByteMetrics `json:"bytes_in"`
	// BytesOut holds computed outgoing byte metrics.
	BytesOut ByteMetrics `json:"bytes_out"`
	// Earliest is the earliest timestamp in a Result set.
	Earliest time.Time `json:"earliest"`
	// Latest is the latest timestamp in a Result set.
	Latest time.Time `json:"latest"`
	// End is the latest timestamp in a Result set plus its latency.
	End time.Time `json:"end"`
	// Duration is the duration of the attack.
	Duration time.Duration `json:"duration"`
	// Wait is the extra time waiting for responses from targets.
	Wait time.Duration `json:"wait"`
	// Requests is the total number of requests executed.
	Requests uint64 `json:"requests"`
	// Rate is the rate of sent requests per second.
	Rate float64 `json:"rate"`
	// Throughput is the rate of successful requests per second.
	Throughput float64 `json:"throughput"`
	// Success is the percentage of non-error responses.
	Success float64 `json:"success"`
	// StatusCodes is a histogram of the responses' status codes.
	StatusCodes map[string]int `json:"status_codes"`
	// Errors is a set of unique errors returned by the targets during the attack.
	Errors []string `json:"errors"`
}

Metrics wraps "vegeta.Metrics" to avoid dependency on it.

type Options

type Options struct {
	Rate        int
	Duration    time.Duration
	Timeout     time.Duration
	Method      string
	Body        []byte
	MaxBody     int64
	Header      http.Header
	Workers     uint64
	MaxWorkers  uint64
	KeepAlive   bool
	Connections int
	HTTP2       bool
	LocalAddr   net.IPAddr
	Buckets     []time.Duration
	Resolvers   []string

	InsecureSkipVerify bool
	CACertificatePool  *x509.CertPool
	TLSCertificates    []tls.Certificate

	Attacker backedAttacker
}

Options provides optional settings to attack.

Jump to

Keyboard shortcuts

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