当前位置: 首页>>代码示例>>Golang>>正文


Golang plugin.ConfigType类代码示例

本文整理汇总了Golang中github.com/intelsdi-x/snap/control/plugin.ConfigType的典型用法代码示例。如果您正苦于以下问题:Golang ConfigType类的具体用法?Golang ConfigType怎么用?Golang ConfigType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ConfigType类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetMetricTypes

// 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
}
开发者ID:IRCody,项目名称:snap,代码行数:32,代码来源:anothermock.go

示例2: GetGlobalConfigItem

// 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)
}
开发者ID:intelsdi-x,项目名称:snap-plugin-utilities,代码行数:12,代码来源:config.go

示例3: GetMetricTypes

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{})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-apache,代码行数:11,代码来源:apache.go

示例4: GetMetricTypes

//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{})
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-etcd,代码行数:13,代码来源:etcd.go

示例5: GetMetricTypes

//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
}
开发者ID:lynxbat,项目名称:snap,代码行数:16,代码来源:mock.go

示例6: GetMetricTypes

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
}
开发者ID:yxzoro,项目名称:snap,代码行数:17,代码来源:grpc.go

示例7: GetMetricTypes

// 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
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-cpu,代码行数:46,代码来源:cpu.go

示例8: GetMetricTypes

// 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
}
开发者ID:XinDongIntel,项目名称:MyFirstGoProj,代码行数:20,代码来源:plugin.go

示例9: GetMetricTypes

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
}
开发者ID:IRCody,项目名称:snap,代码行数:21,代码来源:grpc.go

示例10: GetGlobalConfigItems

// 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
}
开发者ID:intelsdi-x,项目名称:snap-plugin-utilities,代码行数:24,代码来源:config.go


注:本文中的github.com/intelsdi-x/snap/control/plugin.ConfigType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。