Update code style
This commit is contained in:
parent
be7b64172a
commit
f4d802d9a8
|
@ -4,19 +4,18 @@ Telegraph plugin to push metrics on Warp10
|
||||||
|
|
||||||
### Telegraph output for Warp10 ###
|
### Telegraph output for Warp10 ###
|
||||||
|
|
||||||
* Execute a post http on Warp10 at every flush time configured in telegraph in order to push the metrics collected
|
Execute a post http on Warp10 at every flush time configured in telegraph in order to push the metrics collected
|
||||||
|
|
||||||
### Config ###
|
### Config ###
|
||||||
|
|
||||||
* Add following instruction in the config file (Output part)
|
Add following instruction in the config file (Output part)
|
||||||
|
|
||||||
```
|
```
|
||||||
[[outputs.warp10]]
|
[[outputs.warp10]]
|
||||||
warpUrl = "https://warp1.cityzendata.net/api/v0/update"
|
warpUrl = "http://localhost:4242"
|
||||||
token = "token"
|
token = "token"
|
||||||
prefix = "telegraf."
|
prefix = "telegraf."
|
||||||
debug = false
|
debug = false
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Contact ###
|
### Contact ###
|
||||||
|
|
|
@ -24,10 +24,10 @@ type Warp10 struct {
|
||||||
|
|
||||||
var sampleConfig = `
|
var sampleConfig = `
|
||||||
# prefix for metrics class Name
|
# prefix for metrics class Name
|
||||||
prefix = "telegraf."
|
prefix = "Prefix"
|
||||||
## POST HTTP Mode ##
|
## POST HTTP(or HTTPS) ##
|
||||||
# Url name of the Warp 10 server
|
# Url name of the Warp 10 server
|
||||||
warp_url = "localhost:4242/"
|
warp_url = "WarpUrl"
|
||||||
# Token to access your app on warp 10
|
# Token to access your app on warp 10
|
||||||
token = "Token"
|
token = "Token"
|
||||||
`
|
`
|
||||||
|
@ -47,7 +47,7 @@ func (o *Warp10) Write(metrics []telegraf.Metric) error {
|
||||||
if len(metrics) == 0 {
|
if len(metrics) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var timeNow = time.Now()
|
var now = time.Now()
|
||||||
collectString := make([]string, 0)
|
collectString := make([]string, 0)
|
||||||
index := 0
|
index := 0
|
||||||
for _, mm := range metrics {
|
for _, mm := range metrics {
|
||||||
|
@ -56,20 +56,20 @@ func (o *Warp10) Write(metrics []telegraf.Metric) error {
|
||||||
|
|
||||||
metric := &MetricLine{
|
metric := &MetricLine{
|
||||||
Metric: fmt.Sprintf("%s%s", o.Prefix, mm.Name()+"."+k),
|
Metric: fmt.Sprintf("%s%s", o.Prefix, mm.Name()+"."+k),
|
||||||
Timestamp: timeNow.Unix() * 1000000,
|
Timestamp: now.Unix() * 1000000,
|
||||||
}
|
}
|
||||||
|
|
||||||
metricValue, buildError := buildValue(v)
|
metricValue, err := buildValue(v)
|
||||||
if buildError != nil {
|
if err != nil {
|
||||||
fmt.Printf("Warp: %s\n", buildError.Error())
|
log.Printf("Warp: %s\n", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
metric.Value = metricValue
|
metric.Value = metricValue
|
||||||
|
|
||||||
tagsSlice := buildTags(mm.Tags())
|
tagsSlice := buildTags(mm.Tags())
|
||||||
metric.Tags = fmt.Sprint(strings.Join(tagsSlice, ","))
|
metric.Tags = strings.Join(tagsSlice, ",")
|
||||||
|
|
||||||
messageLine := fmt.Sprintf("%v// %s{%s} %v \n", metric.Timestamp, metric.Metric, metric.Tags, metric.Value)
|
messageLine := fmt.Sprintf("%d// %s{%s} %s\n", metric.Timestamp, metric.Metric, metric.Tags, metric.Value)
|
||||||
|
|
||||||
collectString = append(collectString, messageLine)
|
collectString = append(collectString, messageLine)
|
||||||
index += 1
|
index += 1
|
||||||
|
|
Loading…
Reference in New Issue