Skip to content

Commit

Permalink
Add system uptime metricset
Browse files Browse the repository at this point in the history
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
andrewkroh committed Aug 11, 2017
1 parent e8f55ba commit 5e514dc
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta1...master[Check the HEAD di
- Add http server metricset to support push metrics via http. {pull}4770[4770]
- Make config object public for graphite and http server {pull}4820[4820]

- Add system uptime metricset. {issue}[4848[4848]

*Packetbeat*

*Winlogbeat*
Expand Down
5 changes: 5 additions & 0 deletions libbeat/scripts/generate_index_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def field_to_json(fields, desc, path, output,
if "format" in desc:
fieldFormat["id"] = desc["format"]

if "input_format" in desc:
fieldFormat["params"] = {
"inputFormat": desc["input_format"]
}

if "pattern" in desc:
fieldFormat["params"] = {
"pattern": desc["pattern"]
Expand Down
17 changes: 17 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10144,6 +10144,23 @@ type: keyword
Name of the user running the process.
[float]
== uptime fields
`uptime` contains the operating system uptime metric.
[float]
=== `system.uptime.duration.ms`
type: long
format: duration
The OS uptime in milliseconds.
[[exported-fields-vsphere]]
== vSphere fields
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/docs/modules/system.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ metricbeat.modules:
processors:
- drop_event.when.regexp:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'
- module: system
period: 15m
metricsets: [uptime]
----

[float]
Expand Down Expand Up @@ -138,6 +142,8 @@ The following metricsets are available:

* <<metricbeat-metricset-system-socket,socket>>

* <<metricbeat-metricset-system-uptime,uptime>>

include::system/core.asciidoc[]

include::system/cpu.asciidoc[]
Expand All @@ -160,3 +166,5 @@ include::system/process_summary.asciidoc[]

include::system/socket.asciidoc[]

include::system/uptime.asciidoc[]

19 changes: 19 additions & 0 deletions metricbeat/docs/modules/system/uptime.asciidoc
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[]
----
1 change: 1 addition & 0 deletions metricbeat/include/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import (
_ "github.com/elastic/beats/metricbeat/module/system/process"
_ "github.com/elastic/beats/metricbeat/module/system/process_summary"
_ "github.com/elastic/beats/metricbeat/module/system/socket"
_ "github.com/elastic/beats/metricbeat/module/system/uptime"
_ "github.com/elastic/beats/metricbeat/module/vsphere"
_ "github.com/elastic/beats/metricbeat/module/vsphere/datastore"
_ "github.com/elastic/beats/metricbeat/module/vsphere/host"
Expand Down
1 change: 1 addition & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ metricbeat.modules:
- network # Network IO
- process # Per process metrics
- process_summary # Process summary
- uptime # System Uptime
#- core # Per CPU core usage
#- diskio # Disk IO
#- socket # Sockets and connection info (linux only)
Expand Down
1 change: 1 addition & 0 deletions metricbeat/module/system/_meta/config.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- network # Network IO
- process # Per process metrics
- process_summary # Process summary
- uptime # System Uptime
#- core # Per CPU core usage
#- diskio # Disk IO
#- socket # Sockets and connection info (linux only)
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/system/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
processors:
- drop_event.when.regexp:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'

- module: system
period: 15m
metricsets: [uptime]
23 changes: 23 additions & 0 deletions metricbeat/module/system/uptime/_meta/data.json
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"
}
}
10 changes: 10 additions & 0 deletions metricbeat/module/system/uptime/_meta/docs.asciidoc
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
11 changes: 11 additions & 0 deletions metricbeat/module/system/uptime/_meta/fields.yml
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.
2 changes: 2 additions & 0 deletions metricbeat/module/system/uptime/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package uptime reports the system's uptime.
package uptime
42 changes: 42 additions & 0 deletions metricbeat/module/system/uptime/metricset.go
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
}
28 changes: 28 additions & 0 deletions metricbeat/module/system/uptime/metricset_test.go
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"},
}
}
4 changes: 4 additions & 0 deletions metricbeat/modules.d/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
processors:
- drop_event.when.regexp:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'

- module: system
period: 15m
metricsets: [uptime]

0 comments on commit 5e514dc

Please sign in to comment.