collector

package
v0.0.0-...-e4f994d Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector struct {
	// PauseDur represents the interval in-between each set of stats output.
	// Defaults to 10 seconds.
	PauseDur time.Duration

	// EnableCPU determines whether CPU statistics will be output. Defaults to true.
	EnableCPU bool

	// EnableMem determines whether memory statistics will be output. Defaults to true.
	EnableMem bool

	// EnableGC determines whether garbage collection statistics will be output. EnableMem
	// must also be set to true for this to take affect. Defaults to true.
	EnableGC bool

	// Done, when closed, is used to signal Collector that is should stop collecting
	// statistics and the Run function should return.
	Done <-chan struct{}
	// contains filtered or unexported fields
}

Collector implements the periodic grabbing of informational data from the runtime package and outputting the values to a GaugeFunc.

func New

func New(fieldsFunc FieldsFunc) *Collector

New creates a new Collector that will periodically output statistics to fieldsFunc. It will also set the values of the exported fields to the described defaults. The values of the exported defaults can be changed at any point before Run is called.

func (*Collector) OneOff

func (c *Collector) OneOff() Fields

OneOff gathers returns a map containing all statistics. It is safe for use from multiple go routines

func (*Collector) Run

func (c *Collector) Run()

Run gathers statistics then outputs them to the configured PointFunc every PauseDur. Unlike OneOff, this function will return until Done has been closed (or never if Done is nil), therefore it should be called in its own go routine.

type Fields

type Fields struct {
	// CPU
	NumCpu       int64 `json:"cpu.count"`
	NumGoroutine int64 `json:"cpu.goroutines"`
	NumCgoCall   int64 `json:"cpu.cgo_calls"`

	// General
	Alloc      int64 `json:"mem.alloc"`
	TotalAlloc int64 `json:"mem.total"`
	Sys        int64 `json:"mem.sys"`
	Lookups    int64 `json:"mem.lookups"`
	Mallocs    int64 `json:"mem.malloc"`
	Frees      int64 `json:"mem.frees"`

	// Heap
	HeapAlloc    int64 `json:"mem.heap.alloc"`
	HeapSys      int64 `json:"mem.heap.sys"`
	HeapIdle     int64 `json:"mem.heap.idle"`
	HeapInuse    int64 `json:"mem.heap.inuse"`
	HeapReleased int64 `json:"mem.heap.released"`
	HeapObjects  int64 `json:"mem.heap.objects"`

	// Stack
	StackInuse  int64 `json:"mem.stack.inuse"`
	StackSys    int64 `json:"mem.stack.sys"`
	MSpanInuse  int64 `json:"mem.stack.mspan_inuse"`
	MSpanSys    int64 `json:"mem.stack.mspan_sys"`
	MCacheInuse int64 `json:"mem.stack.mcache_inuse"`
	MCacheSys   int64 `json:"mem.stack.mcache_sys"`

	OtherSys int64 `json:"mem.othersys"`

	// GC
	GCSys         int64   `json:"mem.gc.sys"`
	NextGC        int64   `json:"mem.gc.next"`
	LastGC        int64   `json:"mem.gc.last"`
	PauseTotalNs  int64   `json:"mem.gc.pause_total"`
	PauseNs       int64   `json:"mem.gc.pause"`
	NumGC         int64   `json:"mem.gc.count"`
	GCCPUFraction float64 `json:"mem.gc.cpu_fraction"`

	Goarch  string `json:"-"`
	Goos    string `json:"-"`
	Version string `json:"-"`

	Timestamp int64 `json:"timestamp"`
}

NOTE: uint64 is not supported by influxDB client due to potential overflows

func (*Fields) Tags

func (f *Fields) Tags() map[string]string

func (*Fields) Values

func (f *Fields) Values() map[string]interface{}

type FieldsFunc

type FieldsFunc func(Fields)

FieldsFunc represents a callback after successfully gathering statistics

Jump to

Keyboard shortcuts

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