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

Add system uptime metricset #4887

Merged
merged 3 commits into from
Aug 14, 2017
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
3 changes: 2 additions & 1 deletion CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta1...master[Check the HEAD di
- Add graphite protocol metricbeat module. {pull}4734[4734]
- 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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

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
9 changes: 9 additions & 0 deletions metricbeat/docs/modules/system.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ 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 +143,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 +167,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
5 changes: 5 additions & 0 deletions metricbeat/module/system/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewkroh was there any reason to exclude freebsd here? sigar has the implementation for this. // cc @kaiyan-sheng @ruflin

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can’t think of any reason. It probably should be tagged as freebsd,cgo.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, what is the difference between freebsd & freebsd,cgo tags?


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"},
}
}
5 changes: 5 additions & 0 deletions metricbeat/modules.d/system.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@
processors:
- drop_event.when.regexp:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib)($|/)'

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