forked from bigpigeon/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.go
50 lines (40 loc) · 1.09 KB
/
stat.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
package stat
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/haproxy"
"github.com/pkg/errors"
)
const (
statsMethod = "stat"
)
var (
debugf = logp.MakeDebug("haproxy-stat")
)
// init registers the haproxy stat MetricSet.
func init() {
if err := mb.Registry.AddMetricSet("haproxy", statsMethod, New, haproxy.HostParser); err != nil {
panic(err)
}
}
// MetricSet for haproxy stats.
type MetricSet struct {
mb.BaseMetricSet
}
// New creates a new haproxy stat MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return &MetricSet{BaseMetricSet: base}, nil
}
// Fetch methods returns a list of stats metrics.
func (m *MetricSet) Fetch() ([]common.MapStr, error) {
hapc, err := haproxy.NewHaproxyClient(m.HostData().URI)
if err != nil {
return nil, errors.Wrap(err, "failed creating haproxy client")
}
res, err := hapc.GetStat()
if err != nil {
return nil, errors.Wrap(err, "failed fetching haproxy stat")
}
return eventMapping(res), nil
}