add map as hashed field

This commit is contained in:
2024-04-21 23:47:18 +02:00
parent 8e3e170ecf
commit c8e7e406ac

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/influxdata/line-protocol/v2/lineprotocol"
log "github.com/sirupsen/logrus"
"hash/fnv"
"os/exec"
"strings"
"time"
@@ -48,11 +49,16 @@ func main() {
enc.StartLine("tf2server")
enc.AddTag("address", string(ip))
enc.AddTag("map", tStat.Map)
enc.AddTag("name", tStat.Name)
enc.AddField("player", lineprotocol.IntValue(int64(tStat.NumPlayers)))
enc.AddField("maxplayer", lineprotocol.IntValue(int64(tStat.MaxPlayers)))
enc.AddField("ping", lineprotocol.IntValue(int64(tStat.Ping)))
// hash map to convert it to int
h := fnv.New32a()
h.Write([]byte(tStat.Map))
enc.AddField("map", lineprotocol.UintValue(uint64(h.Sum32())))
enc.EndLine(time.Now())
fmt.Print(string(enc.Bytes()))
}