Skip to content

Commit

Permalink
Add freebsd build tags for Metricbeat system metricsets (elastic#1966)
Browse files Browse the repository at this point in the history
The MetricSets made available on FreeBSD by this change are core, cpu, filesystem, fsstat, memory, and process.

- Enable python system tests on FreeBSD.
- Remove cmdline from the required fields list in the python system tests for system/process events because cmdline may not be included for certain kernel level processes.
- Disable python filtering tests on OpenBSD because system/process is not implemented.
- Add build tags for the Golang tests in the system module.
  • Loading branch information
andrewkroh authored and ruflin committed Jul 6, 2016
1 parent b00a66a commit e412c00
Show file tree
Hide file tree
Showing 25 changed files with 114 additions and 24 deletions.
2 changes: 1 addition & 1 deletion metricbeat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ES_BEATS?=..
# Metricbeat can only be cross-compiled on platforms not requiring CGO which
# are the same platforms where the system metrics (cpu, memory) are not
# implemented.
GOX_OS=solaris freebsd netbsd
GOX_OS=solaris netbsd
GOX_FLAGS='-arch=amd64'

include ${ES_BEATS}/libbeat/scripts/Makefile
Expand Down
12 changes: 12 additions & 0 deletions metricbeat/docs/faq.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@
This section contains frequently asked questions about Metricbeat. Also check out the
https://discuss.elastic.co/c/beats/metricbeat[Metricbeat discussion forum].

=== How do I fix the `open /compat/linux/proc: no such file or directory` error on FreeBSD?

The system metricsets rely a Linux comparability layer to retrieve metrics on
FreeBSD. You need to mount the Linux procfs filesystem using the following
commands.

[source,sh]
----
sudo mkdir -p /compat/linux/proc
sudo mount -t linprocfs /dev/null /compat/linux/proc
----

include::../../libbeat/docs/shared-faq.asciidoc[]
1 change: 1 addition & 0 deletions metricbeat/module/system/common/process_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// +build !integration
// +build darwin freebsd linux windows

package common

Expand Down
7 changes: 7 additions & 0 deletions metricbeat/module/system/core/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
=== System Core Metricset

The System `core` metricset provides load statistics for each CPU core.

This metricset is available on:

- Darwin
- FreeBSD
- Linux
- OpenBSD
2 changes: 1 addition & 1 deletion metricbeat/module/system/core/core.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin linux openbsd windows
// +build darwin freebsd linux openbsd

package core

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/system/core/core_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// +build !integration
// +build darwin freebsd linux openbsd

package core

import (
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/system/cpu/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
=== System CPU Metricset

The System `cpu` metricset provides CPU statistics.

This metricset is available on:

- Darwin
- FreeBSD
- Linux
- OpenBSD
- Windows
2 changes: 1 addition & 1 deletion metricbeat/module/system/cpu/cpu.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin linux openbsd windows
// +build darwin freebsd linux openbsd windows

package cpu

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/system/cpu/cpu_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// +build !integration
// +build darwin freebsd linux openbsd windows

package cpu

import (
Expand Down
11 changes: 10 additions & 1 deletion metricbeat/module/system/filesystem/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
=== System Filesystem Metricset

The System `filesystem` metricset provides file system statistics. For each file system, one document is provided.
The System `filesystem` metricset provides file system statistics. For each file
system, one document is provided.

This metricset is available on:

- Darwin
- FreeBSD
- Linux
- OpenBSD
- Windows
2 changes: 1 addition & 1 deletion metricbeat/module/system/filesystem/filesystem.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin linux openbsd windows
// +build darwin freebsd linux openbsd windows

package filesystem

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/system/filesystem/filesystem_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// +build !integration
// +build darwin freebsd linux openbsd windows

package filesystem

import (
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/system/fsstat/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
=== System Fsstat Metricset

The System `fsstats` metricset provides overall file system statistics.

This metricset is available on:

- Darwin
- FreeBSD
- Linux
- OpenBSD
- Windows
2 changes: 1 addition & 1 deletion metricbeat/module/system/fsstat/fsstat.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin linux openbsd windows
// +build darwin freebsd linux openbsd windows

package fsstat

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/system/fsstat/fsstat_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// +build !integration
// +build darwin freebsd linux openbsd windows

package fsstat

import (
Expand Down
8 changes: 8 additions & 0 deletions metricbeat/module/system/memory/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
=== System Memory Metricset

The System `memory` metricset provides memory statistics.

This metricset is available on:

- Darwin
- FreeBSD
- Linux
- OpenBSD
- Windows
2 changes: 1 addition & 1 deletion metricbeat/module/system/memory/memory.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin linux openbsd windows
// +build darwin freebsd linux openbsd windows

package memory

Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/system/memory/memory_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// +build !integration
// +build darwin freebsd linux openbsd windows

package memory

import (
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/system/network/network_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// +build !integration
// +build darwin freebsd linux windows

package network

import (
Expand Down
10 changes: 9 additions & 1 deletion metricbeat/module/system/process/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
=== System Process Metricset

The System `process` metricset provides process statistics. One document is provided for each process.
The System `process` metricset provides process statistics. One document is
provided for each process.

This metricset is available on:

- Darwin
- FreeBSD
- Linux
- Windows
2 changes: 1 addition & 1 deletion metricbeat/module/system/process/process.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build darwin linux windows
// +build darwin freebsd linux windows

package process

Expand Down
5 changes: 4 additions & 1 deletion metricbeat/module/system/process/process_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// +build !integration
// +build darwin freebsd linux windows

package process

import (
Expand All @@ -11,7 +14,7 @@ import (
func TestData(t *testing.T) {
f := mbtest.NewEventsFetcher(t, getConfig())

// Do a first fetch to have precentages
// Do a first fetch to have percentages
f.Fetch()
time.Sleep(1 * time.Second)

Expand Down
2 changes: 1 addition & 1 deletion metricbeat/tests/system/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class Test(BaseTest):
@unittest.skipUnless(re.match("(?i)win|linux|darwin|openbsd", sys.platform), "os")
@unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd|openbsd", sys.platform), "os")
def test_start_stop(self):
"""
Metricbeat starts and stops without error.
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/tests/system/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import metricbeat
import unittest

@unittest.skipUnless(re.match("(?i)win|linux|darwin|openbsd", sys.platform), "os")
@unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd", sys.platform), "os")
class GlobalFiltering(metricbeat.BaseTest):

def test_drop_fields(self):
Expand Down
32 changes: 20 additions & 12 deletions metricbeat/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
SYSTEM_NETWORK_FIELDS = ["name", "out.bytes", "in.bytes", "out.packets",
"in.packets", "in.error", "out.error", "in.dropeed", "out.dropped"]

SYSTEM_PROCESS_FIELDS = ["cmdline", "cpu", "memory", "name", "pid", "ppid",
"state", "username"]
# cmdline is also part of the system process fields, but it may not be present
# for some kernel level processes.
SYSTEM_PROCESS_FIELDS = ["cpu", "memory", "name", "pid", "ppid", "state",
"username"]


class SystemTest(metricbeat.BaseTest):
@unittest.skipUnless(re.match("(?i)win|linux|darwin|openbsd", sys.platform), "os")
@unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd|openbsd", sys.platform), "os")
def test_cpu(self):
"""
Test cpu system output.
Expand All @@ -62,7 +64,7 @@ def test_cpu(self):
cpu = evt["system"]["cpu"]
self.assertItemsEqual(self.de_dot(SYSTEM_CPU_FIELDS), cpu.keys())

@unittest.skipUnless(re.match("(?i)win|linux|darwin|openbsd", sys.platform), "os")
@unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd|openbsd", sys.platform), "os")
def test_cpu_ticks_option(self):
"""
Test cpu_ticks configuration option.
Expand Down Expand Up @@ -91,7 +93,7 @@ def test_cpu_ticks_option(self):
cpuStats = evt["system"]["cpu"]
self.assertItemsEqual(self.de_dot(SYSTEM_CPU_FIELDS_ALL), cpuStats.keys())

@unittest.skipUnless(re.match("(?i)linux|darwin|openbsd", sys.platform), "os")
@unittest.skipUnless(re.match("(?i)linux|darwin|freebsd|openbsd", sys.platform), "os")
def test_core(self):
"""
Test core system output.
Expand All @@ -117,8 +119,8 @@ def test_core(self):
core = evt["system"]["core"]
self.assertItemsEqual(self.de_dot(SYSTEM_CORE_FIELDS), core.keys())

@unittest.skipUnless(re.match("(?i)linux|darwin|openbsd", sys.platform), "os")
def test_core(self):
@unittest.skipUnless(re.match("(?i)linux|darwin|freebsd|openbsd", sys.platform), "os")
def test_core_with_cpu_ticks(self):
"""
Test core system output.
"""
Expand Down Expand Up @@ -172,7 +174,7 @@ def test_diskio(self):
diskio = evt["system"]["diskio"]
self.assertItemsEqual(self.de_dot(SYSTEM_DISKIO_FIELDS), diskio.keys())

@unittest.skipUnless(re.match("(?i)win|linux|darwin|openbsd", sys.platform), "os")
@unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd|openbsd", sys.platform), "os")
def test_filesystem(self):
"""
Test system/filesystem output.
Expand All @@ -198,7 +200,7 @@ def test_filesystem(self):
filesystem = evt["system"]["filesystem"]
self.assertItemsEqual(self.de_dot(SYSTEM_FILESYSTEM_FIELDS), filesystem.keys())

@unittest.skipUnless(re.match("(?i)win|linux|darwin|openbsd", sys.platform), "os")
@unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd|openbsd", sys.platform), "os")
def test_fsstat(self):
"""
Test system/fsstat output.
Expand All @@ -224,7 +226,7 @@ def test_fsstat(self):
fsstat = evt["system"]["fsstat"]
self.assertItemsEqual(SYSTEM_FSSTAT_FIELDS, fsstat.keys())

@unittest.skipUnless(re.match("(?i)win|linux|darwin|openbsd", sys.platform), "os")
@unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd|openbsd", sys.platform), "os")
def test_memory(self):
"""
Test system memory output.
Expand Down Expand Up @@ -290,7 +292,7 @@ def test_network(self):
network = evt["system"]["network"]
self.assertItemsEqual(self.de_dot(SYSTEM_NETWORK_FIELDS), network.keys())

@unittest.skipUnless(re.match("(?i)win|linux|darwin", sys.platform), "os")
@unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd", sys.platform), "os")
def test_process(self):
"""
Test system/process output.
Expand All @@ -311,11 +313,18 @@ def test_process(self):
output = self.read_output_json()
self.assertGreater(len(output), 0)

found_cmdline = False
for evt in output:
self.assert_fields_are_documented(evt)
process = evt["system"]["process"]
cmdline = process.pop("cmdline", None)
if cmdline is not None:
found_cmdline = True
self.assertItemsEqual(SYSTEM_PROCESS_FIELDS, process.keys())

self.assertTrue(found_cmdline, "cmdline not found in any process events")

@unittest.skipUnless(re.match("(?i)win|linux|darwin|freebsd", sys.platform), "os")
def test_process_metricbeat(self):
"""
Checks that the per proc stats are found in the output and
Expand All @@ -340,7 +349,6 @@ def test_process_metricbeat(self):
assert isinstance(output["system.process.cpu.start_time"], basestring)
self.check_username(output["system.process.username"])


def check_username(self, observed, expected = None):
if expected == None:
expected = getpass.getuser()
Expand Down

0 comments on commit e412c00

Please sign in to comment.