ustress

package
v0.0.0-...-d94da1c Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ChannelTimeout = 5

ChannelTimeout is a last resort method of killing goroutines

View Source
const (
	// HTTPfolder - the folder where the reports will be dumped
	HTTPfolder = "./data/" // Would be nice to generate absolute path via code || gopath
)

Variables

View Source
var (
	InvalidOptionType = errors.New("Invalid option value has been given")
	InvalidOptionName = errors.New("Option with that name does not exist")
)
View Source
var (
	Tr = &http.Transport{}
)

Functions

func Attack

func Attack(cfg *StressConfig) chan WorkerData

Attack main API for probing URL

func NewFile

func NewFile(filename string) *os.File

NewFile returns a new file to write data to

func SaveFileReport

func SaveFileReport(r *Report)

SaveFileReport it will save the report as json on local storage

func Worker

func Worker(
	thread int,
	request <-chan WorkerData,
	response chan<- WorkerData,
	group *sync.WaitGroup,
)

Worker is a goroutine that receives from request channel configuration for probing URL and sends its response via response chan

Types

type Headers

type Headers map[string]string

Headers map

type Option

type Option func(*StressConfig) error

func NewOption

func NewOption(name string, val interface{}) Option

type OutputSaver

type OutputSaver func(*Report) error

OutputSaver is a callback with report data

type Report

type Report struct {
	UUID      uuid.UUID     `json:"uuid"`
	TimeStamp time.Time     `json:"timestamp"`
	Config    *StressConfig `json:"config"`
	Stats     Stats         `json:"stats"`
	Duration  float64       `json:"durationTotal"`
	Data      []WorkerData  `json:"data"`
	Completed bool          `json:"completed"`
}

Report structure

func NewReport

func NewReport(cfg *StressConfig, saveFunc OutputSaver, tickerSave int) (*Report, error)

NewReport probes an endpoint and generates a new report saveFunc will be called every [tickerSave]ms meant for handling the report in real time

func (*Report) CalcStats

func (report *Report) CalcStats() *Report

func (*Report) JSON

func (r *Report) JSON() []byte

type Stats

type Stats struct {
	Median          float64     `json:"median"`
	PercentileA     float64     `json:"50_percentile"`
	PercentileB     float64     `json:"75_percentile"`
	PercentileC     float64     `json:"95_percentile"`
	PercentileD     float64     `json:"99_percentile"`
	ErrorPercentage float64     `json:"error_percentage"`
	CodesCount      map[int]int `json:"codes_count"`
}

Stats Structure

type StressConfig

type StressConfig struct {
	// URL to probe
	URL    string `json:"url"`
	Method string `json:"method"`
	// Number of request to be sent to the victim
	Requests int `json:"requests"`

	// Ho many treads to be used (dependent on the image resources)
	Threads int `json:"threads"`
	// similar to curl --resolve Force resolve of HOST:PORT to ADDRESS
	Resolve string `json:"resolve"`
	// insecure
	Insecure bool `json:"insecure"`

	// payload
	Payload string `json:"payload"`

	// Headers
	Headers Headers `json:"headers"`

	Duration  int `json:"duration"`  // Minutes
	Frequency int `json:"frequency"` // Miliseconds

	// If each worker should capture response
	WithResponse bool `json:"withResponse"`
	// contains filtered or unexported fields
}

MonkeyConfig structure

func NewStressConfig

func NewStressConfig(opts ...Option) (*StressConfig, error)

func (*StressConfig) StopAttack

func (s *StressConfig) StopAttack()

func (*StressConfig) ValidateConfig

func (cfg *StressConfig) ValidateConfig() error

ValidateConfig ...

type WorkerData

type WorkerData struct {
	Request      int           `json:"request"`
	Status       int           `json:"status"` // json:"status,omitempty"
	Thread       int           `json:"thread"`
	Duration     float64       `json:"duration"`
	Error        string        `json:"error"` //`json:"error,omitempty"`
	ResponseBody string        `json:"response"`
	StressConfig *StressConfig `json:"-"` // monkey cfg
}

WorkerData structure is used to track worker work

Jump to

Keyboard shortcuts

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