Commit 94452c24 authored by Node- 门 忠鑫's avatar Node- 门 忠鑫

# 修改报警规则

parent 7313cc4d
......@@ -4,6 +4,7 @@ import (
"fmt"
"git.quantgroup.cn/DevOps/enoch/service/log"
"strconv"
"strings"
)
type Compare struct {
......@@ -12,32 +13,59 @@ type Compare struct {
/**
real < alter
*/
func (Compare) Less(alter string, real string) bool {
return real < alter
func (Compare) Less(alter string, real []string) bool {
rs := true
lastIndex := len(real) - 1
for i, r := range real {
if i != 0 || i != lastIndex {
rs = rs && (r < alter)
}
}
return rs
}
/**
real > alter
*/
func (Compare) Greater(alter string, real string) bool {
return real > alter
func (Compare) Greater(alter string, real []string) bool {
rs := true
lastIndex := len(real) - 1
for i, r := range real {
if i != 0 || i != lastIndex {
rs = rs && (r > alter)
}
}
return rs
}
/**
real = alter
*/
func (Compare) Equal(alter string, real string) bool {
return real == alter
}
func (Compare) Between(floor string, ceil string, real string) bool {
return floor < real && ceil > real
func (Compare) Equal(alter string, real []string) bool {
rs := true
lastIndex := len(real) - 1
for i, r := range real {
if i != 0 || i != lastIndex {
rs = rs && (r == alter)
}
}
return rs
}
/**
同比超过alter
*/
func (Compare) ComparedWithSame(alter string, old string, current string) bool {
func (Compare) ComparedWithSame(alter string, old []string, current []string) bool {
logger.Info.Println("old:", strings.Join(old, ","), "new: ", strings.Join(current, ","))
rs := true
lastIndex := len(current) - 1
for i, r := range current {
if i != 0 || i != lastIndex {
rs = rs && compareSame(alter, old[i], r)
}
}
return rs
}
func compareSame(alter string, old string, current string) bool {
cf := parseToFloat(current)
of := parseToFloat(old)
return (cf-of)/of > parseToFloat(alter)
......@@ -54,34 +82,27 @@ func parseToFloat(value string) float64 {
type MsgBuilder struct {
}
func (MsgBuilder) Less(alter string, real string) string {
return fmt.Sprintf(" 当前值:%.3f, 低于阈值:%s",parseToFloat(real), alter)
func (MsgBuilder) Less(alter string) string {
return fmt.Sprintf(" 低于阈值:%s", alter)
}
/**
real > alter
*/
func (MsgBuilder) Greater(alter string, real string) string {
return fmt.Sprintf(" 当前值:%.3f, 高于阈值:%s", parseToFloat(real), alter)
func (MsgBuilder) Greater(alter string) string {
return fmt.Sprintf(" 高于阈值:%s", alter)
}
/**
real = alter
*/
func (MsgBuilder) Equal(alter string, real string) string {
return fmt.Sprintf(" 当前值:%.3f, 等于阈值:%.3s", parseToFloat(real), alter)
}
func (MsgBuilder) Between(floor string, ceil string, real string) string {
return fmt.Sprintf(" 当前值:%.3f, 介于于阈值:%s 和 %s 之间", parseToFloat(real), ceil, floor)
func (MsgBuilder) Equal(alter string) string {
return fmt.Sprintf(" 等于阈值:%.3s", alter)
}
/**
同比超过alter
*/
func (MsgBuilder) ComparedWithSame(alter string, old string, current string) string {
func (MsgBuilder) ComparedWithSame(alter string) string {
return "同比超过" + alter
}
package alarm
import (
"fmt"
"git.quantgroup.cn/DevOps/enoch/service/log"
"github.com/influxdata/influxdb/client/v2"
"reflect"
......@@ -32,7 +33,12 @@ func DealResult(res []client.Result, strategies []Strategy) {
if needIgnore(ignoreTag, tagValues) {
continue
}
value := series.Values[0][1]
value := make([]string,0)
for _, v := range series.Values {
value = append(value, fmt.Sprint(v[1]))
}
//value := series.Values[0][1]
if nil == value && noDataAlter { //空值报警
Sender(tagValues, strategy.Name, "no data", notice)
......@@ -43,11 +49,11 @@ func DealResult(res []client.Result, strategies []Strategy) {
for j, arg := range currentAlterValue {
params[j] = reflect.ValueOf(arg)
}
params[alterValueLen] = reflect.ValueOf(reflect.ValueOf(value).String())
logger.Info.Println(uniqueTag, ":", params)
params[alterValueLen] = reflect.ValueOf(value)
logger.Info.Println(uniqueTag, ":alter", params[:1], "-", strings.Join(value, ","))
rs := operatorMethod.Call(params)
if rs[0].Bool() { //触发报警策略
Sender(tagValues, strategy.Name, buildMsgMethod.Call(params)[0].String(), notice) // 报警
Sender(tagValues, strategy.Name, buildMsgMethod.Call(params[:1])[0].String(), notice) // 报警
}
}
......@@ -63,7 +69,10 @@ func DealResult(res []client.Result, strategies []Strategy) {
continue
}
tagValueMap[uniqueTag] = tagValues
value := series.Values[0][1]
value := make([]string,0)
for _, v := range series.Values {
value = append(value, fmt.Sprint(v[1]))
}
if nil == params[uniqueTag] {
currentParams := make([]reflect.Value, strategy.SqlLen+alterValueLen)
......@@ -73,9 +82,8 @@ func DealResult(res []client.Result, strategies []Strategy) {
}
params[uniqueTag] = currentParams
}
valueStr := reflect.ValueOf(value).String()
params[uniqueTag][alterValueLen+i] = reflect.ValueOf(valueStr)
params[uniqueTag][alterValueLen+i] = reflect.ValueOf(value)
}
}
......@@ -89,7 +97,7 @@ func DealResult(res []client.Result, strategies []Strategy) {
rs := operatorMethod.Call(v)
//结果报警
if rs[0].Bool() { //触发报警策略
Sender(tagValueMap[k], strategy.Name, buildMsgMethod.Call(v)[0].String(), notice) // 报警
Sender(tagValueMap[k], strategy.Name, buildMsgMethod.Call(v[:1])[0].String(), notice) // 报警
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment