forked from premendrasingh/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
50 lines (40 loc) · 1.07 KB
/
info.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 info
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 = "info"
)
var (
debugf = logp.MakeDebug("haproxy-info")
)
// init registers the haproxy info MetricSet.
func init() {
if err := mb.Registry.AddMetricSet("haproxy", "info", New, haproxy.HostParser); err != nil {
panic(err)
}
}
// MetricSet for haproxy info.
type MetricSet struct {
mb.BaseMetricSet
}
// New creates a haproxy info MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
return &MetricSet{BaseMetricSet: base}, nil
}
// Fetch fetches info stats from the haproxy service.
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.GetInfo()
if err != nil {
return nil, errors.Wrap(err, "failed fetching haproxy info")
}
return eventMapping(res)
}