func processMetric(ns string, dom libvirt.VirDomain, p plugin.PluginMetricType) (plugin.PluginMetricType, error) {
	cpure := regexp.MustCompile(`^/libvirt/.*/.*/cpu/.*`)
	memre := regexp.MustCompile(`^/libvirt/.*/.*/mem/.*`)
	netre := regexp.MustCompile(`^/libvirt/.*/.*/net/.*`)
	diskre := regexp.MustCompile(`^/libvirt/.*/.*/disk/.*`)

	switch {
	case memre.MatchString(ns):
		metric, err := memStat(p.Namespace(), dom)
		return *metric, err

	case cpure.MatchString(ns):
		metric, err := cpuTimes(p.Namespace(), dom)
		return *metric, err

	case netre.MatchString(ns):
		metric, err := interfaceStat(p.Namespace(), dom)
		return *metric, err

	case diskre.MatchString(ns):
		metric, err := diskStat(p.Namespace(), dom)
		return *metric, err

	}
	return plugin.PluginMetricType{}, fmt.Errorf("Failed to process metric, unknown type %s", ns)
}
func createEvent(m plugin.PluginMetricType, config map[string]ctypes.ConfigValue) *raidman.Event {
	return &raidman.Event{
		Host:    m.Source(),
		Service: strings.Join(m.Namespace(), "/"),
		Metric:  m.Data(),
	}
}
Ejemplo n.º 3
0
// checkCache checks the cache for metric types.
// returns:
//  - array of metrics that need to be collected
//  - array of metrics that were returned from the cache
func checkCache(mts []core.Metric) ([]plugin.PluginMetricType, []core.Metric) {
	var fromCache []core.Metric
	var metricsToCollect []plugin.PluginMetricType
	for _, mt := range mts {
		if m := metricCache.get(core.JoinNamespace(mt.Namespace()), mt.Version()); m != nil {
			switch metric := m.(type) {
			case core.Metric:
				fromCache = append(fromCache, metric)
			case []core.Metric:
				for _, met := range metric {
					fromCache = append(fromCache, met)
				}
			default:
				log.WithFields(log.Fields{
					"_module": "client",
					"_block":  "checkCache",
				}).Error("unsupported type found in the cache")
			}
		} else {
			mt := plugin.PluginMetricType{
				Namespace_:          mt.Namespace(),
				LastAdvertisedTime_: mt.LastAdvertisedTime(),
				Version_:            mt.Version(),
				Tags_:               mt.Tags(),
				Labels_:             mt.Labels(),
				Config_:             mt.Config(),
			}
			metricsToCollect = append(metricsToCollect, mt)
		}
	}
	return metricsToCollect, fromCache
}