Skip to content

Commit

Permalink
Adds a "type" field to the filesystem beat (elastic#4717) (elastic#4717)
Browse files Browse the repository at this point in the history
Its value is copied from sigar.FileSystem.SysTypeName (on Windows, sigar.FileSystem.TypeName) and passed through so that it becomes possible to filter out `overlay`, `tmpfs` or otherwise uninteresting filesystems.

Fixes elastic#3459.
  • Loading branch information
cv authored and andrewkroh committed Aug 2, 2017
1 parent 50b0e4f commit 7e2396a
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha2...v6.0.0-beta1[View commi
with the system process metricset. The documentation for these metrics already
stated that on multi-core systems the percentages could be greater than 100%. {pull}4544[4544]
- Remove filters setting from metricbeat modules. {pull}4699[4699]
- Added `type` field to filesystem metrics. {pull}4717[4717]
*Packetbeat*
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8797,6 +8797,14 @@ type: keyword
The disk name. For example: `/dev/disk1`
[float]
=== `system.filesystem.type`
type: keyword
The disk type. For example: `ext4`
[float]
=== `system.filesystem.mount_point`
Expand Down
28 changes: 16 additions & 12 deletions metricbeat/module/system/filesystem/_meta/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
"hostname": "host.example.com",
"name": "host.example.com"
},
"@metadata": {
"beat": "noindex",
"type": "doc"
},
"metricset": {
"module": "system",
"name": "filesystem",
"rtt": 115
},
"system": {
"filesystem": {
"available": 38688276480,
"device_name": "none",
"files": 3940352,
"free": 41930997760,
"free_files": 3276976,
"available": 105569656832,
"device_name": "/dev/disk1",
"type": "hfs",
"files": 4294967279
"free": 105831800832,
"free_files": 4292793781,
"mount_point": "/",
"total": 63371726848,
"total": 249779191808,
"used": {
"bytes": 21440729088,
"pct": 0.3383
}
"bytes": 143947390976,
"pct": 0.5763
},
}
},
"type": "metricsets"
}
}
}
4 changes: 3 additions & 1 deletion metricbeat/module/system/filesystem/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ This metricset is available on:

Often there are mounted filesystems that you do not want Metricbeat to report
metrics on. A simple strategy to deal with these filesystems is to configure a
drop_event filter that matches the `mount_point` using a regular expression.
drop_event filter that matches the `mount_point` or `type` using a regular
expression.

Below is an example.

[source,yaml]
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/system/filesystem/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
type: keyword
description: >
The disk name. For example: `/dev/disk1`
- name: type
type: keyword
description: >
The disk type. For example: `ext4`
- name: mount_point
type: keyword
description: >
Expand Down
52 changes: 29 additions & 23 deletions metricbeat/module/system/filesystem/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,36 @@ for each of the mounted file systems.
An example event looks as following:
{
"@timestamp": "2016-05-25T20:51:36.813Z",
"beat": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"metricset": {
"module": "system",
"name": "filesystem",
"rtt": 55
},
"system": {
"filesystem": {
"avail": 13838553088,
"device_name": "/dev/disk1",
"files": 60981246,
"free": 14100697088,
"free_files": 3378553,
"mount_point": "/",
"total": 249779191808,
"used": 235678494720,
"used_p": 0.9435
"@timestamp": "2016-05-23T08:05:34.853Z",
"beat": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"@metadata": {
"beat": "noindex",
"type": "doc"
},
"metricset": {
"module": "system",
"name": "filesystem",
"rtt": 115
},
"system": {
"filesystem": {
"available": 105569656832,
"device_name": "/dev/disk1",
"type": "hfs",
"files": 4294967279
"free": 105831800832,
"free_files": 4292793781,
"mount_point": "/",
"total": 249779191808,
"used": {
"bytes": 143947390976,
"pct": 0.5763
},
}
}
},
"type": "metricsets"
}
*/
Expand Down
12 changes: 12 additions & 0 deletions metricbeat/module/system/filesystem/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"path/filepath"
"time"

"runtime"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/metricbeat/module/system"
sigar "github.com/elastic/gosigar"
Expand All @@ -16,6 +18,7 @@ type FileSystemStat struct {
DevName string `json:"device_name"`
Mount string `json:"mount_point"`
UsedPercent float64 `json:"used_p"`
SysTypeName string `json:"type"`
ctime time.Time
}

Expand Down Expand Up @@ -46,10 +49,18 @@ func GetFileSystemStat(fs sigar.FileSystem) (*FileSystemStat, error) {
return nil, err
}

var t string
if runtime.GOOS == "windows" {
t = fs.TypeName
} else {
t = fs.SysTypeName
}

filesystem := FileSystemStat{
FileSystemUsage: stat,
DevName: fs.DevName,
Mount: fs.DirName,
SysTypeName: t,
}

return &filesystem, nil
Expand All @@ -66,6 +77,7 @@ func AddFileSystemUsedPercentage(f *FileSystemStat) {

func GetFilesystemEvent(fsStat *FileSystemStat) common.MapStr {
return common.MapStr{
"type": fsStat.SysTypeName,
"device_name": fsStat.DevName,
"mount_point": fsStat.Mount,
"total": fsStat.Total,
Expand Down
4 changes: 4 additions & 0 deletions metricbeat/module/system/filesystem/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func TestFileSystemList(t *testing.T) {
assert.True(t, (stat.Free >= 0))
assert.True(t, (stat.Avail >= 0))
assert.True(t, (stat.Used >= 0))

if runtime.GOOS != "windows" {
assert.NotEqual(t, "", stat.SysTypeName)
}
}
}
}
2 changes: 1 addition & 1 deletion metricbeat/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
SYSTEM_DISKIO_FIELDS = ["name", "read.count", "write.count", "read.bytes",
"write.bytes", "read.time", "write.time", "io.time"]

SYSTEM_FILESYSTEM_FIELDS = ["available", "device_name", "files", "free",
SYSTEM_FILESYSTEM_FIELDS = ["available", "device_name", "type", "files", "free",
"free_files", "mount_point", "total", "used.bytes",
"used.pct"]

Expand Down

0 comments on commit 7e2396a

Please sign in to comment.