Add request_duration_seconds metric #72
19
metrics.go
19
metrics.go
@ -87,19 +87,22 @@ func (mh *MetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (mh *MetricsHandler) updateMetrics() {
|
func (mh *MetricsHandler) updateMetrics() {
|
||||||
// Update metricURLsTotalGauge
|
// Update metricURLsTotalGauge
|
||||||
for state := db.PasteStateUndef; state <= db.PasteStateDeleted; state++ {
|
results := make([](struct {
|
||||||
for ty := db.PasteTypeUndef; ty <= db.PasteTypeFileUpload; ty++ {
|
Type db.PasteType
|
||||||
var count int64
|
State db.PasteState
|
||||||
query := mh.db.Unscoped().Model(&db.Paste{}).Where("type = ? AND state = ?", ty, state).Count(&count)
|
Count float64
|
||||||
|
}), 0)
|
||||||
|
query := mh.db.Unscoped().Model(&db.Paste{}).Select("type", "state", "COUNT(*) as count").Group("type, state").Find(&results)
|
||||||
if err := query.Error; err != nil {
|
if err := query.Error; err != nil {
|
||||||
log.Printf("error: %v", errors.Wrap(err, "fetching pastes_total metric"))
|
log.Printf("error: %v", errors.Wrap(err, "fetching pastes_total metric"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
metricURLsTotalGauge.Reset()
|
||||||
|
for _, r := range results {
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"state": state.String(),
|
"type": r.Type.String(),
|
||||||
"type": ty.String(),
|
"state": r.State.String(),
|
||||||
}
|
|
||||||
metricURLsTotalGauge.With(labels).Set(float64(count))
|
|
||||||
}
|
}
|
||||||
|
metricURLsTotalGauge.With(labels).Set(r.Count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user