Skip to content
Permalink
Browse files

Adding badge, differentiate repo information fetching and service che…

…cking
  • Loading branch information...
Depado committed Apr 1, 2016
1 parent e8817f0 commit e562c21c878359a267adcba6de6357f563582a67
Showing with 37 additions and 24 deletions.
  1. +2 −0 README.md
  2. +13 −5 conf/conf.go
  3. +1 −1 main.go
  4. +21 −18 models/service.go
@@ -1,4 +1,6 @@
# gomonit
[![Go Report Card](https://goreportcard.com/badge/github.com/Depado/gomonit)](https://goreportcard.com/report/github.com/Depado/gomonit)

Small soft to check if your services are running, providing a web interface.

Using gin and semantic-ui
@@ -12,7 +12,8 @@ type Configuration struct {
Listen string
Debug bool
CIURL string
UpdateInterval time.Duration
ServiceInterval time.Duration
RepoInterval time.Duration
GithubOAuthToken string
Services []service
}
@@ -32,7 +33,8 @@ type unparsed struct {
Listen string `yaml:"listen"`
Debug bool `yaml:"debug"`
CIURL string `yaml:"ci_url"`
UpdateInterval string `yaml:"update_interval"`
ServiceInterval string `yaml:"service_interval"`
RepoInterval string `yaml:"repo_interval"`
GithubOAuthToken string `yaml:"github_oauth_token"`
Services []service
}
@@ -44,22 +46,28 @@ var C Configuration
func Load(fp string) error {
var err error
var u unparsed
var d time.Duration
var sd time.Duration
var rd time.Duration

conf, err := ioutil.ReadFile(fp)
if err != nil {
return err
}
if err = yaml.Unmarshal(conf, &u); err != nil {
return err
}
if d, err = time.ParseDuration(u.UpdateInterval); err != nil {
if sd, err = time.ParseDuration(u.ServiceInterval); err != nil {
return err
}
if rd, err = time.ParseDuration(u.RepoInterval); err != nil {
return err
}
C = Configuration{
Listen: u.Listen,
Debug: u.Debug,
CIURL: u.CIURL,
UpdateInterval: d,
ServiceInterval: sd,
RepoInterval: rd,
Services: u.Services,
GithubOAuthToken: u.GithubOAuthToken,
}
@@ -23,7 +23,7 @@ func main() {
log.Fatal(err)
}
// Starting monitoring of services
go models.All.Monitor(conf.C.UpdateInterval)
go models.All.Monitor()

// Gin initialization
if !conf.C.Debug {
@@ -138,31 +138,34 @@ func (s *Service) FetchRepoInfos() {
s.Description = repo.Description
}

// Check updates the status of the Host
func (s *Service) Check() {
if s.URL != "" {
s.FetchStatus()
}
if s.BuildAPI != "" {
go s.FetchBuilds()
}
if s.RepoURL != "" {
go s.FetchCommits()
go s.FetchRepoInfos()
}
}

// Services represents a list of services
type Services []*Service

// Monitor allows to monitor Services every interval delay
func (ss Services) Monitor(interval time.Duration) {
tc := time.NewTicker(interval)
func (ss Services) Monitor() {
go func() {
rtc := time.NewTicker(conf.C.RepoInterval)
for {
for _, s := range ss {
if s.BuildAPI != "" {
go s.FetchBuilds()
}
if s.RepoURL != "" {
go s.FetchCommits()
go s.FetchRepoInfos()
}
}
<-rtc.C
}
}()
stc := time.NewTicker(conf.C.ServiceInterval)
for {
for _, s := range ss {
go s.Check()
if s.URL != "" {
s.FetchStatus()
}
}
<-tc.C
<-stc.C
}
}

0 comments on commit e562c21

Please sign in to comment.
You can’t perform that action at this time.