本文整理汇总了Golang中bosun/org/opentsdb.TagSet类的典型用法代码示例。如果您正苦于以下问题:Golang TagSet类的具体用法?Golang TagSet怎么用?Golang TagSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TagSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseTcollectorValue
// parseTcollectorValue parses a tcollector-style line into a data point.
func parseTcollectorValue(line string) (*opentsdb.DataPoint, error) {
sp := strings.Fields(line)
if len(sp) < 3 {
return nil, fmt.Errorf("bad line: %s", line)
}
ts, err := strconv.ParseInt(sp[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("bad timestamp: %s", sp[1])
}
val, err := strconv.ParseFloat(sp[2], 64)
if err != nil {
return nil, fmt.Errorf("bad value: %s", sp[2])
}
if !opentsdb.ValidTag(sp[0]) {
return nil, fmt.Errorf("bad metric: %s", sp[0])
}
dp := opentsdb.DataPoint{
Metric: sp[0],
Timestamp: ts,
Value: val,
}
tags := opentsdb.TagSet{}
for _, tag := range sp[3:] {
ts, err := opentsdb.ParseTags(tag)
if err != nil {
return nil, fmt.Errorf("bad tag, metric %s: %v: %v", sp[0], tag, err)
}
tags.Merge(ts)
}
setExternalTags(tags)
dp.Tags = tags
return &dp, nil
}
示例2: BenchmarkSimpleRewrite
func BenchmarkSimpleRewrite(b *testing.B) {
rule := &DenormalizationRule{
Metric: "a.b.c",
TagNames: []string{"host"},
}
tags := opentsdb.TagSet{"host": "foo-bar", "baz": "qwerty"}
dp := &opentsdb.DataPoint{
Metric: "a.b.c",
Timestamp: 42,
Value: 3,
Tags: tags.Copy(),
}
for i := 0; i < b.N; i++ {
err := rule.Translate(dp)
if err != nil {
b.Fatal(err)
}
//expectedName := "__foo-bar.a.b.c"
/* if dp.Metric != expectedName {
b.Errorf("metric name %s is not `%s`", dp.Metric, expectedName)
}
if dp.Timestamp != 42 {
b.Errorf("new metric timestamp does not match. %d != 42", dp.Timestamp)
}
if dp.Value != 3 {
b.Errorf("new metric value does not match. %d != 3", dp.Value)
}
if !dp.Tags.Equal(tags) {
b.Errorf("new metric tags do not match. %v != %v", dp.Tags, tags)
} */
}
}
示例3: AddTags
func (to *TagOverride) AddTags(t opentsdb.TagSet) {
if to.tags == nil {
to.tags = t.Copy()
} else {
to.tags = to.tags.Merge(t)
}
}
示例4: AddMeta
// AddMeta adds a metadata entry to memory, which is queued for later sending.
func AddMeta(metric string, tags opentsdb.TagSet, name string, value interface{}, setHost bool) {
if tags == nil {
tags = make(opentsdb.TagSet)
}
if _, present := tags["host"]; setHost && !present {
tags["host"] = util.Hostname
}
if err := tags.Clean(); err != nil {
slog.Error(err)
return
}
ts := tags.Tags()
metalock.Lock()
defer metalock.Unlock()
prev, present := metadata[Metakey{metric, ts, name}]
if present && !reflect.DeepEqual(prev, value) {
slog.Infof("metadata changed for %s/%s/%s: %v to %v", metric, ts, name, prev, value)
go sendMetadata([]Metasend{{
Metric: metric,
Tags: tags,
Name: name,
Value: value,
}})
} else if metadebug {
slog.Infof("AddMeta for %s/%s/%s: %v", metric, ts, name, value)
}
metadata[Metakey{metric, ts, name}] = value
}
示例5: AddTS
// AddTS is the same as Add but lets you specify the timestamp
func AddTS(md *opentsdb.MultiDataPoint, name string, ts int64, value interface{}, t opentsdb.TagSet, rate metadata.RateType, unit metadata.Unit, desc string) {
if b, ok := value.(bool); ok {
if b {
value = 1
} else {
value = 0
}
}
tags := t.Copy()
if host, present := tags["host"]; !present {
tags["host"] = util.Hostname
} else if host == "" {
delete(tags, "host")
}
if rate != metadata.Unknown {
metadata.AddMeta(name, nil, "rate", rate, false)
}
if unit != metadata.None {
metadata.AddMeta(name, nil, "unit", unit, false)
}
if desc != "" {
metadata.AddMeta(name, tags, "desc", desc, false)
}
tags = AddTags.Copy().Merge(tags)
d := opentsdb.DataPoint{
Metric: name,
Timestamp: ts,
Value: value,
Tags: tags,
}
*md = append(*md, &d)
}
示例6: Put
// Put is useful for capturing "events" that have a gauge value. Subsequent
// calls between the sending interval will overwrite previous calls.
func Put(metric string, ts opentsdb.TagSet, v interface{}) error {
if err := check(metric, &ts); err != nil {
return err
}
tss := metric + ts.String()
mlock.Lock()
puts[tss] = &putMetric{metric, ts.Copy(), v}
mlock.Unlock()
return nil
}
示例7: Set
// Set registers a callback for the given metric and tags, calling f immediately
// before queueing data for send.
func Set(metric string, ts opentsdb.TagSet, f func() interface{}) error {
if err := check(metric, &ts); err != nil {
return err
}
tss := metric + ts.String()
mlock.Lock()
sets[tss] = &setMetric{metric, ts.Copy(), f}
mlock.Unlock()
return nil
}
示例8: AddTS
// AddTS is the same as Add but lets you specify the timestamp
func AddTS(md *opentsdb.MultiDataPoint, name string, ts int64, value interface{}, t opentsdb.TagSet, rate metadata.RateType, unit metadata.Unit, desc string) {
// Check if we really want that metric
if skipMetric(name) {
return
}
tags := t.Copy()
if host, present := tags["host"]; !present {
tags["host"] = util.Hostname
} else if host == "" {
delete(tags, "host")
}
// if tags are not cleanable, log a message and skip it
if err := tags.Clean(); err != nil {
line := ""
//attempt to log where Add was called from
if _, filename, l, ok := runtime.Caller(1); ok {
if filepath.Base(filename) == "collectors.go" {
_, filename, l, ok = runtime.Caller(2)
}
if ok {
line = fmt.Sprintf("%s:%d", filepath.Base(filename), l)
}
}
slog.Errorf("Invalid tagset discovered: %s. Skipping datapoint. Added from: %s", tags.String(), line)
return
}
if rate != metadata.Unknown {
metadata.AddMeta(name, nil, "rate", rate, false)
}
if unit != metadata.None {
metadata.AddMeta(name, nil, "unit", unit, false)
}
if desc != "" {
metadata.AddMeta(name, tags, "desc", desc, false)
}
tags = AddTags.Copy().Merge(tags)
if b, ok := value.(bool); ok {
if b {
value = 1
} else {
value = 0
}
}
d := opentsdb.DataPoint{
Metric: name,
Timestamp: ts,
Value: value,
Tags: tags,
}
*md = append(*md, &d)
}
示例9: GetLast
// GetLast returns the value of the most recent data point for the given metric
// and tag. tags should be of the form "{key=val,key2=val2}". If diff is true,
// the value is treated as a counter. err is non nil if there is no match.
func (s *Search) GetLast(metric string, tags opentsdb.TagSet, diff bool) (v float64, err error) {
s.RLock()
defer s.RUnlock()
if mmap := s.last[metric]; mmap != nil {
if p := mmap[tags.String()]; p != nil {
if diff {
return p.DiffFromPrev, nil
}
return p.LastVal, nil
}
}
return 0, nil
}
示例10: Sample
func Sample(metric string, ts opentsdb.TagSet, v float64) error {
if err := check(metric, &ts); err != nil {
return err
}
tss := metric + ts.String()
mlock.Lock()
if aggs[tss] == nil {
aggs[tss] = &agMetric{
metric: metric,
ts: ts.Copy(),
}
}
aggs[tss].values = append(aggs[tss].values, v)
mlock.Unlock()
return nil
}
示例11: Add
// Add takes a metric and increments a counter for that metric. The metric name
// is appended to the basename specified in the Init function.
func Add(metric string, ts opentsdb.TagSet, inc int64) error {
if err := check(metric, &ts); err != nil {
return err
}
tss := metric + ts.String()
mlock.Lock()
if counters[tss] == nil {
counters[tss] = &addMetric{
metric: metric,
ts: ts.Copy(),
}
}
counters[tss].value += inc
mlock.Unlock()
return nil
}
示例12: c_fortinet_os
func c_fortinet_os(host, community string, cpuIntegrators map[string]tsIntegrator) (opentsdb.MultiDataPoint, error) {
var md opentsdb.MultiDataPoint
ts := opentsdb.TagSet{"host": host}
// CPU
cpuRaw, err := snmp_subtree(host, community, fortinetBaseOID+fortinetCPU)
if err != nil {
return md, err
}
coreCount := len(cpuRaw)
var totalPercent int
for id, v := range cpuRaw {
cpuVal, err := strconv.Atoi(fmt.Sprintf("%v", v))
if err != nil {
return md, fmt.Errorf("couldn't convert cpu value to int for fortinet cpu utilization on host %v: %v", host, err)
}
ts := ts.Copy().Merge(opentsdb.TagSet{"processor": id})
Add(&md, "fortinet.cpu.percent_used", cpuVal, ts, metadata.Gauge, metadata.Pct, "")
totalPercent += cpuVal
}
if _, ok := cpuIntegrators[host]; !ok {
cpuIntegrators[host] = getTsIntegrator()
}
Add(&md, osCPU, cpuIntegrators[host](time.Now().Unix(), float64(totalPercent)/float64(coreCount)), opentsdb.TagSet{"host": host}, metadata.Counter, metadata.Pct, "")
// Memory
memTotal, err := snmp_oid(host, community, fortinetBaseOID+fortinetMemTotal)
if err != nil {
return md, fmt.Errorf("failed to get total memory for fortinet host %v: %v", host, err)
}
memTotalBytes := memTotal.Int64() * 2 << 9 // KiB to Bytes
Add(&md, "fortinet.mem.total", memTotal, ts, metadata.Gauge, metadata.KBytes, "The total memory in kilobytes.")
Add(&md, osMemTotal, memTotalBytes, ts, metadata.Gauge, metadata.Bytes, osMemTotalDesc)
memPctUsed, err := snmp_oid(host, community, fortinetBaseOID+fortinetMemPercentUsed)
if err != nil {
return md, fmt.Errorf("failed to get percent of memory used for fortinet host %v: %v", host, err)
}
Add(&md, "fortinet.mem.percent_used", memPctUsed, ts, metadata.Gauge, metadata.Pct, "The percent of memory used.")
memPctUsedFloat := float64(memPctUsed.Int64()) / 100
memPctFree := 100 - memPctUsed.Int64()
Add(&md, osMemPctFree, memPctFree, ts, metadata.Gauge, metadata.Pct, osMemPctFreeDesc)
memFree := float64(memTotalBytes) * (float64(1) - memPctUsedFloat)
Add(&md, osMemFree, int64(memFree), ts, metadata.Gauge, metadata.Bytes, osMemFreeDesc)
Add(&md, osMemUsed, int64(float64(memTotalBytes)-memFree), ts, metadata.Gauge, metadata.Bytes, osMemUsedDesc)
return md, nil
}
示例13: AddTagOverrides
func (to *TagOverride) AddTagOverrides(sources map[string]string, t opentsdb.TagSet) error {
if to.matchedTags == nil {
to.matchedTags = make(map[string]*regexp.Regexp)
}
var err error
for tag, re := range sources {
to.matchedTags[tag], err = regexp.Compile(re)
if err != nil {
return fmt.Errorf("invalid regexp: %s error: %s", re, err)
}
}
if to.tags == nil {
to.tags = t.Copy()
} else {
to.tags = to.tags.Merge(t)
}
return nil
}
示例14: TestTagMetadata_RoundTrip
func TestTagMetadata_RoundTrip(t *testing.T) {
host := randString(4)
tagset := opentsdb.TagSet{"host": host, "iface": "foo", "iname": "bar", "direction": "in"}
if err := testData.Metadata().PutTagMetadata(tagset, "alias", "foo", time.Now()); err != nil {
t.Fatal(err)
}
metas, err := testData.Metadata().GetTagMetadata(tagset, "alias")
if err != nil {
t.Fatal(err)
}
if len(metas) != 1 {
t.Fatal("expected 1 metadata result")
}
m := metas[0]
if m.Name != "alias" {
t.Fatalf("name %s != alias", m.Name)
}
if !m.Tags.Equal(tagset) {
t.Fatalf("tagset %s != %s", m.Tags.String(), tagset.String())
}
}
示例15: rabbitmqBackingQueueStatus
func rabbitmqBackingQueueStatus(p string, ts opentsdb.TagSet, bqs rmqBackingQueueStatus) opentsdb.MultiDataPoint {
var md opentsdb.MultiDataPoint
Add(&md, p+"avg_rate", bqs.AvgAckEgressRate, ts.Copy().Merge(opentsdb.TagSet{"method": "ack", "direction": "out"}),
metadata.Rate, metadata.Message, DescRmqBackingQueueStatusAvgAckEgressRate)
Add(&md, p+"avg_rate", bqs.AvgAckIngressRate, ts.Copy().Merge(opentsdb.TagSet{"method": "ack", "direction": "in"}),
metadata.Rate, metadata.Message, DescRmqBackingQueueStatusAvgAckIngressRate)
Add(&md, p+"avg_rate", bqs.AvgEgressRate, ts.Copy().Merge(opentsdb.TagSet{"method": "noack", "direction": "out"}),
metadata.Rate, metadata.Message, DescRmqBackingQueueStatusAvgEgressRate)
Add(&md, p+"avg_rate", bqs.AvgIngressRate, ts.Copy().Merge(opentsdb.TagSet{"method": "noack", "direction": "in"}),
metadata.Rate, metadata.Message, DescRmqBackingQueueStatusAvgIngressRate)
Add(&md, p+"len", bqs.Len, ts,
metadata.Gauge, metadata.Message, DescRmqBackingQueueStatusLen)
return md
}