From 49176ae240540db69f4aa089a6a05b23d86170f4 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Thu, 16 Dec 2021 17:58:49 +0800 Subject: [PATCH] support grafana-agent --- Makefile | 2 +- README.md | 2 +- src/server/router/router_opentsdb.go | 2 +- src/server/router/router_prom.go | 30 +++++++++++++++++++--------- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 45cc6b97..a51db486 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ NOW = $(shell date -u '+%Y%m%d%I%M%S') -RELEASE_VERSION = 5.1.0 +RELEASE_VERSION = 5.2.0 APP = n9e SERVER_BIN = $(APP) diff --git a/README.md b/README.md index a03519aa..ca92685d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Nightingale, Prometheus enterprise edition - [x] notify.py support feishu - [ ] notify.py support sms - [ ] notify.py support voice -- [ ] support remote write api +- [x] support remote write api - [ ] support pushgateway api diff --git a/src/server/router/router_opentsdb.go b/src/server/router/router_opentsdb.go index f4731235..03077ead 100644 --- a/src/server/router/router_opentsdb.go +++ b/src/server/router/router_opentsdb.go @@ -193,7 +193,7 @@ func handleOpenTSDB(c *gin.Context) { if len(list) > 0 { promstat.CounterSampleTotal.WithLabelValues(config.C.ClusterName, "opentsdb").Add(float64(len(list))) if !writer.Writers.PushQueue(list) { - msg = "wirter queue full" + msg = "writer queue full" } idents.Idents.MSet(ids) diff --git a/src/server/router/router_prom.go b/src/server/router/router_prom.go index d53ec839..4519d1e8 100644 --- a/src/server/router/router_prom.go +++ b/src/server/router/router_prom.go @@ -58,18 +58,30 @@ func remoteWrite(c *gin.Context) { } var ( - now = time.Now().Unix() - ids = make(map[string]interface{}) - lst = make([]interface{}, count) + now = time.Now().Unix() + ids = make(map[string]interface{}) + lst = make([]interface{}, count) + ident string ) for i := 0; i < count; i++ { - labels := req.Timeseries[i].GetLabels() + ident = "" - ident := "" - for _, label := range labels { - if label.GetName() == "ident" { - ident = label.GetValue() + // find ident label + for j := 0; j < len(req.Timeseries[i].Labels); j++ { + if req.Timeseries[i].Labels[j].Name == "ident" { + ident = req.Timeseries[i].Labels[j].Value + } + } + + if ident == "" { + // not found, try agent_hostname + for j := 0; j < len(req.Timeseries[i].Labels); j++ { + // agent_hostname for grafana-agent + if req.Timeseries[i].Labels[j].Name == "agent_hostname" { + req.Timeseries[i].Labels[j].Name = "ident" + ident = req.Timeseries[i].Labels[j].Value + } } } @@ -97,7 +109,7 @@ func remoteWrite(c *gin.Context) { if writer.Writers.PushQueue(lst) { c.String(200, "") } else { - c.String(http.StatusInternalServerError, "wirter queue full") + c.String(http.StatusInternalServerError, "writer queue full") } }