Skip to content

Commit 8548f60

Browse files
authored
Merge pull request #7 from nohn/stats_24
Fetch Stats15 value from Stats24[] as a workaround for #6 without querying the /status endpoint
2 parents 7e555c3 + 6a2a5eb commit 8548f60

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

downdetector-exporter.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var (
3737
lg = kitlog.NewLogfmtLogger(os.Stdout)
3838

3939
// fields for metrics request. If expanded, struct CompanySet needs to be expanded accordingly
40-
fieldsToReturn = []string{"id", "name", "slug", "baseline_current", "country_iso", "stats_60", "status"}
40+
fieldsToReturn = []string{"id", "name", "slug", "baseline_current", "country_iso", "stats_24", "stats_60", "status"}
4141
fieldsToReturnSearch = []string{"id", "name", "slug", "country_iso"}
4242

4343
token Token
@@ -99,6 +99,10 @@ type CompanySet struct {
9999
BaselineCurrent int `json:"baseline_current"`
100100
// Stats60 is the current metrics of mentions
101101
Stats60 int `json:"stats_60"`
102+
// IgnoreStats24 is the statistics over the last 24h in 15 minute buckets.
103+
IgnoreStats24 []int `json:"stats_24"`
104+
// Stats15 is the number of reports over the last 15
105+
Stats15 int `json:"-"`
102106
// NumStatus needs to be filled in programmatically from IgnoreStatus value so it can be used as metric
103107
NumStatus int `json:"-"`
104108
}
@@ -490,6 +494,8 @@ func getMetrics(companyIDs string, searchString string) {
490494
default:
491495
companySet.NumStatus = -1
492496
}
497+
// get last value from Stats24 array
498+
companySet.Stats15 = companySet.IgnoreStats24[len(companySet.IgnoreStats24)-1]
493499

494500
// Debugging output
495501
level.Debug(lg).Log("msg", fmt.Sprintf(""))
@@ -503,6 +509,7 @@ func getMetrics(companyIDs string, searchString string) {
503509
level.Debug(lg).Log("msg", fmt.Sprintf("===== Metrics ====="))
504510
level.Debug(lg).Log("msg", fmt.Sprintf("Current Baseline: %d", companySet.BaselineCurrent))
505511
level.Debug(lg).Log("msg", fmt.Sprintf("Stats60: %d", companySet.Stats60))
512+
level.Debug(lg).Log("msg", fmt.Sprintf("Stats15: %d", companySet.Stats15))
506513
level.Debug(lg).Log("msg", fmt.Sprintf("Status: %d", companySet.NumStatus))
507514

508515
// create empty array to hold labels

grafana_dashboard.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@
159159
"interval": "",
160160
"legendFormat": "Stats60 {{ name }} {{countryiso}}",
161161
"refId": "B"
162+
},
163+
{
164+
"expr": "avg(dd_Stats15{id=~\"[[id]]\"}) by (name,countryiso)",
165+
"interval": "",
166+
"legendFormat": "Stats15 {{ name }} {{countryiso}}",
167+
"refId": "C"
162168
}
163169
],
164170
"thresholds": [],

0 commit comments

Comments
 (0)