From efd756e24ade09209f2b9069260697f70a1f418c Mon Sep 17 00:00:00 2001 From: ChouAndy Date: Wed, 2 Oct 2024 20:05:02 +0800 Subject: [PATCH] feat: aws add MonitorHealthy --- aws/cloudwatch.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/aws/cloudwatch.go b/aws/cloudwatch.go index defdb70..0a55a99 100644 --- a/aws/cloudwatch.go +++ b/aws/cloudwatch.go @@ -11,7 +11,7 @@ import ( "github.com/dinngo/go-sdk/utils" ) -func PutErrorMetric(namesapce string, service string) error { +func putMetric(name, namesapce, service string) error { cfg, err := config.LoadDefaultConfig(context.TODO()) if err != nil { return err @@ -22,7 +22,7 @@ func PutErrorMetric(namesapce string, service string) error { Namespace: utils.Pointer(namesapce), MetricData: []types.MetricDatum{ { - MetricName: utils.Pointer("Error"), + MetricName: utils.Pointer(name), Timestamp: utils.Pointer(time.Now().UTC()), Unit: types.StandardUnitCount, Value: aws.Float64(1), @@ -41,3 +41,20 @@ func PutErrorMetric(namesapce string, service string) error { return nil } + +func PutErrorMetric(namesapce, service string) error { + return putMetric("Error", namesapce, service) +} + +func PutHealthyMetric(namesapce, service string) error { + return putMetric("Healthy", namesapce, service) +} + +func MonitorHealthy(namesapce, service string) { + go func() { + for { + PutHealthyMetric(namesapce, service) + time.Sleep(time.Minute) + } + }() +}