Skip to content

Commit

Permalink
Merge pull request #7 from nohn/stats_24
Browse files Browse the repository at this point in the history
Fetch Stats15 value from Stats24[] as a workaround for #6 without querying the /status endpoint
  • Loading branch information
kic68 authored Nov 5, 2023
2 parents 7e555c3 + 6a2a5eb commit 8548f60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion downdetector-exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:"-"`
}
Expand Down Expand Up @@ -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(""))
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions grafana_dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down

0 comments on commit 8548f60

Please sign in to comment.