forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a new metricset that reports the system uptime. The metricset is enabled by default with a period of 15m. The metricset reports one field `system.uptime.duration.ms` that is the system's uptime reported in milliseconds. In Kibana the field is formatted as a `duration` and shown in human-readable format (e.g. "8 days"). Closes elastic#4848
- Loading branch information
1 parent
e8f55ba
commit 5e514dc
Showing
16 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// | ||
This file is generated! See scripts/docs_collector.py | ||
//// | ||
|
||
[[metricbeat-metricset-system-uptime]] | ||
include::../../../module/system/uptime/_meta/docs.asciidoc[] | ||
|
||
|
||
==== Fields | ||
|
||
For a description of each field in the metricset, see the | ||
<<exported-fields-system,exported fields>> section. | ||
|
||
Here is an example document generated by this metricset: | ||
|
||
[source,json] | ||
---- | ||
include::../../../module/system/uptime/_meta/data.json[] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"@timestamp": "2016-05-23T08:05:34.853Z", | ||
"@metadata": { | ||
"beat": "noindex", | ||
"type": "doc" | ||
}, | ||
"system": { | ||
"uptime": { | ||
"duration": { | ||
"ms": 695499821 | ||
} | ||
} | ||
}, | ||
"metricset": { | ||
"module": "system", | ||
"name": "uptime", | ||
"rtt": 115 | ||
}, | ||
"beat": { | ||
"name": "host.example.com", | ||
"hostname": "host.example.com" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
=== System Uptime Metricset | ||
|
||
The System `uptime` metricset provides the uptime of the host operating system. | ||
|
||
This metricset is available on: | ||
|
||
- Darwin | ||
- Linux | ||
- OpenBSD | ||
- Windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
- name: uptime | ||
type: group | ||
description: > | ||
`uptime` contains the operating system uptime metric. | ||
fields: | ||
- name: duration.ms | ||
type: long | ||
format: duration | ||
input_format: milliseconds | ||
description: > | ||
The OS uptime in milliseconds. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package uptime reports the system's uptime. | ||
package uptime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// +build darwin linux openbsd windows | ||
|
||
package uptime | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/metricbeat/mb" | ||
"github.com/elastic/beats/metricbeat/mb/parse" | ||
sigar "github.com/elastic/gosigar" | ||
) | ||
|
||
func init() { | ||
if err := mb.Registry.AddMetricSet("system", "uptime", New, parse.EmptyHostParser); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// MetricSet for fetching an OS uptime metric. | ||
type MetricSet struct { | ||
mb.BaseMetricSet | ||
} | ||
|
||
// New is a mb.MetricSetFactory that returns a new MetricSet. | ||
func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | ||
return &MetricSet{base}, nil | ||
} | ||
|
||
// Fetch fetches the uptime metric from the OS. | ||
func (m *MetricSet) Fetch() (common.MapStr, error) { | ||
var uptime sigar.Uptime | ||
if err := uptime.Get(); err != nil { | ||
return nil, errors.Wrap(err, "failed to get uptime") | ||
} | ||
|
||
return common.MapStr{ | ||
"duration": common.MapStr{ | ||
"ms": int64(uptime.Length * 1000), | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// +build darwin linux openbsd windows | ||
|
||
package uptime | ||
|
||
import ( | ||
"testing" | ||
|
||
mbtest "github.com/elastic/beats/metricbeat/mb/testing" | ||
) | ||
|
||
func TestData(t *testing.T) { | ||
f := mbtest.NewEventFetcher(t, getConfig()) | ||
|
||
uptime, err := f.Fetch() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
event := mbtest.CreateFullEvent(f, uptime) | ||
mbtest.WriteEventToDataJSON(t, event) | ||
} | ||
|
||
func getConfig() map[string]interface{} { | ||
return map[string]interface{}{ | ||
"module": "system", | ||
"metricsets": []string{"uptime"}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters