This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metricbeat.go
91 lines (70 loc) · 1.83 KB
/
metricbeat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Metricbeat collects metric sets from different modules.
Each event created has the following format:
curl -XPUT http://localhost:9200/metricbeat/metricsets -d
{
"metriset": metricsetName,
"module": moduleName,
"moduleName-metricSetName": {
"metric1": "value",
"metric2": "value",
"metric3": "value",
"nestedmetric": {
"metric4": "value"
}
},
"@timestamp": timestamp
}
All documents are currently stored in one index called metricbeat. It is important to use an independent namespace
for each MetricSet to prevent type conflicts. Also all values are stored under the same type "metricsets".
*/
package beater
import (
"fmt"
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/helper"
)
type Metricbeat struct {
done chan struct{}
config *Config
}
// New creates and returns a new Metricbeat instance.
func New() *Metricbeat {
return &Metricbeat{}
}
func (mb *Metricbeat) Config(b *beat.Beat) error {
// List all registered modules and metricsets.
logp.Info("%s", helper.Registry.String())
mb.config = &Config{}
err := b.RawConfig.Unpack(mb.config)
if err != nil {
return fmt.Errorf("error reading configuration file. %v", err)
}
return nil
}
func (mb *Metricbeat) Setup(b *beat.Beat) error {
mb.done = make(chan struct{})
return nil
}
func (mb *Metricbeat) Run(b *beat.Beat) error {
// Checks all defined metricsets and starts a module for each entry with the defined metricsets
for _, moduleConfig := range mb.config.Metricbeat.Modules {
module, err := helper.Registry.GetModule(moduleConfig)
if err != nil {
return err
}
err = module.Start(b)
if err != nil {
return err
}
}
<-mb.done
return nil
}
func (mb *Metricbeat) Cleanup(b *beat.Beat) error {
return nil
}
func (mb *Metricbeat) Stop() {
close(mb.done)
}