本文整理汇总了Golang中github.com/intelsdi-x/snap/core.Namespace.IsDynamic方法的典型用法代码示例。如果您正苦于以下问题:Golang Namespace.IsDynamic方法的具体用法?Golang Namespace.IsDynamic怎么用?Golang Namespace.IsDynamic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/intelsdi-x/snap/core.Namespace
的用法示例。
在下文中一共展示了Namespace.IsDynamic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: specifyInstanceOfDynamicMetric
// specifyInstanceOfDynamicMetric returns specified namespace of incoming cataloged metric's namespace
// based on requested metric namespace
func specifyInstanceOfDynamicMetric(catalogedNamespace core.Namespace, requestedNamespace core.Namespace) core.Namespace {
specifiedNamespace := make(core.Namespace, len(catalogedNamespace))
copy(specifiedNamespace, catalogedNamespace)
_, indexes := catalogedNamespace.IsDynamic()
for _, index := range indexes {
if len(requestedNamespace) > index {
// use namespace's element of requested metric declared in task manifest
// to specify a dynamic instance of the cataloged metric
specifiedNamespace[index].Value = requestedNamespace[index].Value
}
}
return specifiedNamespace
}
示例2: GetMetric
// GetMetric retrieves a metric for a given requested namespace and version.
// If provided a version of -1 the latest plugin will be returned.
func (mc *metricCatalog) GetMetric(requested core.Namespace, version int) (*metricType, error) {
mc.mutex.Lock()
defer mc.mutex.Unlock()
var ns core.Namespace
catalogedmt, err := mc.tree.GetMetric(requested.Strings(), version)
if err != nil {
log.WithFields(log.Fields{
"_module": "control",
"_file": "metrics.go,",
"_block": "get-metric",
"error": err,
}).Error("error getting metric")
return nil, err
}
ns = catalogedmt.Namespace()
if isDynamic, _ := ns.IsDynamic(); isDynamic {
// when namespace is dynamic and the cataloged namespace (e.g. ns=/intel/mock/*/bar) is different than
// the requested (e.g. requested=/intel/mock/host0/bar), than specify an instance of dynamic element,
// so as a result the dynamic element will have set a value (e.g. ns[2].Value equals "host0")
if ns.String() != requested.String() {
ns = specifyInstanceOfDynamicMetric(ns, requested)
}
}
returnedmt := &metricType{
Plugin: catalogedmt.Plugin,
namespace: ns,
version: catalogedmt.Version(),
lastAdvertisedTime: catalogedmt.LastAdvertisedTime(),
tags: catalogedmt.Tags(),
policy: catalogedmt.Plugin.ConfigPolicy.Get(catalogedmt.Namespace().Strings()),
config: catalogedmt.Config(),
unit: catalogedmt.Unit(),
description: catalogedmt.Description(),
subscriptions: catalogedmt.SubscriptionCount(),
}
return returnedmt, nil
}