From c3b837f68ee7116cdf2093aacfa50bee529b33af Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Tue, 13 Jun 2023 15:06:04 +0800 Subject: [PATCH] add (o *opsclient)unixtimestartandend() in gala-ops plugin --- gala-ops/server/httphandler/component.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gala-ops/server/httphandler/component.go b/gala-ops/server/httphandler/component.go index 901f1f80..504c0441 100644 --- a/gala-ops/server/httphandler/component.go +++ b/gala-ops/server/httphandler/component.go @@ -1,6 +1,10 @@ package httphandler -import "gitee.com/openeuler/PilotGo-plugins/sdk/plugin/client" +import ( + "time" + + "gitee.com/openeuler/PilotGo-plugins/sdk/plugin/client" +) type Opsclient struct { Sdkmethod *client.Client @@ -8,3 +12,13 @@ type Opsclient struct { } var Galaops *Opsclient + +func (o *Opsclient) UnixTimeStartandEnd(timerange time.Duration) (int64, int64) { + now := time.Now() + past5Minutes := now.Add(timerange * time.Minute) + startOfPast5Minutes := time.Date(past5Minutes.Year(), past5Minutes.Month(), past5Minutes.Day(), + past5Minutes.Hour(), past5Minutes.Minute(), 0, 0, past5Minutes.Location()) + timestamp := startOfPast5Minutes.Unix() + return timestamp, now.Unix() +} + -- Gitee