Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not build internal metrics without CGO #6501

Merged
merged 3 commits into from
Mar 13, 2018
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di
- Remove double slashes in Windows service script. {pull}6491[6491]
- Fix infinite failure on Kubernetes watch {pull}6504[6504]
- Ensure Kubernetes labels/annotations don't break mapping {pull}6490[6490]
- Report ephemeral ID and uptime in monitoring events on all platforms {pull}6501[6501]

*Auditbeat*

Expand Down
33 changes: 6 additions & 27 deletions libbeat/cmd/instance/metrics.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
// +build darwin linux windows
// +build cgo
// +build darwin,cgo freebsd,cgo linux windows

package instance

import (
"fmt"
"os"
"runtime"
"time"

"github.com/satori/go.uuid"

"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/metric/system/cpu"
"github.com/elastic/beats/libbeat/metric/system/process"
"github.com/elastic/beats/libbeat/monitoring"
"github.com/elastic/beats/libbeat/monitoring/report/log"
)

var (
beatProcessStats *process.Stats
ephemeralID uuid.UUID
systemMetrics *monitoring.Registry
)

func init() {
beatMetrics := monitoring.Default.NewRegistry("beat")
systemMetrics = monitoring.Default.NewRegistry("system")
}

func setupMetrics(name string) error {
monitoring.NewFunc(beatMetrics, "memstats", reportMemStats, monitoring.Report)
monitoring.NewFunc(beatMetrics, "cpu", reportBeatCPU, monitoring.Report)
monitoring.NewFunc(beatMetrics, "info", reportInfo, monitoring.Report)

systemMetrics := monitoring.Default.NewRegistry("system")
monitoring.NewFunc(systemMetrics, "cpu", reportSystemCPUUsage, monitoring.Report)
if runtime.GOOS != "windows" {
monitoring.NewFunc(systemMetrics, "load", reportSystemLoadAverage, monitoring.Report)
}

ephemeralID = uuid.NewV4()
}

func setupMetrics(name string) error {
beatProcessStats = &process.Stats{
Procs: []string{name},
EnvWhitelist: nil,
Expand Down Expand Up @@ -91,19 +83,6 @@ func getRSSSize() (uint64, error) {
return rss, nil
}

func reportInfo(_ monitoring.Mode, V monitoring.Visitor) {
V.OnRegistryStart()
defer V.OnRegistryFinished()

delta := time.Since(log.StartTime)
uptime := int64(delta / time.Millisecond)
monitoring.ReportNamespace(V, "uptime", func() {
monitoring.ReportInt(V, "ms", uptime)
})

monitoring.ReportString(V, "ephemeral_id", ephemeralID.String())
}

func reportBeatCPU(_ monitoring.Mode, V monitoring.Visitor) {
V.OnRegistryStart()
defer V.OnRegistryFinished()
Expand Down
35 changes: 35 additions & 0 deletions libbeat/cmd/instance/metrics_common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package instance

import (
"time"

"github.com/satori/go.uuid"

"github.com/elastic/beats/libbeat/monitoring"
"github.com/elastic/beats/libbeat/monitoring/report/log"
)

var (
ephemeralID uuid.UUID
beatMetrics *monitoring.Registry
)

func init() {
beatMetrics = monitoring.Default.NewRegistry("beat")
monitoring.NewFunc(beatMetrics, "info", reportInfo, monitoring.Report)

ephemeralID = uuid.NewV4()
}

func reportInfo(_ monitoring.Mode, V monitoring.Visitor) {
V.OnRegistryStart()
defer V.OnRegistryFinished()

delta := time.Since(log.StartTime)
uptime := int64(delta / time.Millisecond)
monitoring.ReportNamespace(V, "uptime", func() {
monitoring.ReportInt(V, "ms", uptime)
})

monitoring.ReportString(V, "ephemeral_id", ephemeralID.String())
}
8 changes: 6 additions & 2 deletions libbeat/cmd/instance/metrics_other.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// +build !darwin,!linux,!windows darwin,!cgo linux,!cgo windows,!cgo
// +build !darwin !cgo
// +build !freebsd !cgo
// +build !linux,!windows

package instance

import "github.com/elastic/beats/libbeat/logp"
import (
"github.com/elastic/beats/libbeat/logp"
)

func setupMetrics(name string) error {
logp.Warn("Metrics not implemented for this OS.")
Expand Down