switched to lineformat enc
This commit is contained in:
18
main.go
18
main.go
@@ -4,9 +4,11 @@ import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/influxdata/line-protocol/v2/lineprotocol"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TF2Stat struct {
|
||||
@@ -43,11 +45,17 @@ func main() {
|
||||
continue
|
||||
}
|
||||
|
||||
escapedName := strings.ReplaceAll(tStat.Name, " ", `\ `)
|
||||
escapedName = strings.ReplaceAll(escapedName, ",", `\,`)
|
||||
escapedName = strings.ReplaceAll(escapedName, "=", `\=`)
|
||||
// myMeasurement,tag1=value1,tag2=value2 fieldKey="fieldValue" 1556813561098000000
|
||||
fmt.Printf("tf2server,address=%s,name=%s player=%di,maxplayer=%di,map=%q,ping=%di\n", string(ip), escapedName, tStat.NumPlayers, tStat.MaxPlayers, tStat.Map, tStat.Ping)
|
||||
var enc lineprotocol.Encoder
|
||||
|
||||
enc.StartLine("tf2server")
|
||||
enc.AddTag("address", string(ip))
|
||||
enc.AddTag("name", tStat.Name)
|
||||
enc.AddField("player", lineprotocol.IntValue(int64(tStat.NumPlayers)))
|
||||
enc.AddField("maxplayer", lineprotocol.IntValue(int64(tStat.MaxPlayers)))
|
||||
enc.AddField("map", lineprotocol.MustNewValue(tStat.Map))
|
||||
enc.AddField("ping", lineprotocol.IntValue(int64(tStat.Ping)))
|
||||
enc.EndLine(time.Now())
|
||||
fmt.Print(string(enc.Bytes()))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user