rmetric

package
v0.0.0-...-976ba61 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package rmetric provides method to collect metrics of go runtime so it is called as rmetric (runtime metrics).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector struct {
	// CollectInterval represents the interval in-between each set of stats output.
	// Defaults to 10 seconds.
	CollectInterval 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 of go runtime to a RuntimeStatsHandler.

func New

func New(statsHandler RuntimeStatsHandler) *Collector

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

func (*Collector) Once

func (c *Collector) Once() RuntimeStats

Once 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 RuntimeStatsHandler every CollectInterval. Unlike Once, this function will return until Done has been closed (or never if Done is nil), therefore it should be called in its own goroutine.

type RuntimeStats

type RuntimeStats struct {
	// CPU
	NumCPU       int64 `json:"cpu.count"`
	NumThread    int64 `json:"cpu.threads"`
	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:"-"`
}

RuntimeStats represents metrics of go runtime.

func (*RuntimeStats) Tags

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

Tags return go arch.

func (*RuntimeStats) Values

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

Values returns metrics which you can write into TSDB.

type RuntimeStatsHandler

type RuntimeStatsHandler func(RuntimeStats)

RuntimeStatsHandler represents a handler to handle stats after successfully gathering statistics

Jump to

Keyboard shortcuts

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