stat

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: MIT Imports: 20 Imported by: 107

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWriteFailed = errors.New("submit failed")

ErrWriteFailed is an error that indicates failed to submit a StatReport.

Functions

func CpuUsage

func CpuUsage() int64

CpuUsage returns current cpu usage.

func DisableLog

func DisableLog()

DisableLog disables logs of stats.

func Report

func Report(msg string)

Report reports given message.

func SetReportWriter

func SetReportWriter(writer Writer)

SetReportWriter sets the report writer.

func SetReporter

func SetReporter(fn func(string))

SetReporter sets the given reporter.

Types

type Metrics

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

A Metrics is used to log and report stat reports.

func NewMetrics

func NewMetrics(name string) *Metrics

NewMetrics returns a Metrics.

func (*Metrics) Add

func (m *Metrics) Add(task Task)

Add adds task to m.

func (*Metrics) AddDrop

func (m *Metrics) AddDrop()

AddDrop adds a drop to m.

func (*Metrics) SetName

func (m *Metrics) SetName(name string)

SetName sets the name of m.

type RemoteWriter

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

A RemoteWriter is a writer to write StatReport.

func (*RemoteWriter) Write

func (rw *RemoteWriter) Write(report *StatReport) error

type StatReport

type StatReport struct {
	Name          string  `json:"name"`
	Timestamp     int64   `json:"tm"`
	Pid           int     `json:"pid"`
	ReqsPerSecond float32 `json:"qps"`
	Drops         int     `json:"drops"`
	Average       float32 `json:"avg"`
	Median        float32 `json:"med"`
	Top90th       float32 `json:"t90"`
	Top99th       float32 `json:"t99"`
	Top99p9th     float32 `json:"t99p9"`
}

A StatReport is a stat report entry.

type Task

type Task struct {
	Drop        bool
	Duration    time.Duration
	Description string
}

A Task is a task reported to Metrics.

type Writer

type Writer interface {
	Write(report *StatReport) error
}

Writer interface wraps the Write method.

func NewRemoteWriter

func NewRemoteWriter(endpoint string) Writer

NewRemoteWriter returns a RemoteWriter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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