system

package
v0.0.0-...-6eee6bf Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package system ingests monitoring information from system

Index

Constants

This section is empty.

Variables

View Source
var MonitorProvider = stage.IngestProvider{
	StageType: "sysmon",
	Instantiator: func(cfg interface{}) *node.Init {
		log := logrus.WithField("stageType", "sysmon")
		interval, err := time.ParseDuration(cfg.(Monitor).Interval)
		if err != nil {
			log.WithField("interval", defaultInterval).Infof("using default interval")
			interval = defaultInterval
		}
		return node.AsInit(func(out chan<- map[string]interface{}) {
			ticker := time.NewTicker(interval)
			defer ticker.Stop()

			for {
				<-ticker.C
				stats := map[string]interface{}{}
				vmem, err := mem.VirtualMemory()
				if err != nil {
					log.WithError(err).Warn("can't fetch virtual memory. Skipping")
					continue
				}
				stats["memoryPercent"] = 100 * vmem.Available / vmem.Total
				scpu, err := cpu.Percent(0, true)
				if err != nil {
					log.WithError(err).Warn("can't fetch cpu stats. Skipping")
					continue
				}
				for i, sc := range scpu {
					stats[fmt.Sprintf("cpuPercent%d", i)] = sc
				}
				scpu, err = cpu.Percent(0, false)
				if err != nil {
					log.WithError(err).Warn("can't fetch cpu stats. Skipping")
					continue
				}
				stats["cpuPercentTotal"] = scpu[0]
				nios, err := net.IOCounters(false)
				if err != nil {
					log.WithError(err).Warn("can't fetch cpu stats. Skipping")
					continue
				}
				for _, nio := range nios {
					stats["netBytesSentPerSecond_"+nio.Name] = nio.BytesSent
					stats["netBytesRecvPerSecond_"+nio.Name] = nio.BytesRecv
				}
				out <- stats
			}
		})
	},
}

Functions

This section is empty.

Types

type Monitor

type Monitor struct {
	Name     string `hcl:",label"`
	Interval string `hcl:"interval,optional"`
}

Jump to

Keyboard shortcuts

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