-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from Cairry/master
Add VictoriaMetrics datasource and prometheus query api
- Loading branch information
Showing
11 changed files
with
371 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package process | ||
|
||
import ( | ||
"watchAlert/internal/global" | ||
"watchAlert/internal/models" | ||
"watchAlert/pkg/ctx" | ||
) | ||
|
||
// EvalCondition 评估告警条件 | ||
func EvalCondition(ctx *ctx.Context, f func() models.AlertCurEvent, value float64, ec models.EvalCondition) { | ||
|
||
switch ec.Type { | ||
case "count", "metric": | ||
switch ec.Operator { | ||
case ">": | ||
if value > ec.Value { | ||
processEvent(ctx, f()) | ||
} | ||
case ">=": | ||
if value >= ec.Value { | ||
processEvent(ctx, f()) | ||
} | ||
case "<": | ||
if value < ec.Value { | ||
processEvent(ctx, f()) | ||
} | ||
case "<=": | ||
if value <= ec.Value { | ||
processEvent(ctx, f()) | ||
} | ||
case "==": | ||
if value == ec.Value { | ||
processEvent(ctx, f()) | ||
} | ||
case "!=": | ||
if value != ec.Value { | ||
processEvent(ctx, f()) | ||
} | ||
default: | ||
global.Logger.Sugar().Error("无效的评估条件", ec.Type, ec.Operator, ec.Value) | ||
} | ||
default: | ||
global.Logger.Sugar().Error("无效的评估类型", ec.Type) | ||
} | ||
|
||
} | ||
|
||
func processEvent(ctx *ctx.Context, event models.AlertCurEvent) { | ||
ok := ctx.DB.Rule().GetRuleIsExist(event.RuleId) | ||
if ok { | ||
SaveEventCache(ctx, event) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.