提交 2c7f030e 编写于 作者: N ning

fix ident extract

上级 039be7fc
......@@ -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)
......
......@@ -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 = ""
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册