host

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2015 License: Apache-2.0 Imports: 8 Imported by: 82

Documentation

Index

Constants

View Source
const (
	Timestamp     = "ts"
	HostName      = "host_name"
	LocalNetworks = "local_networks"
	OS            = "os"
	KernelVersion = "kernel_version"
	Uptime        = "uptime"
	Load1         = "load1"
	Load5         = "load5"
	Load15        = "load15"
)

Keys for use in Node.Metadata.

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

Exposed for testing.

Variables

View Source
var GetKernelVersion = func() (string, error) {
	var utsname syscall.Utsname
	if err := Uname(&utsname); err != nil {
		return "unknown", err
	}
	return fmt.Sprintf("%s %s", charsToString(utsname.Release), charsToString(utsname.Version)), nil
}

GetKernelVersion returns the kernel version as reported by uname.

View Source
var GetLoad = func() report.Metrics {
	buf, err := ioutil.ReadFile("/proc/loadavg")
	if err != nil {
		return nil
	}
	now := time.Now()
	toks := strings.Fields(string(buf))
	if len(toks) < 3 {
		return nil
	}
	one, err := strconv.ParseFloat(toks[0], 64)
	if err != nil {
		return nil
	}
	five, err := strconv.ParseFloat(toks[1], 64)
	if err != nil {
		return nil
	}
	fifteen, err := strconv.ParseFloat(toks[2], 64)
	if err != nil {
		return nil
	}
	return report.Metrics{
		Load1:  report.MakeMetric().Add(now, one),
		Load5:  report.MakeMetric().Add(now, five),
		Load15: report.MakeMetric().Add(now, fifteen),
	}
}

GetLoad returns the current load averages as metrics.

View Source
var GetUptime = func() (time.Duration, error) {
	buf, err := ioutil.ReadFile("/proc/uptime")
	if err != nil {
		return 0, err
	}

	fields := strings.Fields(string(buf))
	if len(fields) != 2 {
		return 0, fmt.Errorf("invalid format: %s", string(buf))
	}

	uptime, err := strconv.ParseFloat(fields[0], 64)
	if err != nil {
		return 0, err
	}

	return time.Duration(uptime) * time.Second, nil
}

GetUptime returns the uptime of the host.

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

Exposed for testing.

View Source
var Uname = syscall.Uname

Uname is swappable for mocking in tests.

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, localNets report.Networks) *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.

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, probeID 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