-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add munin module, with node metricset that obtain metrics from a running munin node using the same protocol used by munin masters.
- Loading branch information
Showing
22 changed files
with
522 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//// | ||
This file is generated! See scripts/docs_collector.py | ||
//// | ||
|
||
[[metricbeat-module-munin]] | ||
== Munin module | ||
|
||
experimental[] | ||
|
||
== munin module | ||
|
||
This is the munin module. | ||
|
||
|
||
|
||
[float] | ||
=== Example configuration | ||
|
||
The Munin module supports the standard configuration options that are described | ||
in <<configuration-metricbeat>>. Here is an example configuration: | ||
|
||
[source,yaml] | ||
---- | ||
metricbeat.modules: | ||
- module: munin | ||
metricsets: ["node"] | ||
enabled: false | ||
period: 10s | ||
hosts: ["localhost:4949"] | ||
node.namespace: node | ||
---- | ||
|
||
[float] | ||
=== Metricsets | ||
|
||
The following metricsets are available: | ||
|
||
* <<metricbeat-metricset-munin-node,node>> | ||
|
||
include::munin/node.asciidoc[] | ||
|
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,17 @@ | ||
//// | ||
This file is generated! See scripts/docs_collector.py | ||
//// | ||
|
||
[[metricbeat-metricset-munin-node]] | ||
=== Munin node metricset | ||
|
||
experimental[] | ||
|
||
include::../../../module/munin/node/_meta/docs.asciidoc[] | ||
|
||
|
||
==== Fields | ||
|
||
For a description of each field in the metricset, see the | ||
<<exported-fields-munin,exported fields>> section. | ||
|
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,13 @@ | ||
FROM ubuntu:16.04 | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y munin-node netcat && \ | ||
apt-get clean && rm rm -rf /var/lib/apt/lists/* | ||
|
||
EXPOSE 4949 | ||
|
||
COPY munin-node.conf /etc/munin/munin-node.conf | ||
|
||
HEALTHCHECK --interval=1s --retries=90 CMD nc -z 127.0.0.1 4949 | ||
|
||
CMD munin-node |
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,6 @@ | ||
- module: munin | ||
metricsets: ["node"] | ||
enabled: false | ||
period: 10s | ||
hosts: ["localhost:4949"] | ||
node.namespace: node |
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,4 @@ | ||
== munin module | ||
|
||
This is the munin module. | ||
|
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 @@ | ||
MUNIN_HOST=munin | ||
MUNIN_PORT=4949 |
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,13 @@ | ||
- key: munin | ||
title: "Munin" | ||
description: > | ||
experimental[] | ||
Munin node metrics exporter | ||
release: experimental | ||
fields: | ||
- name: munin | ||
type: group | ||
description: > | ||
munin contains metrics exposed by a munin node agent | ||
fields: |
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,15 @@ | ||
setsid 0 | ||
|
||
ignore_file [\#~]$ | ||
ignore_file DEADJOE$ | ||
ignore_file \.bak$ | ||
ignore_file %$ | ||
ignore_file \.dpkg-(tmp|new|old|dist)$ | ||
ignore_file \.rpm(save|new)$ | ||
ignore_file \.pod$ | ||
|
||
allow .* | ||
|
||
host 0.0.0.0 | ||
|
||
port 4949 |
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 munin is a Metricbeat module that contains MetricSets. | ||
package munin |
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,115 @@ | ||
package munin | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"net" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/joeshaw/multierror" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
) | ||
|
||
const ( | ||
unknownValue = "U" | ||
) | ||
|
||
// Node connection | ||
type Node struct { | ||
conn net.Conn | ||
|
||
writer io.Writer | ||
reader *bufio.Reader | ||
} | ||
|
||
// Connect with a munin node | ||
func Connect(address string, timeout time.Duration) (*Node, error) { | ||
conn, err := net.DialTimeout("tcp", address, timeout) | ||
if err != nil { | ||
return nil, err | ||
} | ||
n := &Node{conn: conn, | ||
writer: conn, | ||
reader: bufio.NewReader(conn), | ||
} | ||
// Cosume and ignore first line returned by munin, it is a comment | ||
// about the node | ||
scanner := bufio.NewScanner(n.reader) | ||
scanner.Scan() | ||
return n, scanner.Err() | ||
} | ||
|
||
// Close node connection relasing its resources | ||
func (n *Node) Close() error { | ||
return n.conn.Close() | ||
} | ||
|
||
// List of items exposed by the node | ||
func (n *Node) List() ([]string, error) { | ||
_, err := io.WriteString(n.writer, "list\n") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
scanner := bufio.NewScanner(n.reader) | ||
scanner.Scan() | ||
return strings.Fields(scanner.Text()), scanner.Err() | ||
} | ||
|
||
// Fetch metrics from munin node | ||
func (n *Node) Fetch(items ...string) (common.MapStr, error) { | ||
var errs multierror.Errors | ||
event := common.MapStr{} | ||
|
||
for _, item := range items { | ||
_, err := io.WriteString(n.writer, "fetch "+item+"\n") | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
|
||
scanner := bufio.NewScanner(n.reader) | ||
scanner.Split(bufio.ScanWords) | ||
for scanner.Scan() { | ||
name := strings.TrimSpace(scanner.Text()) | ||
|
||
// Munin delimites metrics with a dot | ||
if name == "." { | ||
break | ||
} | ||
|
||
name = strings.TrimSuffix(name, ".value") | ||
|
||
if !scanner.Scan() { | ||
if scanner.Err() == nil { | ||
errs = append(errs, errors.New("unexpected EOF when expecting value")) | ||
} | ||
break | ||
} | ||
value := scanner.Text() | ||
|
||
key := fmt.Sprintf("%s.%s", item, name) | ||
|
||
if value == unknownValue { | ||
errs = append(errs, errors.Errorf("unknown value for %s", key)) | ||
continue | ||
} | ||
if f, err := strconv.ParseFloat(value, 64); err == nil { | ||
event.Put(key, f) | ||
continue | ||
} | ||
event.Put(key, value) | ||
} | ||
|
||
if scanner.Err() != nil { | ||
errs = append(errs, scanner.Err()) | ||
} | ||
} | ||
|
||
return event, errs.Err() | ||
} |
Oops, something went wrong.