host

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2017 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExecHost      = "host_exec"
	ResizeExecTTY = "host_resize_exec_tty"
)

Control IDs used by the host integration.

View Source
const (
	Timestamp     = "ts"
	HostName      = "host_name"
	LocalNetworks = "local_networks"
	OS            = "os"
	KernelVersion = "kernel_version"
	Uptime        = "uptime"
	Load1         = "load1"
	CPUUsage      = "host_cpu_usage_percent"
	MemoryUsage   = "host_mem_usage_bytes"
	ScopeVersion  = "host_scope_version"
)

Keys for use in Node.Latest.

View Source
const (
	ProcUptime  = "/proc/uptime"
	ProcLoad    = "/proc/loadavg"
	ProcStat    = "/proc/stat"
	ProcMemInfo = "/proc/meminfo"
)

Exposed for testing.

Variables

View Source
var (
	MetadataTemplates = report.MetadataTemplates{
		KernelVersion: {ID: KernelVersion, Label: "Kernel Version", From: report.FromLatest, Priority: 1},
		Uptime:        {ID: Uptime, Label: "Uptime", From: report.FromLatest, Priority: 2},
		HostName:      {ID: HostName, Label: "Hostname", From: report.FromLatest, Priority: 11},
		OS:            {ID: OS, Label: "OS", From: report.FromLatest, Priority: 12},
		LocalNetworks: {ID: LocalNetworks, Label: "Local Networks", From: report.FromSets, Priority: 13},
		ScopeVersion:  {ID: ScopeVersion, Label: "Scope Version", From: report.FromLatest, Priority: 14},
	}

	MetricTemplates = report.MetricTemplates{
		CPUUsage:    {ID: CPUUsage, Label: "CPU", Format: report.PercentFormat, Priority: 1},
		MemoryUsage: {ID: MemoryUsage, Label: "Memory", Format: report.FilesizeFormat, Priority: 2},
		Load1:       {ID: Load1, Label: "Load (1m)", Format: report.DefaultFormat, Group: "load", Priority: 11},
	}
)

Exposed for testing.

View Source
var GetCPUUsagePercent = func() (float64, float64) {
	return 0.0, 0.0
}

GetCPUUsagePercent returns the percent cpu usage and max (i.e. 100% or 0 if unavailable)

View Source
var GetKernelReleaseAndVersion = func() (string, string, error) {
	release, err := exec.Command("uname", "-r").CombinedOutput()
	if err != nil {
		return "unknown", "unknown", err
	}
	release = bytes.Trim(release, " \n")
	version, err := exec.Command("uname", "-v").CombinedOutput()
	if err != nil {
		return string(release), "unknown", err
	}
	version = bytes.Trim(version, " \n")
	return string(release), string(version), nil
}

GetKernelReleaseAndVersion returns the kernel version as reported by uname.

View Source
var GetLoad = func(now time.Time) report.Metrics {
	out, err := exec.Command("w").CombinedOutput()
	if err != nil {
		return nil
	}
	matches := loadRe.FindAllStringSubmatch(string(out), -1)
	if matches == nil || len(matches) < 1 || len(matches[0]) < 4 {
		return nil
	}

	one, err := strconv.ParseFloat(matches[0][1], 64)
	if err != nil {
		return nil
	}
	return report.Metrics{
		Load1: report.MakeSingletonMetric(now, one),
	}
}

GetLoad returns the current load averages as metrics.

View Source
var GetLocalNetworks = func() ([]*net.IPNet, error) {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return nil, err
	}
	localNets := report.Networks{}
	for _, addr := range addrs {

		if ipNet, ok := addr.(*net.IPNet); ok {
			localNets = append(localNets, ipNet)
		}
	}
	return localNets, nil
}

GetLocalNetworks is exported for mocking

View Source
var GetMemoryUsageBytes = func() (float64, float64) {
	return 0.0, 0.0
}

GetMemoryUsageBytes returns the bytes memory usage and max

View Source
var GetUptime = func() (time.Duration, error) {
	out, err := exec.Command("w").CombinedOutput()
	if err != nil {
		return 0, err
	}
	matches := uptimeRe.FindAllStringSubmatch(string(out), -1)
	if matches == nil || len(matches) < 1 || len(matches[0]) < 4 {
		return 0, err
	}
	d, err := strconv.Atoi(matches[0][1])
	if err != nil {
		return 0, err
	}
	h, err := strconv.Atoi(matches[0][2])
	if err != nil {
		return 0, err
	}
	m, err := strconv.Atoi(matches[0][3])
	if err != nil {
		return 0, err
	}
	return (time.Duration(d) * 24 * time.Hour) + (time.Duration(h) * time.Hour) + (time.Duration(m) * time.Minute), nil
}

GetUptime returns the uptime of the host.

Functions

This section is empty.

Types

type Reporter

type Reporter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Reporter generates Reports containing the host topology.

func NewReporter

func NewReporter(hostID, hostName, probeID, version string, pipes controls.PipeClient, handlerRegistry *controls.HandlerRegistry) *Reporter

NewReporter returns a Reporter which produces a report containing host topology for this host.

func (*Reporter) Name added in v0.10.0

func (*Reporter) Name() string

Name of this reporter, for metrics gathering

func (*Reporter) Report

func (r *Reporter) Report() (report.Report, error)

Report implements Reporter.

func (*Reporter) Stop added in v0.14.0

func (r *Reporter) Stop()

Stop stops the reporter.

type Tagger

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

Tagger tags each node in each topology of a report with the origin host node ID of this (probe) host. Effectively, a foreign key linking every node in every topology to an origin host node in the host topology.

func NewTagger

func NewTagger(hostID string) Tagger

NewTagger tags each node with a foreign key linking it to its origin host in the host topology.

func (Tagger) Name added in v0.10.0

func (Tagger) Name() string

Name of this tagger, for metrics gathering

func (Tagger) Tag

func (t Tagger) Tag(r report.Report) (report.Report, error)

Tag implements Tagger.

Jump to

Keyboard shortcuts

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