本文整理汇总了Golang中github.com/intelsdi-x/snap/core.Namespace.Strings方法的典型用法代码示例。如果您正苦于以下问题:Golang Namespace.Strings方法的具体用法?Golang Namespace.Strings怎么用?Golang Namespace.Strings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/intelsdi-x/snap/core.Namespace
的用法示例。
在下文中一共展示了Namespace.Strings方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Remove
// Remove removes a metricType from the catalog and from matching map
func (mc *metricCatalog) Remove(ns core.Namespace) {
mc.mutex.Lock()
defer mc.mutex.Unlock()
mc.tree.Remove(ns.Strings())
// remove all items from map mKey mapped for this 'ns'
key := ns.Key()
mc.removeMatchedKey(key)
}
示例3: traceStat
func traceStat(ns core.Namespace, swagURL string) (*plugin.MetricType, error) {
trace := ns.Strings()[4]
metric, err := getTrace(trace, swagURL)
if err != nil {
return nil, err
}
return &plugin.MetricType{
Namespace_: ns,
Data_: metric,
Timestamp_: time.Now(),
}, nil
}
示例4: GetPlugin
func (mc *metricCatalog) GetPlugin(mns core.Namespace, ver int) (*loadedPlugin, error) {
mt, err := mc.tree.GetMetric(mns.Strings(), ver)
if err != nil {
log.WithFields(log.Fields{
"_module": "control",
"_file": "metrics.go,",
"_block": "get-plugin",
"error": err,
}).Error("error getting plugin")
return nil, err
}
return mt.Plugin, nil
}
示例5: Fetch
// Fetch transactionally retrieves all metrics which fall under namespace ns
func (mc *metricCatalog) Fetch(ns core.Namespace) ([]*metricType, error) {
mc.mutex.Lock()
defer mc.mutex.Unlock()
mtsi, err := mc.tree.Fetch(ns.Strings())
if err != nil {
log.WithFields(log.Fields{
"_module": "control",
"_file": "metrics.go,",
"_block": "fetch",
"error": err,
}).Error("error fetching metrics")
return nil, err
}
return mtsi, nil
}
示例6: GetVersions
// GetVersions retrieves all versions of a given metric namespace.
func (mc *metricCatalog) GetVersions(ns core.Namespace) ([]*metricType, error) {
mc.mutex.Lock()
defer mc.mutex.Unlock()
mts, err := mc.tree.GetVersions(ns.Strings())
if err != nil {
log.WithFields(log.Fields{
"_module": "control",
"_file": "metrics.go,",
"_block": "get-versions",
"error": err,
}).Error("error getting plugin version")
return nil, err
}
return mts, nil
}
示例7: findTuplesMatches
// findTuplesMatches returns all matched combination of queried tuples in incoming namespace,
// where a tuple is in the form of `(host0;host1;host3)`. If the incoming namespace:
// - does not contain any tuple, return the incoming namespace as the only item in output slice.
// - contains a tuple, return the copies of incoming namespace with appropriate values set to namespaces' elements
func findTuplesMatches(incomingNs core.Namespace) []core.Namespace {
// How it works, exemplary incoming namespace:
// "intel", "mock", "(host0;host1)", "(baz;bar)"
//
// the following 4 namespaces will be returned:
// "intel", "mock", "host0", "baz"
// "intel", "mock", "host1", "baz"
// "intel", "mock", "host0", "bar"
// "intel", "mock", "host1", "bar"
matchedItems := make(map[int][]string)
numOfPossibleCombinations := 1
for index, element := range incomingNs.Strings() {
match := []string{}
if ok, tupleItems := containsTuple(element); ok {
match = tupleItems
} else {
match = []string{element}
}
// store matched items under current index of incoming namespace element
matchedItems[index] = append(matchedItems[index], match...)
// number of possible combinations increases N=len(match) times
numOfPossibleCombinations = numOfPossibleCombinations * len(match)
}
//prepare slice for returned namespaces (results of tuple find)
returnedNss := make([]core.Namespace, numOfPossibleCombinations)
// initialize each of returned namespaces as a copy of incoming namespace
// (copied original value, name and description of their elements)
for i := 0; i < numOfPossibleCombinations; i++ {
returnedNs := make([]core.NamespaceElement, len(incomingNs.Strings()))
copy(returnedNs, incomingNs)
returnedNss[i] = returnedNs
}
// set appropriate value to namespace's elements
for index, items := range matchedItems {
for i := range returnedNss {
// retrieve the matched item (when 'i' exceeds the number of matched items, start from beginning)
item := items[i%len(items)]
returnedNss[i][index].Value = item
}
}
return returnedNss
}
示例8: 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
}
示例9: Remove
// Remove removes a metricType from the catalog and from matching map
func (mc *metricCatalog) Remove(ns core.Namespace) {
mc.mutex.Lock()
defer mc.mutex.Unlock()
mc.tree.Remove(ns.Strings())
}
示例10: GetVersions
// GetVersions retrieves all versions of a given metric namespace.
func (mc *metricCatalog) GetVersions(ns core.Namespace) ([]*metricType, error) {
mc.mutex.Lock()
defer mc.mutex.Unlock()
return mc.getVersions(ns.Strings())
}
示例11: Get
// Get retrieves a metric given a namespace and version.
// If provided a version of -1 the latest plugin will be returned.
func (mc *metricCatalog) Get(ns core.Namespace, version int) (*metricType, error) {
mc.mutex.Lock()
defer mc.mutex.Unlock()
return mc.get(ns.Strings(), version)
}
示例12: parseName
func parseName(namespace core.Namespace) string {
return strings.Join(namespace.Strings()[len(namespacePrefix):], "/")
}