mirror of https://github.com/MedzikUser/go-pingbot
feat(uptime): Add uptime to status and build date
- Moved type.go to types.go - Added build date - Removed linter from gitpod Dockerfile (now is in gitpod image) - Added mongodb Database and Collection to config file (now isn't used [TODO]) - Added uptime to status
This commit is contained in:
parent
5263dddad2
commit
018a2e9b90
|
@ -3,7 +3,4 @@ FROM gitpod/workspace-full
|
||||||
# GoReleaser
|
# GoReleaser
|
||||||
RUN curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh
|
RUN curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh
|
||||||
|
|
||||||
# GoLangCI Lint
|
|
||||||
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1
|
|
||||||
|
|
||||||
RUN npm i -g nodemon
|
RUN npm i -g nodemon
|
||||||
|
|
|
@ -15,6 +15,7 @@ builds:
|
||||||
ldflags:
|
ldflags:
|
||||||
- -s -w
|
- -s -w
|
||||||
- -X gitlab.com/gaming0skar123/go/pingbot/config.Version={{.RawVersion}}
|
- -X gitlab.com/gaming0skar123/go/pingbot/config.Version={{.RawVersion}}
|
||||||
|
- -X gitlab.com/gaming0skar123/go/pingbot/config.Build={{.Date}}
|
||||||
|
|
||||||
archives:
|
archives:
|
||||||
- format: tar.gz
|
- format: tar.gz
|
||||||
|
|
|
@ -13,3 +13,7 @@ check=2 # Check every two minutes
|
||||||
[cluster]
|
[cluster]
|
||||||
id=1 # Cluster ID
|
id=1 # Cluster ID
|
||||||
node=1 # Node ID
|
node=1 # Node ID
|
||||||
|
|
||||||
|
[mongodb]
|
||||||
|
database="PingBot"
|
||||||
|
collection="URL"
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
const GH_Repo = "MedzikUser/go-pingbot"
|
const GH_Repo = "MedzikUser/go-pingbot"
|
||||||
var Version = "dev"
|
|
||||||
|
var (
|
||||||
|
Version = "dev"
|
||||||
|
Build = ""
|
||||||
|
StartTime time.Time
|
||||||
|
)
|
||||||
|
|
|
@ -6,7 +6,9 @@ import (
|
||||||
_ "github.com/joho/godotenv/autoload"
|
_ "github.com/joho/godotenv/autoload"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mongo
|
var (
|
||||||
var Mongo_URI = os.Getenv("MONGODB_URI")
|
// mongo
|
||||||
var Mongo_DB = os.Getenv("MONGODB_DB")
|
Mongo_URI = os.Getenv("MONGODB_URI")
|
||||||
var Mongo_Collection = os.Getenv("MONGODB_COLLECTION")
|
Mongo_DB = os.Getenv("MONGODB_DB")
|
||||||
|
Mongo_Collection = os.Getenv("MONGODB_COLLECTION")
|
||||||
|
)
|
||||||
|
|
3
main.go
3
main.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gitlab.com/gaming0skar123/go/pingbot/backend"
|
"gitlab.com/gaming0skar123/go/pingbot/backend"
|
||||||
"gitlab.com/gaming0skar123/go/pingbot/common"
|
"gitlab.com/gaming0skar123/go/pingbot/common"
|
||||||
|
@ -41,5 +42,7 @@ func main() {
|
||||||
log.Warn("Auto Update -> Disabled")
|
log.Warn("Auto Update -> Disabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.StartTime = time.Now()
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/struCoder/pidusage"
|
"github.com/struCoder/pidusage"
|
||||||
|
@ -52,14 +54,72 @@ func Status(c *gin.Context) {
|
||||||
"v": json{
|
"v": json{
|
||||||
"go": runtime.Version(),
|
"go": runtime.Version(),
|
||||||
"release": config.Version,
|
"release": config.Version,
|
||||||
|
"build": config.Build,
|
||||||
},
|
},
|
||||||
"node": json{
|
"node": json{
|
||||||
"cluster": config.Toml.Cluster.ID,
|
"cluster": config.Toml.Cluster.ID,
|
||||||
"node": config.Toml.Cluster.Node,
|
"node": config.Toml.Cluster.Node,
|
||||||
|
//"uptime": time.Since(config.StartTime).String(),
|
||||||
|
"uptime": uptime(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func uptime() string {
|
||||||
|
t := time.Since(config.StartTime)
|
||||||
|
|
||||||
|
var uptime string
|
||||||
|
|
||||||
|
var (
|
||||||
|
y int
|
||||||
|
d int
|
||||||
|
)
|
||||||
|
|
||||||
|
h := round(t.Hours())
|
||||||
|
m := round(t.Minutes())
|
||||||
|
s := round(t.Seconds())
|
||||||
|
|
||||||
|
for h/24 > 0 {
|
||||||
|
d++
|
||||||
|
h -= 24
|
||||||
|
}
|
||||||
|
|
||||||
|
for d/365 > 0 {
|
||||||
|
y++
|
||||||
|
d -= 365
|
||||||
|
}
|
||||||
|
|
||||||
|
if y > 0 {
|
||||||
|
uptime += strconv.Itoa(y) + "y "
|
||||||
|
}
|
||||||
|
|
||||||
|
if d > 0 {
|
||||||
|
uptime += strconv.Itoa(d) + "d "
|
||||||
|
}
|
||||||
|
|
||||||
|
if h > 0 {
|
||||||
|
uptime += strconv.Itoa(h) + "h "
|
||||||
|
}
|
||||||
|
|
||||||
|
if m > 0 {
|
||||||
|
uptime += strconv.Itoa(m-(round(t.Hours())*60)) + "m "
|
||||||
|
}
|
||||||
|
|
||||||
|
if s > 0 {
|
||||||
|
uptime += strconv.Itoa(s-(m*60)) + "s"
|
||||||
|
}
|
||||||
|
|
||||||
|
return uptime
|
||||||
|
}
|
||||||
|
|
||||||
|
func round(val float64) int {
|
||||||
|
if val < 0 {
|
||||||
|
return int(val - 1.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return int(val)
|
||||||
|
}
|
||||||
|
|
||||||
func mb(b uint64) string {
|
func mb(b uint64) string {
|
||||||
return fmt.Sprintf("%d MB", b/1000/1000)
|
return fmt.Sprintf("%d MB", b/1000/1000)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue