Exemplo n.º 1
0
// GetMetricTypes returns metric types for testing
func (f *AnotherMock) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	mts := []plugin.MetricType{}
	if _, ok := cfg.Table()["test-fail"]; ok {
		return mts, fmt.Errorf("testing")
	}
	if _, ok := cfg.Table()["test"]; ok {
		mts = append(mts, plugin.MetricType{
			Namespace_:   core.NewNamespace("intel", "anothermock", "test"),
			Description_: "anothermock description",
			Unit_:        "anothermock unit",
		})
	}
	mts = append(mts, plugin.MetricType{
		Namespace_:   core.NewNamespace("intel", "anothermock", "foo"),
		Description_: "anothermock description",
		Unit_:        "anothermock unit",
	})
	mts = append(mts, plugin.MetricType{
		Namespace_:   core.NewNamespace("intel", "anothermock", "bar"),
		Description_: "anothermock description",
		Unit_:        "anothermock unit",
	})
	mts = append(mts, plugin.MetricType{
		Namespace_: core.NewNamespace("intel", "anothermock").
			AddDynamicElement("host", "name of the host").
			AddStaticElement("baz"),
		Description_: "anothermock description",
		Unit_:        "anothermock unit",
	})
	return mts, nil
}
Exemplo n.º 2
0
// GetGlobalConfigItem returns value of config item specified by `name` defined in Plugin Global Config
// Notes: GetGlobalConfigItem() will be helpful to access and get configuration item's value in GetMetricTypes()
func GetGlobalConfigItem(cfg plugin.ConfigType, name string) (interface{}, error) {

	if cfg.ConfigDataNode != nil && len(cfg.Table()) > 0 {
		if item, ok := cfg.Table()[name]; ok {
			return getConfigItemValue(item)
		}
	}

	return nil, fmt.Errorf("Cannot find %v in Global Config", name)
}
func (a *Apache) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	webservercfg, ok := cfg.Table()["apache_mod_status_url"]
	if !ok {
		return getMetrics("http://127.0.0.1:80/server-status?auto", []string{})
	}
	webserver, ok := webservercfg.(ctypes.ConfigValueStr)
	if !ok {
		return nil, errBadWebserver
	}
	return getMetrics(webserver.Value, []string{})
}
Exemplo n.º 4
0
//GetMetricTypes returns metric types for testing
func (e *Etcd) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	hostcfg, ok := cfg.Table()["etcd_host"]
	if !ok {
		return nil, errNoHost
	}
	host, ok := hostcfg.(ctypes.ConfigValueStr)
	if !ok {
		return nil, errBadHost
	}

	return gathermts(host.Value, []string{})
}
Exemplo n.º 5
0
Arquivo: mock.go Projeto: lynxbat/snap
//GetMetricTypes returns metric types for testing
func (f *Mock) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	mts := []plugin.MetricType{}
	if _, ok := cfg.Table()["test-fail"]; ok {
		return mts, fmt.Errorf("missing on-load plugin config entry 'test'")
	}
	if _, ok := cfg.Table()["test"]; ok {
		mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace("intel", "mock", "test")})
	}
	mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace("intel", "mock", "foo")})
	mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace("intel", "mock", "bar")})
	mts = append(mts, plugin.MetricType{Namespace_: core.NewNamespace("intel", "mock").
		AddDynamicElement("host", "name of the host").
		AddStaticElement("baz")})
	return mts, nil
}
Exemplo n.º 6
0
Arquivo: grpc.go Projeto: yxzoro/snap
func (g *grpcClient) GetMetricTypes(config plugin.ConfigType) ([]core.Metric, error) {
	arg := &rpc.GetMetricTypesArg{
		Config: common.ToConfigMap(config.Table()),
	}
	reply, err := g.collector.GetMetricTypes(getContext(g.timeout), arg)

	if err != nil {
		return nil, err
	}

	if reply.Error != "" {
		return nil, errors.New(reply.Error)
	}

	results := common.ToCoreMetrics(reply.Metrics)
	return results, nil
}
Exemplo n.º 7
0
// GetMetricTypes returns list of available metric types
// It returns error in case retrieval was not successful
func (p *Plugin) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	if !p.initialized {
		if err := p.init(cfg.Table()); err != nil {
			return nil, err
		}
	}
	if err := getStats(p.proc_path, p.stats, p.prevMetricsSum, p.cpuMetricsNumber,
		p.snapMetricsNames, p.procStatMetricsNames); err != nil {
		return nil, err
	}
	metricTypes := []plugin.MetricType{}

	namespaces := []string{}

	prefix := filepath.Join(vendor, fs, pluginName)
	for cpu, stats := range p.stats {
		for metric, _ := range stats {
			namespaces = append(namespaces, prefix+"/"+cpu+"/"+metric)
		}
	}

	// List of terminal metric names
	mList := make(map[string]bool)
	for _, namespace := range namespaces {
		namespace = strings.TrimRight(namespace, string(os.PathSeparator))
		metricType := plugin.MetricType{
			Namespace_: core.NewNamespace(strings.Split(namespace, string(os.PathSeparator))...)}
		ns := metricType.Namespace()
		// CPU metric (aka last element in namespace)
		mItem := ns[len(ns)-1]
		// Keep it if not already seen before
		if !mList[mItem.Value] {
			mList[mItem.Value] = true
			metricTypes = append(metricTypes, plugin.MetricType{
				Namespace_: core.NewNamespace(strings.Split(prefix, string(os.PathSeparator))...).
					AddDynamicElement("cpuID", "ID of CPU ('all' for aggregate)").
					AddStaticElement(mItem.Value),
				Description_: "dynamic CPU metric: " + mItem.Value,
			})
		}
	}

	return metricTypes, nil
}
Exemplo n.º 8
0
// GetMetricTypes Returns list of metrics available for current vendor.
func (ic *IpmiCollector) GetMetricTypes(cfg plugin.ConfigType) ([]plugin.MetricType, error) {
	ic.construct(cfg.Table())
	var mts []plugin.MetricType
	mts = make([]plugin.MetricType, 0)
	if ic.IpmiLayer == nil {
		ic.Initialized = false
		return mts, fmt.Errorf("Wrong mode configuration")
	}
	for _, host := range ic.Hosts {
		for _, req := range ic.Vendor[host] {
			for _, metric := range req.Format.GetMetrics() {
				path := extendPath(req.MetricsRoot, metric)
				mts = append(mts, plugin.MetricType{Namespace_: makeName(path), Tags_: map[string]string{"source": host}})
			}
		}
	}
	ic.Initialized = true
	return mts, nil
}
Exemplo n.º 9
0
Arquivo: grpc.go Projeto: IRCody/snap
func (g *grpcClient) GetMetricTypes(config plugin.ConfigType) ([]core.Metric, error) {
	arg := &rpc.GetMetricTypesArg{
		Config: ToConfigMap(config.Table()),
	}
	reply, err := g.collector.GetMetricTypes(getContext(g.timeout), arg)

	if err != nil {
		return nil, err
	}

	if reply.Error != "" {
		return nil, errors.New(reply.Error)
	}

	for _, metric := range reply.Metrics {
		metric.LastAdvertisedTime = ToTime(time.Now())
	}

	results := ToCoreMetrics(reply.Metrics)
	return results, nil
}
Exemplo n.º 10
0
// GetGlobalConfigItems returns map to values of multiple configuration items defined in Plugin Global Config and specified in 'names' slice
// Notes: GetGlobalConfigItems() will be helpful to access and get multiple configuration items' values in GetMetricTypes()
func GetGlobalConfigItems(cfg plugin.ConfigType, names []string) (map[string]interface{}, error) {
	result := make(map[string]interface{})

	for _, name := range names {
		if cfg.ConfigDataNode != nil && len(cfg.Table()) > 0 {
			item, ok := cfg.Table()[name]
			if !ok {
				return nil, fmt.Errorf("Cannot find %v in Global Config", name)
			}

			val, err := getConfigItemValue(item)
			if err != nil {
				return nil, err
			}
			result[name] = val
		} else {
			return nil, fmt.Errorf("Cannot find %v in Global Config", name)
		}
	}

	return result, nil
}