Skip to content

Commit

Permalink
[Metricbeat] Migrate mysql/galera_status to ReporterV2 (elastic#11324)
Browse files Browse the repository at this point in the history
* Migrate mysql/galera_status to ReporterV2
  • Loading branch information
fearful-symmetry authored Mar 21, 2019
1 parent 495eb58 commit 5a83876
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions metricbeat/module/mysql/galera_status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@ package galera_status
import (
"database/sql"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/common/cfgwarn"
"github.com/elastic/beats/metricbeat/mb"
"github.com/elastic/beats/metricbeat/module/mysql"

"github.com/pkg/errors"
)

var (
debugf = logp.MakeDebug("mysql-galera-status")
)

// init registers the MetricSet with the central registry.
func init() {
mb.Registry.MustAddMetricSet("mysql", "galera_status", New,
Expand All @@ -55,31 +50,37 @@ type MetricSet struct {
// New create a new instance of the MetricSet
// Loads query_mode config setting from the config file
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
cfgwarn.Experimental("The galera_status metricset is experimental.")
return &MetricSet{BaseMetricSet: base}, nil
}

// Fetch methods implements the data gathering and data conversion to the right format
// It returns the event which is then forward to the output.
func (m *MetricSet) Fetch() (common.MapStr, error) {
func (m *MetricSet) Fetch(reporter mb.ReporterV2) error {
if m.db == nil {
var err error
m.db, err = mysql.NewDB(m.HostData().URI)
if err != nil {
return nil, errors.Wrap(err, "Galera-status fetch failed")
return errors.Wrap(err, "Galera-status fetch failed")
}
}

status, err := m.loadStatus(m.db)
if err != nil {
return nil, err
return err
}

event := eventMapping(status)

if m.Module().Config().Raw {
event["raw"] = rawEventMapping(status)
}
return event, nil

reporter.Event(mb.Event{
MetricSetFields: event,
})

return nil
}

// loadStatus loads all status entries from the given database into an array.
Expand Down

0 comments on commit 5a83876

Please sign in to comment.