コード例 #1
0
// GetMetricTypes returns metric types that can be collected
func (p *Libvirt) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.PluginMetricType, error) {

	conn, err := libvirt.NewVirConnection(getHypervisorURI(cfg.Table()))

	if err != nil {
		handleErr(err)
	}

	var metrics []plugin.PluginMetricType

	domains, err := conn.ListDomains()
	if err != nil {
		handleErr(err)
	}

	hostname, err := conn.GetHostname()
	if err != nil {
		handleErr(err)
	}

	defer conn.CloseConnection()
	for j := 0; j < domainCount(domains); j++ {
		dom, err := conn.LookupDomainById(domains[j])
		if err != nil {
			handleErr(err)
		}
		defer dom.Free()

		netMts, err := getNetMetricTypes(dom, hostname)
		if err != nil {
			handleErr(err)
		}
		metrics = append(metrics, netMts...)
		cpuMts, err := getCPUMetricTypes(dom, hostname)
		if err != nil {
			handleErr(err)
		}
		metrics = append(metrics, cpuMts...)
		memMts, err := getMemMetricTypes(dom, hostname)
		if err != nil {
			handleErr(err)
		}
		metrics = append(metrics, memMts...)
		diskMts, err := getDiskMetricTypes(dom, hostname)
		if err != nil {
			handleErr(err)
		}
		metrics = append(metrics, diskMts...)
	}
	for _, metric := range cpuMetricsTypes {
		metrics = append(metrics, plugin.PluginMetricType{Namespace_: []string{"libvirt", hostname, "*", "cpu", metric}})
	}
	for _, metric := range memoryMetricsTypes {
		metrics = append(metrics, plugin.PluginMetricType{Namespace_: []string{"libvirt", hostname, "*", "mem", metric}})
	}
	return metrics, nil
}
コード例 #2
0
// GetMetricTypes returns the metric types exposed by ceph-daemon sockets
func (ceph *Ceph) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.PluginMetricType, error) {
	// init ceph plugin with Global Config params
	if err := ceph.init(cfg.Table()); err != nil {
		return nil, err
	}

	mts := make([]plugin.PluginMetricType, len(ceph.keys))
	for i, k := range ceph.keys {
		mts[i] = plugin.PluginMetricType{Namespace_: strings.Split(strings.TrimPrefix(k, "/"), "/")}
	}

	return mts, nil
}
コード例 #3
0
ファイル: mock.go プロジェクト: gitter-badger/snap-1
//GetMetricTypes returns metric types for testing
func (f *Mock) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.PluginMetricType, error) {
	mts := []plugin.PluginMetricType{}
	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.PluginMetricType{Namespace_: []string{"intel", "mock", "test"}})
	}
	mts = append(mts, plugin.PluginMetricType{Namespace_: []string{"intel", "mock", "foo"}})
	mts = append(mts, plugin.PluginMetricType{Namespace_: []string{"intel", "mock", "bar"}})
	mts = append(mts, plugin.PluginMetricType{
		Namespace_: []string{"intel", "mock", "*", "baz"},
		Labels_:    []core.Label{core.Label{Index: 2, Name: "host"}},
	})
	return mts, nil
}
コード例 #4
0
// GetMetricTypes Returns list of metrics available for current vendor.
func (ic *IpmiCollector) GetMetricTypes(cfg plugin.PluginConfigType) ([]plugin.PluginMetricType, error) {
	ic.construct(cfg.Table())
	var mts []plugin.PluginMetricType
	mts = make([]plugin.PluginMetricType, 0)
	if ic.IpmiLayer == nil {
		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.PluginMetricType{Namespace_: makeName(path), Source_: host})
			}
		}
	}
	ic.Initialized = true
	return mts, nil
}