<commit_before>package collector

import (
	"fullerite/config"
	"fullerite/metric"

	l "github.com/Sirupsen/logrus"
)

const (
	// DefaultCollectionInterval the interval to collect on unless overridden by a collectors config
	DefaultCollectionInterval = 10
	// CPUInfoCollectionInterval default collection interval for the CPUInfo collector
	CPUInfoCollectionInterval = 3600
)

var defaultLog = l.WithFields(l.Fields{"app": "fullerite", "pkg": "collector"})

// Collector defines the interface of a generic collector.
type Collector interface {
	Collect()
	Configure(map[string]interface{})

	// taken care of by the base class
	Name() string
	Channel() chan metric.Metric
	Interval() int
	SetInterval(int)
}

// New creates a new Collector based on the requested collector name.
func New(name string) Collector {
	var collector Collector

	channel := make(chan metric.Metric)
	collectorLog := defaultLog.WithFields(l.Fields{"collector": name})

	switch name {
	case "Test":
		collector = NewTest(channel, DefaultCollectionInterval, collectorLog)
	case "Diamond":
		collector = NewDiamond(channel, DefaultCollectionInterval, collectorLog)
	case "Fullerite":
		collector = NewFullerite(channel, DefaultCollectionInterval, collectorLog)
	case "ProcStatus":
		collector = NewProcStatus(channel, DefaultCollectionInterval, collectorLog)
	case "FulleriteHTTP":
		collector = newFulleriteHTTPCollector(channel, DefaultCollectionInterval, collectorLog)
	case "NerveUWSGI":
		collector = newNerveUWSGICollector(channel, DefaultCollectionInterval, collectorLog)
	case "DockerStats":
		collector = NewDockerStats(channel, DefaultCollectionInterval, collectorLog)
	case "CpuInfo":
		collector = NewCPUInfo(channel, CPUInfoCollectionInterval, collectorLog)
	case "MesosStats":
		collector = NewMesosStats(channel, DefaultCollectionInterval, collectorLog)
	case "MySQLBinlogGrowth":
		collector = NewMySQLBinlogGrowth(channel, DefaultCollectionInterval, collectorLog)
	default:
		defaultLog.Error("Cannot create collector: ", name)
		return nil
	}
	return collector
}

type baseCollector struct {
	// fulfill most of the rote parts of the collector interface
	channel  chan metric.Metric
	name     string
	interval int

	// intentionally exported
	log *l.Entry
}

func (col *baseCollector) configureCommonParams(configMap map[string]interface{}) {
	if interval, exists := configMap["interval"]; exists {
		col.interval = config.GetAsInt(interval, DefaultCollectionInterval)
	}
}

// SetInterval : set the interval to collect on
func (col *baseCollector) SetInterval(interval int) {<commit_msg>Added MesosSlaveStats case to collector.go<commit_after>package collector

import (
	"fullerite/config"
	"fullerite/metric"

	l "github.com/Sirupsen/logrus"
)

const (
	// DefaultCollectionInterval the interval to collect on unless overridden by a collectors config
	DefaultCollectionInterval = 10
	// CPUInfoCollectionInterval default collection interval for the CPUInfo collector
	CPUInfoCollectionInterval = 3600
)

var defaultLog = l.WithFields(l.Fields{"app": "fullerite", "pkg": "collector"})

// Collector defines the interface of a generic collector.
type Collector interface {
	Collect()
	Configure(map[string]interface{})

	// taken care of by the base class
	Name() string
	Channel() chan metric.Metric
	Interval() int
	SetInterval(int)
}

// New creates a new Collector based on the requested collector name.
func New(name string) Collector {
	var collector Collector

	channel := make(chan metric.Metric)
	collectorLog := defaultLog.WithFields(l.Fields{"collector": name})

	switch name {
	case "Test":
		collector = NewTest(channel, DefaultCollectionInterval, collectorLog)
	case "Diamond":
		collector = NewDiamond(channel, DefaultCollectionInterval, collectorLog)
	case "Fullerite":
		collector = NewFullerite(channel, DefaultCollectionInterval, collectorLog)
	case "ProcStatus":
		collector = NewProcStatus(channel, DefaultCollectionInterval, collectorLog)
	case "FulleriteHTTP":
		collector = newFulleriteHTTPCollector(channel, DefaultCollectionInterval, collectorLog)
	case "NerveUWSGI":
		collector = newNerveUWSGICollector(channel, DefaultCollectionInterval, collectorLog)
	case "DockerStats":
		collector = NewDockerStats(channel, DefaultCollectionInterval, collectorLog)
	case "CpuInfo":
		collector = NewCPUInfo(channel, CPUInfoCollectionInterval, collectorLog)
	case "MesosStats":
		collector = NewMesosStats(channel, DefaultCollectionInterval, collectorLog)
	case "MesosSlaveStats":
		collector = NewMesosSlaveStats(channel, DefaultCollectionInterval, collectorLog)
	case "MySQLBinlogGrowth":
		collector = NewMySQLBinlogGrowth(channel, DefaultCollectionInterval, collectorLog)
	default:
		defaultLog.Error("Cannot create collector: ", name)
		return nil
	}
	return collector
}

type baseCollector struct {
	// fulfill most of the rote parts of the collector interface
	channel  chan metric.Metric
	name     string
	interval int

	// intentionally exported
	log *l.Entry
}

func (col *baseCollector) configureCommonParams(configMap map[string]interface{}) {
	if interval, exists := configMap["interval"]; exists {
		col.interval = config.GetAsInt(interval, DefaultCollectionInterval)
	}
}

// SetInterval : set the interval to collect on
func (col *baseCollector) SetInterval(interval int) {
{'fraction_non_alphanumeric': 0.08627525014158959, 'fraction_numerical': 0.0022654332641117614, 'mean_word_length': 6.007936507936508, 'pattern_counts': {'":': 27, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4722634', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1497, 'n_words': 430}