Skip to content

Commit

Permalink
[agent] append default tags to metrics sending via agent
Browse files Browse the repository at this point in the history
  • Loading branch information
laiwei committed Apr 26, 2017
1 parent 8912c85 commit b20061f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
2 changes: 2 additions & 0 deletions config/agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"collector": {
"ifacePrefix": ["eth", "em"]
},
"default_tags": {
},
"ignore": {
"cpu.busy": true,
"df.bytes.free": true,
Expand Down
2 changes: 2 additions & 0 deletions modules/agent/cfg.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"collector": {
"ifacePrefix": ["eth", "em"]
},
"default_tags": {
},
"ignore": {
"cpu.busy": true,
"df.bytes.free": true,
Expand Down
19 changes: 10 additions & 9 deletions modules/agent/g/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ type CollectorConfig struct {
}

type GlobalConfig struct {
Debug bool `json:"debug"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
Plugin *PluginConfig `json:"plugin"`
Heartbeat *HeartbeatConfig `json:"heartbeat"`
Transfer *TransferConfig `json:"transfer"`
Http *HttpConfig `json:"http"`
Collector *CollectorConfig `json:"collector"`
IgnoreMetrics map[string]bool `json:"ignore"`
Debug bool `json:"debug"`
Hostname string `json:"hostname"`
IP string `json:"ip"`
Plugin *PluginConfig `json:"plugin"`
Heartbeat *HeartbeatConfig `json:"heartbeat"`
Transfer *TransferConfig `json:"transfer"`
Http *HttpConfig `json:"http"`
Collector *CollectorConfig `json:"collector"`
DefaultTags map[string]string `json:"default_tags"`
IgnoreMetrics map[string]bool `json:"ignore"`
}

var (
Expand Down
27 changes: 27 additions & 0 deletions modules/agent/g/var.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package g

import (
"bytes"
"github.com/open-falcon/falcon-plus/common/model"
"github.com/toolkits/slice"
"log"
Expand Down Expand Up @@ -55,6 +56,32 @@ func SendToTransfer(metrics []*model.MetricValue) {
return
}

dt := Config().DefaultTags
if len(dt) > 0 {
var buf bytes.Buffer
default_tags_list := []string{}
for k, v := range dt {
buf.Reset()
buf.WriteString(k)
buf.WriteString("=")
buf.WriteString(v)
default_tags_list = append(default_tags_list, buf.String())
}
default_tags := strings.Join(default_tags_list, ",")

for i, x := range metrics {
buf.Reset()
if x.Tags == "" {
metrics[i].Tags = default_tags
} else {
buf.WriteString(metrics[i].Tags)
buf.WriteString(",")
buf.WriteString(default_tags)
metrics[i].Tags = buf.String()
}
}
}

debug := Config().Debug

if debug {
Expand Down

0 comments on commit b20061f

Please sign in to comment.