本文整理汇总了Golang中github.com/intelsdi-x/snap/core.Namespace.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Namespace.String方法的具体用法?Golang Namespace.String怎么用?Golang Namespace.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/intelsdi-x/snap/core.Namespace
的用法示例。
在下文中一共展示了Namespace.String方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: memStat
func memStat(ns core.Namespace, swagURL string) (*plugin.MetricType, error) {
memType := ns.Strings()[3]
switch {
case regexp.MustCompile(`^/` + Vendor + `/` + Name + `/memory/free`).MatchString(ns.String()):
metric, err := getMemStat(swagURL, memType)
if err != nil {
return nil, err
}
return &plugin.MetricType{
Namespace_: ns,
Data_: metric,
Timestamp_: time.Now(),
}, nil
case regexp.MustCompile(`^/` + Vendor + `/` + Name + `/memory/total`).MatchString(ns.String()):
metric, err := getMemStat(swagURL, memType)
if err != nil {
return nil, err
}
return &plugin.MetricType{
Namespace_: ns,
Data_: metric,
Timestamp_: time.Now(),
}, nil
}
return nil, fmt.Errorf("Unknown error processing %v", ns)
}
示例2: validateMetricNamespace
// validateMetricNamespace validates metric namespace in terms of containing not allowed characters and ending with an asterisk
func validateMetricNamespace(ns core.Namespace) error {
value := ""
for _, i := range ns {
// A dynamic element requires the name while a static element does not.
if i.Name != "" && i.Value != "*" {
return errorMetricStaticElementHasName(i.Value, i.Name, ns.String())
}
if i.Name == "" && i.Value == "*" {
return errorMetricDynamicElementHasNoName(i.Value, ns.String())
}
value += i.Value
}
for _, chars := range notAllowedChars {
for _, ch := range chars {
if strings.ContainsAny(value, ch) {
return errorMetricContainsNotAllowedChars(ns.String())
}
}
}
// plugin should NOT advertise metrics ending with a wildcard
if strings.HasSuffix(value, "*") {
return errorMetricEndsWithAsterisk(ns.String())
}
return nil
}
示例3: validateMetricNamespace
// validateMetricNamespace validates metric namespace in terms of containing not allowed characters and ending with an asterisk
func validateMetricNamespace(ns core.Namespace) error {
name := ""
for _, i := range ns {
name += i.Value
}
for _, chars := range notAllowedChars {
for _, ch := range chars {
if strings.ContainsAny(name, ch) {
return errorMetricContainsNotAllowedChars(ns.String())
}
}
}
// plugin should NOT advertise metrics ending with a wildcard
if strings.HasSuffix(name, "*") {
return errorMetricEndsWithAsterisk(ns.String())
}
return nil
}
示例4: 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
}