Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions instrumentation/host/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,45 @@
//
// The metric events produced are listed here with attribute dimensions.
//
// Name Attribute
// Name Attribute
//
// ----------------------------------------------------------------------
//
// process.cpu.time state=user|system
// system.cpu.time state=user|system|other|idle
// system.memory.usage state=used|available
// system.memory.utilization state=used|available
// system.network.io direction=transmit|receive
// process.cpu.time state=user|system
// system.cpu.time state=user|system|other|idle
// system.memory.usage state=used|available
// system.memory.utilization state=used|available
// system.network.io direction=transmit|receive
//
// Linux-specific Pressure Stall Information (PSI) metrics:
//
// system.psi.cpu.some.avg10 (no attributes)
// system.psi.cpu.some.avg60 (no attributes)
// system.psi.cpu.some.avg300 (no attributes)
// system.psi.cpu.some.total (no attributes)
// system.psi.memory.some.avg10 (no attributes)
// system.psi.memory.some.avg60 (no attributes)
// system.psi.memory.some.avg300 (no attributes)
// system.psi.memory.some.total (no attributes)
// system.psi.memory.full.avg10 (no attributes)
// system.psi.memory.full.avg60 (no attributes)
// system.psi.memory.full.avg300 (no attributes)
// system.psi.memory.full.total (no attributes)
// system.psi.io.some.avg10 (no attributes)
// system.psi.io.some.avg60 (no attributes)
// system.psi.io.some.avg300 (no attributes)
// system.psi.io.some.total (no attributes)
// system.psi.io.full.avg10 (no attributes)
// system.psi.io.full.avg60 (no attributes)
// system.psi.io.full.avg300 (no attributes)
// system.psi.io.full.total (no attributes)
//
// PSI metrics are only available on Linux systems with kernel 4.20+.
// "some" indicates that some tasks are stalled, "full" indicates all tasks are stalled.
// The avg* metrics represent pressure averages over 10, 60, and 300 second windows.
// The total metrics represent cumulative stall time in microseconds.
//
// See https://github.com/open-telemetry/oteps/blob/main/text/0119-standard-system-metrics.md
// for the definition of these metric instruments.
// For PSI metrics, see https://docs.kernel.org/accounting/psi.html
package host // import "go.opentelemetry.io/contrib/instrumentation/host"
6 changes: 6 additions & 0 deletions instrumentation/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const ScopeName = "go.opentelemetry.io/contrib/instrumentation/host"
type host struct {
config config
meter metric.Meter
psi *psiMetrics
}

// config contains optional settings for reporting host metrics.
Expand Down Expand Up @@ -195,6 +196,11 @@ func (h *host) register() error {
return err
}

// Register PSI metrics (Linux only)
if h.psi, err = h.registerPSI(); err != nil {
return err
}

_, err = h.meter.RegisterCallback(
func(ctx context.Context, o metric.Observer) error {
lock.Lock()
Expand Down
18 changes: 17 additions & 1 deletion instrumentation/host/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package host_test

import (
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -125,5 +126,20 @@ func TestHostMetrics(t *testing.T) {
},
},
}
metricdatatest.AssertEqual(t, want, rm.ScopeMetrics[0], metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreValue())

baseMetrics := rm.ScopeMetrics[0]
filteredMetrics := metricdata.ScopeMetrics{
Scope: baseMetrics.Scope,
Metrics: []metricdata.Metrics{},
}

for _, m := range baseMetrics.Metrics {
// Skip PSI metrics in this test - we test those separately
if strings.HasPrefix(m.Name, "system.psi.") {
continue
}
filteredMetrics.Metrics = append(filteredMetrics.Metrics, m)
}

metricdatatest.AssertEqual(t, want, filteredMetrics, metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreValue())
}
Loading