本文整理汇总了Golang中github.com/intelsdi-x/snap/core.Namespace类的典型用法代码示例。如果您正苦于以下问题:Golang Namespace类的具体用法?Golang Namespace怎么用?Golang Namespace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Namespace类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: GetQueriedNamespaces
// GetQueriedNamespaces returns all matched metrics namespaces for query 'ns' which can contain
// an asterisk or tuple (refer to query support)
func (mc *metricCatalog) GetQueriedNamespaces(ns core.Namespace) ([]core.Namespace, error) {
mc.mutex.Lock()
defer mc.mutex.Unlock()
// get metric key (might contain wildcard(s))
wkey := ns.Key()
return mc.matchedNamespaces(wkey)
}
开发者ID:yxzoro,项目名称:snap,代码行数:11,代码来源:metrics.go
示例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)
}
开发者ID:yxzoro,项目名称:snap,代码行数:11,代码来源:metrics.go
示例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
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-osv,代码行数:12,代码来源:trace.go
示例4: MatchQuery
// MatchQuery matches given 'ns' which could contain an asterisk or a tuple and add them to matching map under key 'ns'
// The matched metrics namespaces are also returned (as a []core.Namespace)
func (mc *metricCatalog) MatchQuery(ns core.Namespace) ([]core.Namespace, error) {
mc.mutex.Lock()
defer mc.mutex.Unlock()
// get metric key (might contain wildcard(s))
wkey := ns.Key()
// adding matched namespaces to map
mc.addItemToMatchingMap(wkey)
return mc.matchedNamespaces(wkey)
}
开发者ID:yxzoro,项目名称:snap,代码行数:14,代码来源:metrics.go
示例5: getDynamicElements
func getDynamicElements(ns core.Namespace, indexes []int) []rbody.DynamicElement {
elements := make([]rbody.DynamicElement, 0, len(indexes))
for _, v := range indexes {
e := ns.Element(v)
elements = append(elements, rbody.DynamicElement{
Index: v,
Name: e.Name,
Description: e.Description,
})
}
return elements
}
开发者ID:katarzyna-z,项目名称:snap,代码行数:12,代码来源:metric.go
示例6: 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
}
开发者ID:IRCody,项目名称:snap,代码行数:13,代码来源:metrics.go
示例7: 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
}
开发者ID:yxzoro,项目名称:snap,代码行数:29,代码来源:metrics.go
示例8: 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
}
开发者ID:IRCody,项目名称:snap,代码行数:17,代码来源:metrics.go
示例9: 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
}
开发者ID:IRCody,项目名称:snap,代码行数:17,代码来源:metrics.go
示例10: 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
}
开发者ID:IRCody,项目名称:snap,代码行数:17,代码来源:metrics.go
示例11: 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
}
开发者ID:IRCody,项目名称:snap,代码行数:51,代码来源:metrics.go
示例12: 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
}
开发者ID:Collinux,项目名称:snap,代码行数:20,代码来源:metrics.go
示例13: 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)
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-osv,代码行数:29,代码来源:mem.go
示例14: 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
}
开发者ID:IRCody,项目名称:snap,代码行数:44,代码来源:metrics.go
示例15: createMetricNamespace
// createMetricNamespace returns metric namespace based on given `ns` which is used as a prefix; all dynamic elements
// in the `metricName` are defined based on content of map `dynamicElements`
func (creator *nsCreator) createMetricNamespace(ns core.Namespace, metricName string) (core.Namespace, error) {
metricName = strings.TrimSpace(metricName)
if len(metricName) == 0 {
return nil, errors.New("Cannot create metric namespace: empty metric name")
}
elements := strings.Split(metricName, "/")
// check if metricName contains only static elements
if !strings.Contains(metricName, "*") {
ns = ns.AddStaticElements(elements...)
return ns, nil
}
// when metric name contains dynamic element iterate over elements
for index, element := range elements {
if element == "*" {
// the following element is dynamic
dynamicElement, ok := creator.dynamicElements[elements[index-1]]
// check if this dynamic element is supported (name and description are available)
if !ok {
return nil, fmt.Errorf("Unknown dynamic element in metric `%s` under index %d", metricName, index)
}
// add recognize dynamic element (define its name and description)
ns = ns.AddDynamicElement(dynamicElement.name, dynamicElement.description)
if len(elements)-1 == index {
// in case when an asterisk is the last element, add `value` at the end of ns
ns = ns.AddStaticElement("value")
}
} else {
// the following element is static
ns = ns.AddStaticElement(element)
}
}
if len(ns) == 0 {
return nil, fmt.Errorf("Cannot create metric namespace for metric %s", metricName)
}
return ns, nil
}
开发者ID:intelsdi-x,项目名称:snap-plugin-collector-docker,代码行数:43,代码来源:docker.go
示例16: 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)
}
开发者ID:yxzoro,项目名称:snap,代码行数:7,代码来源:metrics.go
示例17: 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())
}
开发者ID:IRCody,项目名称:snap,代码行数:7,代码来源:metrics.go
示例18: parseName
func parseName(namespace core.Namespace) string {
return strings.Join(namespace.Strings()[len(namespacePrefix):], "/")
}
开发者ID:XinDongIntel,项目名称:MyFirstGoProj,代码行数:3,代码来源:plugin.go
示例19: 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())
}
开发者ID:yxzoro,项目名称:snap,代码行数:6,代码来源:metrics.go
注:本文中的github.com/intelsdi-x/snap/core.Namespace类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论