Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Added publishing tags by file publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
IzabellaRaulin committed Jun 28, 2016
1 parent 76e5f9f commit ae1890d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
43 changes: 43 additions & 0 deletions examples/tasks/mock_tagged-file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"version": 1,
"schedule": {
"type": "simple",
"interval": "1s"
},
"workflow": {
"collect": {
"metrics": {
"/intel/mock/foo": {},
"/intel/mock/bar": {},
"/intel/mock/*/baz": {}
},
"config": {
"/intel/mock": {
"name": "root",
"password": "secret"
}
},
"tags": {
"/intel/mock": {
"experiment": "1",
"os": "linux"
}
},

"process": [
{
"plugin_name": "passthru",
"process": null,
"publish": [
{
"plugin_name": "file",
"config": {
"file": "/tmp/snap_published_mock_file.log"
}
}
]
}
]
}
}
}
15 changes: 14 additions & 1 deletion plugin/publisher/snap-publisher-file/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/intelsdi-x/snap/control/plugin"
"github.com/intelsdi-x/snap/control/plugin/cpolicy"
"github.com/intelsdi-x/snap/core/ctypes"
"strings"
)

const (
Expand Down Expand Up @@ -73,12 +74,24 @@ func (f *filePublisher) Publish(contentType string, content []byte, config map[s
}
w := bufio.NewWriter(file)
for _, m := range metrics {
w.WriteString(fmt.Sprintf("%v|%v|%v\n", m.Timestamp(), m.Namespace(), m.Data()))
formattedTags := formatMetricTagsAsString(m.Tags())
w.WriteString(fmt.Sprintf("%v|%v|%v|%v\n", m.Timestamp(), m.Namespace(), m.Data(), formattedTags))
}
w.Flush()

return nil
}
// formatMetricTagsAsString returns metric's tags as a string in the following format tagKey:tagValue where the next tags are separated by semicolon
func formatMetricTagsAsString(metricTags map[string]string) string {
var tags string
for tag, value := range metricTags {
tags += fmt.Sprintf("%s:%s; ", tag, value)
}
// trim the last semicolon
tags = strings.TrimSuffix(tags, "; ")

return "tags["+tags+"]"
}

func Meta() *plugin.PluginMeta {
return plugin.NewPluginMeta(name, version, pluginType, []string{plugin.SnapGOBContentType}, []string{plugin.SnapGOBContentType})
Expand Down

0 comments on commit ae1890d

Please sign in to comment.