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:
Medzik 2021-08-01 15:48:24 +00:00
parent 5263dddad2
commit 018a2e9b90
9 changed files with 82 additions and 8 deletions

3
.gitpod.Dockerfile vendored
View File

@ -3,7 +3,4 @@ FROM gitpod/workspace-full
# GoReleaser
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

View File

@ -15,6 +15,7 @@ builds:
ldflags:
- -s -w
- -X gitlab.com/gaming0skar123/go/pingbot/config.Version={{.RawVersion}}
- -X gitlab.com/gaming0skar123/go/pingbot/config.Build={{.Date}}
archives:
- format: tar.gz

View File

@ -13,3 +13,7 @@ check=2 # Check every two minutes
[cluster]
id=1 # Cluster ID
node=1 # Node ID
[mongodb]
database="PingBot"
collection="URL"

View File

@ -1,4 +1,11 @@
package config
import "time"
const GH_Repo = "MedzikUser/go-pingbot"
var Version = "dev"
var (
Version = "dev"
Build = ""
StartTime time.Time
)

View File

@ -6,7 +6,9 @@ import (
_ "github.com/joho/godotenv/autoload"
)
// mongo
var Mongo_URI = os.Getenv("MONGODB_URI")
var Mongo_DB = os.Getenv("MONGODB_DB")
var Mongo_Collection = os.Getenv("MONGODB_COLLECTION")
var (
// mongo
Mongo_URI = os.Getenv("MONGODB_URI")
Mongo_DB = os.Getenv("MONGODB_DB")
Mongo_Collection = os.Getenv("MONGODB_COLLECTION")
)

View File

@ -2,6 +2,7 @@ package main
import (
"sync"
"time"
"gitlab.com/gaming0skar123/go/pingbot/backend"
"gitlab.com/gaming0skar123/go/pingbot/common"
@ -41,5 +42,7 @@ func main() {
log.Warn("Auto Update -> Disabled")
}
config.StartTime = time.Now()
wg.Wait()
}

View File

@ -6,6 +6,8 @@ import (
"net/http"
"os"
"runtime"
"strconv"
"time"
"github.com/gin-gonic/gin"
"github.com/struCoder/pidusage"
@ -52,14 +54,72 @@ func Status(c *gin.Context) {
"v": json{
"go": runtime.Version(),
"release": config.Version,
"build": config.Build,
},
"node": json{
"cluster": config.Toml.Cluster.ID,
"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 {
return fmt.Sprintf("%d MB", b/1000/1000)
}