Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
add option to configure stat interval
Browse files Browse the repository at this point in the history
  • Loading branch information
g0rbe committed Mar 31, 2023
1 parent d5f0e0b commit a90d103
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type conf struct {
SSLKey string `yaml:"SSLKey"`
LogErrorOnly bool `yaml:"LogErrorOnly"`
EnableStatAPI bool `yaml:"EnableStatAPI"`
StatAPIWait int `yaml:"StatAPIWait"`
}

var (
Expand All @@ -25,6 +26,7 @@ var (
SSLKey string
LogErrorOnly bool
EnableStatAPI bool
StatAPIWait int
)

// Parse parses the config file in path and gill the global variables.
Expand Down Expand Up @@ -60,5 +62,14 @@ func Parse(path string) error {
LogErrorOnly = c.LogErrorOnly
EnableStatAPI = c.EnableStatAPI

if c.StatAPIWait < 0 {
return fmt.Errorf("StatAPIWait is negative")
}
if c.StatAPIWait == 0 {
c.StatAPIWait = 1440
}

StatAPIWait = c.StatAPIWait

return nil
}
5 changes: 4 additions & 1 deletion server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ SSLKey:
LogErrorOnly: false

# Enable the /stat API. (default: false)
EnableStatAPI: false
EnableStatAPI: false

# Minutes to wait between two stat count (default: 1440)
StatAPIWait: 1440
3 changes: 2 additions & 1 deletion server/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/elmasy-com/columbus-sdk/db"
"github.com/elmasy-com/columbus-server/config"
"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -72,7 +73,7 @@ func UpdateStat() {
}

Current.Update(d, s)
time.Sleep(60 * time.Minute)
time.Sleep(time.Duration(config.StatAPIWait) * time.Minute)
}
}

Expand Down

0 comments on commit a90d103

Please sign in to comment.