fix: recovery alert value is null & refactor stats

This commit is contained in:
710leo 2020-03-19 17:20:29 +08:00
parent 5df96d41a7
commit 3092b4b65d
3 changed files with 6 additions and 7 deletions

View File

@ -110,16 +110,16 @@ func Judge(stra *model.Stra, exps []model.Exp, historyData []*dataobj.RRDData, f
}() }()
leftValue, isTriggered = judgeItemWithStrategy(stra, historyData, exps[0], firstItem, now) leftValue, isTriggered = judgeItemWithStrategy(stra, historyData, exps[0], firstItem, now)
if !isTriggered {
return
}
if value == "" { if value == "" {
value = fmt.Sprintf("%s: %v", exp.Metric, leftValue) value = fmt.Sprintf("%s: %v", exp.Metric, leftValue)
} else { } else {
value += fmt.Sprintf("; %s: %v", exp.Metric, leftValue) value += fmt.Sprintf("; %s: %v", exp.Metric, leftValue)
} }
if !isTriggered {
return
}
//与条件情况下执行 //与条件情况下执行
if len(exps) > 1 { if len(exps) > 1 {
if exps[1].Func == "nodata" { //nodata重新查询索引来进行告警判断 if exps[1].Func == "nodata" { //nodata重新查询索引来进行告警判断

View File

@ -18,11 +18,12 @@ type IdentitySection struct {
func Init(identity IdentitySection) { func Init(identity IdentitySection) {
if identity.Specify != "" { if identity.Specify != "" {
Identity = identity.Specify Identity = identity.Specify
return
} }
var err error var err error
Identity, err = sys.CmdOutTrim("bash", "-c", identity.Shell) Identity, err = sys.CmdOutTrim("bash", "-c", identity.Shell)
if err != nil { if err != nil {
log.Fatalln("[F] cannot get hostname") log.Fatalln("[F] cannot get identity")
} }
} }

View File

@ -7,7 +7,6 @@ import (
"time" "time"
"github.com/didi/nightingale/src/dataobj" "github.com/didi/nightingale/src/dataobj"
"github.com/didi/nightingale/src/toolkits/identity"
"github.com/toolkits/pkg/logger" "github.com/toolkits/pkg/logger"
) )
@ -42,7 +41,6 @@ func Push() {
func NewMetricValue(metric string, value int64) *dataobj.MetricValue { func NewMetricValue(metric string, value int64) *dataobj.MetricValue {
item := &dataobj.MetricValue{ item := &dataobj.MetricValue{
Metric: metric, Metric: metric,
Endpoint: identity.Identity,
Timestamp: time.Now().Unix(), Timestamp: time.Now().Unix(),
ValueUntyped: value, ValueUntyped: value,
CounterType: "GAUGE", CounterType: "GAUGE",