Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
enoch
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
enoch
Commits
94452c24
Commit
94452c24
authored
Apr 10, 2019
by
Node- 门 忠鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
# 修改报警规则
parent
7313cc4d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
36 deletions
+65
-36
operator.go
service/alarm/operator.go
+49
-28
query_engine.go
service/alarm/query_engine.go
+16
-8
No files found.
service/alarm/operator.go
View file @
94452c24
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"fmt"
"fmt"
"git.quantgroup.cn/DevOps/enoch/service/log"
"git.quantgroup.cn/DevOps/enoch/service/log"
"strconv"
"strconv"
"strings"
)
)
type
Compare
struct
{
type
Compare
struct
{
...
@@ -12,32 +13,59 @@ type Compare struct {
...
@@ -12,32 +13,59 @@ type Compare struct {
/**
/**
real < alter
real < alter
*/
*/
func
(
Compare
)
Less
(
alter
string
,
real
string
)
bool
{
func
(
Compare
)
Less
(
alter
string
,
real
[]
string
)
bool
{
return
real
<
alter
rs
:=
true
lastIndex
:=
len
(
real
)
-
1
for
i
,
r
:=
range
real
{
if
i
!=
0
||
i
!=
lastIndex
{
rs
=
rs
&&
(
r
<
alter
)
}
}
return
rs
}
}
/**
func
(
Compare
)
Greater
(
alter
string
,
real
[]
string
)
bool
{
real > alter
rs
:=
true
*/
lastIndex
:=
len
(
real
)
-
1
func
(
Compare
)
Greater
(
alter
string
,
real
string
)
bool
{
for
i
,
r
:=
range
real
{
return
real
>
alter
if
i
!=
0
||
i
!=
lastIndex
{
rs
=
rs
&&
(
r
>
alter
)
}
}
return
rs
}
}
/**
/**
real = alter
real = alter
*/
*/
func
(
Compare
)
Equal
(
alter
string
,
real
string
)
bool
{
func
(
Compare
)
Equal
(
alter
string
,
real
[]
string
)
bool
{
return
real
==
alter
rs
:=
true
}
lastIndex
:=
len
(
real
)
-
1
for
i
,
r
:=
range
real
{
func
(
Compare
)
Between
(
floor
string
,
ceil
string
,
real
string
)
bool
{
if
i
!=
0
||
i
!=
lastIndex
{
return
floor
<
real
&&
ceil
>
real
rs
=
rs
&&
(
r
==
alter
)
}
}
return
rs
}
}
/**
/**
同比超过alter
同比超过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
)
cf
:=
parseToFloat
(
current
)
of
:=
parseToFloat
(
old
)
of
:=
parseToFloat
(
old
)
return
(
cf
-
of
)
/
of
>
parseToFloat
(
alter
)
return
(
cf
-
of
)
/
of
>
parseToFloat
(
alter
)
...
@@ -54,34 +82,27 @@ func parseToFloat(value string) float64 {
...
@@ -54,34 +82,27 @@ func parseToFloat(value string) float64 {
type
MsgBuilder
struct
{
type
MsgBuilder
struct
{
}
}
func
(
MsgBuilder
)
Less
(
alter
string
)
string
{
return
fmt
.
Sprintf
(
" 低于阈值:%s"
,
alter
)
func
(
MsgBuilder
)
Less
(
alter
string
,
real
string
)
string
{
return
fmt
.
Sprintf
(
" 当前值:%.3f, 低于阈值:%s"
,
parseToFloat
(
real
),
alter
)
}
}
/**
/**
real > alter
real > alter
*/
*/
func
(
MsgBuilder
)
Greater
(
alter
string
,
real
string
)
string
{
func
(
MsgBuilder
)
Greater
(
alter
string
)
string
{
return
fmt
.
Sprintf
(
"
当前值:%.3f, 高于阈值:%s"
,
parseToFloat
(
real
)
,
alter
)
return
fmt
.
Sprintf
(
"
高于阈值:%s"
,
alter
)
}
}
/**
/**
real = alter
real = alter
*/
*/
func
(
MsgBuilder
)
Equal
(
alter
string
,
real
string
)
string
{
func
(
MsgBuilder
)
Equal
(
alter
string
)
string
{
return
fmt
.
Sprintf
(
" 当前值:%.3f, 等于阈值:%.3s"
,
parseToFloat
(
real
),
alter
)
return
fmt
.
Sprintf
(
" 等于阈值:%.3s"
,
alter
)
}
func
(
MsgBuilder
)
Between
(
floor
string
,
ceil
string
,
real
string
)
string
{
return
fmt
.
Sprintf
(
" 当前值:%.3f, 介于于阈值:%s 和 %s 之间"
,
parseToFloat
(
real
),
ceil
,
floor
)
}
}
/**
/**
同比超过alter
同比超过alter
*/
*/
func
(
MsgBuilder
)
ComparedWithSame
(
alter
string
,
old
string
,
current
string
)
string
{
func
(
MsgBuilder
)
ComparedWithSame
(
alter
string
)
string
{
return
"同比超过"
+
alter
return
"同比超过"
+
alter
}
}
service/alarm/query_engine.go
View file @
94452c24
package
alarm
package
alarm
import
(
import
(
"fmt"
"git.quantgroup.cn/DevOps/enoch/service/log"
"git.quantgroup.cn/DevOps/enoch/service/log"
"github.com/influxdata/influxdb/client/v2"
"github.com/influxdata/influxdb/client/v2"
"reflect"
"reflect"
...
@@ -32,7 +33,12 @@ func DealResult(res []client.Result, strategies []Strategy) {
...
@@ -32,7 +33,12 @@ func DealResult(res []client.Result, strategies []Strategy) {
if
needIgnore
(
ignoreTag
,
tagValues
)
{
if
needIgnore
(
ignoreTag
,
tagValues
)
{
continue
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
{
//空值报警
if
nil
==
value
&&
noDataAlter
{
//空值报警
Sender
(
tagValues
,
strategy
.
Name
,
"no data"
,
notice
)
Sender
(
tagValues
,
strategy
.
Name
,
"no data"
,
notice
)
...
@@ -43,11 +49,11 @@ func DealResult(res []client.Result, strategies []Strategy) {
...
@@ -43,11 +49,11 @@ func DealResult(res []client.Result, strategies []Strategy) {
for
j
,
arg
:=
range
currentAlterValue
{
for
j
,
arg
:=
range
currentAlterValue
{
params
[
j
]
=
reflect
.
ValueOf
(
arg
)
params
[
j
]
=
reflect
.
ValueOf
(
arg
)
}
}
params
[
alterValueLen
]
=
reflect
.
ValueOf
(
reflect
.
ValueOf
(
value
)
.
String
()
)
params
[
alterValueLen
]
=
reflect
.
ValueOf
(
value
)
logger
.
Info
.
Println
(
uniqueTag
,
":
"
,
params
)
logger
.
Info
.
Println
(
uniqueTag
,
":
alter"
,
params
[
:
1
],
"-"
,
strings
.
Join
(
value
,
","
)
)
rs
:=
operatorMethod
.
Call
(
params
)
rs
:=
operatorMethod
.
Call
(
params
)
if
rs
[
0
]
.
Bool
()
{
//触发报警策略
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) {
...
@@ -63,7 +69,10 @@ func DealResult(res []client.Result, strategies []Strategy) {
continue
continue
}
}
tagValueMap
[
uniqueTag
]
=
tagValues
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
]
{
if
nil
==
params
[
uniqueTag
]
{
currentParams
:=
make
([]
reflect
.
Value
,
strategy
.
SqlLen
+
alterValueLen
)
currentParams
:=
make
([]
reflect
.
Value
,
strategy
.
SqlLen
+
alterValueLen
)
...
@@ -73,9 +82,8 @@ func DealResult(res []client.Result, strategies []Strategy) {
...
@@ -73,9 +82,8 @@ func DealResult(res []client.Result, strategies []Strategy) {
}
}
params
[
uniqueTag
]
=
currentParams
params
[
uniqueTag
]
=
currentParams
}
}
valueStr
:=
reflect
.
ValueOf
(
value
)
.
String
()
params
[
uniqueTag
][
alterValueLen
+
i
]
=
reflect
.
ValueOf
(
value
Str
)
params
[
uniqueTag
][
alterValueLen
+
i
]
=
reflect
.
ValueOf
(
value
)
}
}
}
}
...
@@ -89,7 +97,7 @@ func DealResult(res []client.Result, strategies []Strategy) {
...
@@ -89,7 +97,7 @@ func DealResult(res []client.Result, strategies []Strategy) {
rs
:=
operatorMethod
.
Call
(
v
)
rs
:=
operatorMethod
.
Call
(
v
)
//结果报警
//结果报警
if
rs
[
0
]
.
Bool
()
{
//触发报警策略
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
)
// 报警
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment