-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
329a845
commit 4e7162b
Showing
10 changed files
with
161 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/henrywhitaker3/prompage/internal/collector" | ||
"github.com/henrywhitaker3/prompage/internal/config" | ||
"github.com/henrywhitaker3/prompage/internal/querier" | ||
) | ||
|
||
type App struct { | ||
Config *config.Config | ||
Querier *querier.Querier | ||
Collector *collector.Collector | ||
} | ||
|
||
func NewApp(conf *config.Config, q *querier.Querier) *App { | ||
app := &App{ | ||
Config: conf, | ||
Querier: q, | ||
} | ||
|
||
app.Collector = collector.NewCollector(app.Querier, conf.Services) | ||
|
||
return app | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package collector | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/henrywhitaker3/prompage/internal/config" | ||
"github.com/henrywhitaker3/prompage/internal/querier" | ||
) | ||
|
||
type Result struct { | ||
// The service the result corresponds to | ||
Service config.Service | ||
// Whether the collection was successful or not | ||
Success bool | ||
// The boolean result of the main service query | ||
Status bool | ||
} | ||
|
||
type Collector struct { | ||
q *querier.Querier | ||
svcs []config.Service | ||
} | ||
|
||
func NewCollector(q *querier.Querier, svcs []config.Service) *Collector { | ||
return &Collector{ | ||
q: q, | ||
svcs: svcs, | ||
} | ||
} | ||
|
||
func (c *Collector) Collect(ctx context.Context) []Result { | ||
results := []Result{} | ||
|
||
for _, svc := range c.svcs { | ||
res := Result{ | ||
Service: svc, | ||
} | ||
log.Printf("collecting metrics for %s\n", svc.Name) | ||
|
||
status, err := c.q.Status(ctx, svc.Query) | ||
if err != nil { | ||
log.Printf("ERROR - Failed to scrape status metric for %s query %s: %s", svc.Name, svc.Query.Name, err) | ||
res.Success = false | ||
res.Status = false | ||
results = append(results, res) | ||
continue | ||
} | ||
|
||
res.Success = true | ||
res.Status = status | ||
results = append(results, res) | ||
} | ||
|
||
return results | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package http | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/henrywhitaker3/prompage/internal/app" | ||
"github.com/henrywhitaker3/prompage/internal/config" | ||
"github.com/henrywhitaker3/prompage/internal/querier" | ||
) | ||
|
||
type Result struct { | ||
Query config.Query | ||
Status bool | ||
} | ||
|
||
type ResultCache struct { | ||
mu *sync.Mutex | ||
querier *querier.Querier | ||
results map[string][]Result | ||
} | ||
|
||
func NewResultCache(app *app.App) *ResultCache { | ||
return &ResultCache{ | ||
mu: &sync.Mutex{}, | ||
querier: app.Querier, | ||
results: map[string][]Result{}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters