Browse Source

fix ident extract

tags/v6.0.0-ga12
ning 3 years ago
parent
commit
2c7f030ea5
2 changed files with 11 additions and 2 deletions
  1. +1
    -1
      alert/dispatch/dispatch.go
  2. +10
    -1
      pushgw/router/router_remotewrite.go

+ 1
- 1
alert/dispatch/dispatch.go View File

@@ -180,7 +180,7 @@ func (e *Dispatch) Send(rule *models.AlertRule, event *models.AlertCurEvent, not
s := e.senders[channel]
e.RwLock.RUnlock()
if s == nil {
logger.Warningf("no sender for channel: %s", channel)
logger.Debugf("no sender for channel: %s", channel)
continue
}
logger.Debugf("send event: %s, channel: %s", event.Hash, channel)


+ 10
- 1
pushgw/router/router_remotewrite.go View File

@@ -11,6 +11,15 @@ import (
"github.com/prometheus/prometheus/prompb"
)

func extractMetricFromTimeSeries(s *prompb.TimeSeries) string {
for i := 0; i < len(s.Labels); i++ {
if s.Labels[i].Name == "__name__" {
return s.Labels[i].Value
}
}
return ""
}

func extractIdentFromTimeSeries(s *prompb.TimeSeries) string {
for i := 0; i < len(s.Labels); i++ {
if s.Labels[i].Name == "ident" {
@@ -83,7 +92,7 @@ func (rt *Router) remoteWrite(c *gin.Context) {
ident = extractIdentFromTimeSeries(req.Timeseries[i])

// telegraf 上报数据的场景,只有在 metric 为 system_load1 时,说明指标来自机器,将 host 改为 ident,其他情况都忽略
if metric != "system_load1" {
if extractMetricFromTimeSeries(req.Timeseries[i]) != "system_load1" {
ident = ""
}



Loading…
Cancel
Save