system

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package system provides method to collect metrics of machines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BandwidthStat

type BandwidthStat struct {
	BytesSent   uint64
	BytesRecv   uint64
	PacketsSent uint64
	PacketsRecv uint64
}

type Collector

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

	// 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 SystemStatsHandler.

func New

func New(statsHandler SystemStatsHandler) *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() SystemStats

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 SystemStatsHandler 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 DiskStat

type DiskStat struct {
	Total uint64
	Free  uint64
}

type SystemStats

type SystemStats struct {
	CPUStat struct {
		User   float64
		System float64
		Idle   float64
		Iowait float64
	}
	LoadStat struct {
		Load1  float64
		Load5  float64
		Load15 float64
	}
	MemStat struct {
		Total     uint64
		Available uint64
		Used      uint64
	}
	SwapMemStat struct {
		Total uint64
		Free  uint64
		Used  uint64
	}
	DiskStat      map[string]DiskStat
	BandwidthStat map[string]BandwidthStat
}

func (*SystemStats) Values

func (ss *SystemStats) Values() map[string]interface{}

Values returns metrics which you can write into TSDB.

type SystemStatsHandler

type SystemStatsHandler func(SystemStats)

SystemStatsHandler 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