Add time interval
This commit is contained in:
@@ -23,6 +23,7 @@ var Logger *log.Logger
|
|||||||
type CachetConfig struct {
|
type CachetConfig struct {
|
||||||
APIUrl string `json:"api_url"`
|
APIUrl string `json:"api_url"`
|
||||||
APIToken string `json:"api_token"`
|
APIToken string `json:"api_token"`
|
||||||
|
Interval int64 `json:"interval"`
|
||||||
Monitors []*Monitor `json:"monitors"`
|
Monitors []*Monitor `json:"monitors"`
|
||||||
SystemName string `json:"system_name"`
|
SystemName string `json:"system_name"`
|
||||||
LogPath string `json:"log_path"`
|
LogPath string `json:"log_path"`
|
||||||
@@ -107,7 +108,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := log.Llongfile|log.Ldate|log.Ltime
|
flags := log.Llongfile | log.Ldate | log.Ltime
|
||||||
if len(os.Getenv("DEVELOPMENT")) > 0 {
|
if len(os.Getenv("DEVELOPMENT")) > 0 {
|
||||||
flags = 0
|
flags = 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"api_url": "https://demo.cachethq.io/api",
|
"api_url": "https://demo.cachethq.io/api",
|
||||||
"api_token": "9yMHsdioQosnyVK4iCVR",
|
"api_token": "9yMHsdioQosnyVK4iCVR",
|
||||||
|
"interval": 60,
|
||||||
"monitors": [
|
"monitors": [
|
||||||
{
|
{
|
||||||
"name": "nodegear frontend",
|
"name": "nodegear frontend",
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -9,7 +9,7 @@ func main() {
|
|||||||
config := cachet.Config
|
config := cachet.Config
|
||||||
log := cachet.Logger
|
log := cachet.Logger
|
||||||
|
|
||||||
log.Printf("System: %s, API: %s\n", config.SystemName, config.APIUrl)
|
log.Printf("System: %s, Interval: %d second(s), API: %s\n", config.SystemName, config.Interval, config.APIUrl)
|
||||||
log.Printf("Starting %d monitors:\n", len(config.Monitors))
|
log.Printf("Starting %d monitors:\n", len(config.Monitors))
|
||||||
for _, mon := range config.Monitors {
|
for _, mon := range config.Monitors {
|
||||||
log.Printf(" %s: GET %s & Expect HTTP %d\n", mon.Name, mon.URL, mon.ExpectedStatusCode)
|
log.Printf(" %s: GET %s & Expect HTTP %d\n", mon.Name, mon.URL, mon.ExpectedStatusCode)
|
||||||
@@ -20,7 +20,7 @@ func main() {
|
|||||||
|
|
||||||
log.Println()
|
log.Println()
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Second)
|
ticker := time.NewTicker(time.Duration(config.Interval)*time.Second)
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
for _, mon := range config.Monitors {
|
for _, mon := range config.Monitors {
|
||||||
go mon.Run()
|
go mon.Run()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Features
|
|||||||
--------
|
--------
|
||||||
|
|
||||||
- [x] Creates & Resolves Incidents
|
- [x] Creates & Resolves Incidents
|
||||||
- [x] Posts monitor lag every second
|
- [x] Posts monitor lag every second * config.Interval
|
||||||
- [x] Updates Component to Partial Outage
|
- [x] Updates Component to Partial Outage
|
||||||
- [x] Updates Component to Major Outage if in Partial Outage
|
- [x] Updates Component to Major Outage if in Partial Outage
|
||||||
- [x] Can be run on multiple servers and geo regions
|
- [x] Can be run on multiple servers and geo regions
|
||||||
@@ -32,6 +32,7 @@ Configuration
|
|||||||
{
|
{
|
||||||
"api_url": "https://demo.cachethq.io/api",
|
"api_url": "https://demo.cachethq.io/api",
|
||||||
"api_token": "9yMHsdioQosnyVK4iCVR",
|
"api_token": "9yMHsdioQosnyVK4iCVR",
|
||||||
|
"interval": 60,
|
||||||
"monitors": [
|
"monitors": [
|
||||||
{
|
{
|
||||||
"name": "nodegear frontend",
|
"name": "nodegear frontend",
|
||||||
|
|||||||
Reference in New Issue
Block a user