type MetricSet struct { mb.BaseMetricSet dataPath string }
// New creates a new instance of the MetricSet. New is responsible for unpacking // any MetricSet specific configuration options if there are any. func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // Unpack additional configuration options. config := struct { DataPath string `config:"dataPath"` }{ DataPath:"", }
func (m *MetricSet) Fetch(report mb.ReporterV2) { PthSep := string(os.PathSeparator) var dataPath = m.dataPath files, _ := ioutil.ReadDir(dataPath) for _, f := range files { if !f.IsDir() { continue } var path = dataPath+PthSep+f.Name() cfiles,_ := ioutil.ReadDir(path) var filesize = f.Size()
for _, cf := range cfiles { filesize = filesize + cf.Size() } var name = f.Name(); var index = strings.LastIndex(name,"-") if index <0 { continue } var topic = name[0:index] var partition = name[index+1:len(name)] debugf("topic:%v",f.Name()) report.Event(mb.Event{ MetricSetFields: common.MapStr{ "topic": topic, "partition": partition, "filesize": filesize, }, }) } }
// init registers the MetricSet with the central registry as soon as the program // starts. The New function will be called later to instantiate an instance of // the MetricSet for each host defined in the module's configuration. After the // MetricSet has been created then Fetch will begin to be called periodically. func init() { mb.Registry.MustAddMetricSet("kafka", "filesize", New) }
var debugf = logp.MakeDebug("kafka") // MetricSet holds any configuration or state information. It must implement // the mb.MetricSet interface. And this is best achieved by embedding // mb.BaseMetricSet because it implements all of the required mb.MetricSet // interface methods except for Fetch. type MetricSet struct { mb.BaseMetricSet dataPath string }
// New creates a new instance of the MetricSet. New is responsible for unpacking // any MetricSet specific configuration options if there are any. func New(base mb.BaseMetricSet) (mb.MetricSet, error) { // Unpack additional configuration options. config := struct { DataPath string `config:"dataPath"` }{ DataPath:"", }
// Fetch methods implements the data gathering and data conversion to the right // format. It publishes the event which is then forwarded to the output. In case // of an error set the Error field of mb.Event or simply call report.Error(). func (m *MetricSet) Fetch(report mb.ReporterV2) { PthSep := string(os.PathSeparator) var dataPath = m.dataPath files, _ := ioutil.ReadDir(dataPath) for _, f := range files { if !f.IsDir() { continue } var path = dataPath+PthSep+f.Name() cfiles,_ := ioutil.ReadDir(path) var filesize = f.Size()
for _, cf := range cfiles { filesize = filesize + cf.Size() } var name = f.Name(); var index = strings.LastIndex(name,"-") if index <0 { continue } var topic = name[0:index] var partition = name[index+1:len(name)] debugf("topic:%v",f.Name()) report.Event(mb.Event{ MetricSetFields: common.MapStr{ "topic": topic, "partition": partition, "filesize": filesize, }, }) } }