diff --git a/downdetector-exporter.go b/downdetector-exporter.go index 6ed4d88..b21d60d 100644 --- a/downdetector-exporter.go +++ b/downdetector-exporter.go @@ -37,7 +37,7 @@ var ( lg = kitlog.NewLogfmtLogger(os.Stdout) // fields for metrics request. If expanded, struct CompanySet needs to be expanded accordingly - fieldsToReturn = []string{"id", "name", "slug", "baseline_current", "country_iso", "stats_60", "status"} + fieldsToReturn = []string{"id", "name", "slug", "baseline_current", "country_iso", "stats_24", "stats_60", "status"} fieldsToReturnSearch = []string{"id", "name", "slug", "country_iso"} token Token @@ -99,6 +99,10 @@ type CompanySet struct { BaselineCurrent int `json:"baseline_current"` // Stats60 is the current metrics of mentions Stats60 int `json:"stats_60"` + // IgnoreStats24 is the statistics over the last 24h in 15 minute buckets. + IgnoreStats24 []int `json:"stats_24"` + // Stats15 is the number of reports over the last 15 + Stats15 int `json:"-"` // NumStatus needs to be filled in programmatically from IgnoreStatus value so it can be used as metric NumStatus int `json:"-"` } @@ -490,6 +494,8 @@ func getMetrics(companyIDs string, searchString string) { default: companySet.NumStatus = -1 } + // get last value from Stats24 array + companySet.Stats15 = companySet.IgnoreStats24[len(companySet.IgnoreStats24)-1] // Debugging output level.Debug(lg).Log("msg", fmt.Sprintf("")) @@ -503,6 +509,7 @@ func getMetrics(companyIDs string, searchString string) { level.Debug(lg).Log("msg", fmt.Sprintf("===== Metrics =====")) level.Debug(lg).Log("msg", fmt.Sprintf("Current Baseline: %d", companySet.BaselineCurrent)) level.Debug(lg).Log("msg", fmt.Sprintf("Stats60: %d", companySet.Stats60)) + level.Debug(lg).Log("msg", fmt.Sprintf("Stats15: %d", companySet.Stats15)) level.Debug(lg).Log("msg", fmt.Sprintf("Status: %d", companySet.NumStatus)) // create empty array to hold labels diff --git a/grafana_dashboard.json b/grafana_dashboard.json index 0632cbd..ae2d941 100644 --- a/grafana_dashboard.json +++ b/grafana_dashboard.json @@ -159,6 +159,12 @@ "interval": "", "legendFormat": "Stats60 {{ name }} {{countryiso}}", "refId": "B" + }, + { + "expr": "avg(dd_Stats15{id=~\"[[id]]\"}) by (name,countryiso)", + "interval": "", + "legendFormat": "Stats15 {{ name }} {{countryiso}}", + "refId": "C" } ], "thresholds": [],