host

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Timestamp     = "ts"
	HostName      = "host_name"
	LocalNetworks = "local_networks"
	OS            = "os"
	Load          = "load"
	KernelVersion = "kernel_version"
	Uptime        = "uptime"
)

Keys for use in NodeMetadata

View Source
const (
	ProcUptime = "/proc/uptime"
	ProcLoad   = "/proc/loadavg"
)

Exposed for testing

Variables

View Source
var (
	InterfaceAddrs = net.InterfaceAddrs
	Now            = func() string { return time.Now().UTC().Format(time.RFC3339Nano) }
)

Exposed for testing

View Source
var GetKernelVersion = func() (string, error) {
	out, err := exec.Command("uname", "-v").CombinedOutput()
	if err != nil {
		return "Darwin unknown", err
	}
	matches := unameRe.FindAllStringSubmatch(string(out), -1)
	if matches == nil || len(matches) < 1 || len(matches[0]) < 1 {
		return "Darwin unknown", nil
	}
	return fmt.Sprintf("Darwin %s", matches[0][1]), nil
}

GetKernelVersion returns the kernel version as reported by uname.

View Source
var GetLoad = func() string {
	out, err := exec.Command("w").CombinedOutput()
	if err != nil {
		return "unknown"
	}
	matches := loadRe.FindAllStringSubmatch(string(out), -1)
	if matches == nil || len(matches) < 1 || len(matches[0]) < 4 {
		return "unknown"
	}
	return fmt.Sprintf("%s %s %s", matches[0][1], matches[0][2], matches[0][3])
}

GetLoad returns the current load averages in standard form.

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 {
	// contains filtered or unexported fields
}

Reporter generates Reports containing the host topology.

func NewReporter

func NewReporter(hostID, hostName string) *Reporter

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

func (*Reporter) Report

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

Report implements 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) 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