Instrument with less labels and more focused metrics
This commit is contained in:
parent
455fb65e77
commit
ab9c5281a5
2 changed files with 33 additions and 11 deletions
|
@ -16,8 +16,10 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type promInst struct {
|
type promInst struct {
|
||||||
visits *prometheus.CounterVec
|
visits *prometheus.CounterVec
|
||||||
reqDur *prometheus.HistogramVec
|
reqDur *prometheus.HistogramVec
|
||||||
|
search *prometheus.CounterVec
|
||||||
|
searchDur *prometheus.GaugeVec
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init() Instrument {
|
func Init() Instrument {
|
||||||
|
@ -28,7 +30,7 @@ func Init() Instrument {
|
||||||
Name: "trantor_visits_total",
|
Name: "trantor_visits_total",
|
||||||
Help: "Number of visits.",
|
Help: "Number of visits.",
|
||||||
},
|
},
|
||||||
[]string{"section", "id", "search", "fmt"},
|
[]string{"section"},
|
||||||
)
|
)
|
||||||
reqDur := prometheus.NewHistogramVec(
|
reqDur := prometheus.NewHistogramVec(
|
||||||
prometheus.HistogramOpts{
|
prometheus.HistogramOpts{
|
||||||
|
@ -37,13 +39,31 @@ func Init() Instrument {
|
||||||
},
|
},
|
||||||
[]string{"section"},
|
[]string{"section"},
|
||||||
)
|
)
|
||||||
|
search := prometheus.NewCounterVec(
|
||||||
|
prometheus.CounterOpts{
|
||||||
|
Name: "trantor_search_total",
|
||||||
|
Help: "Number of searches.",
|
||||||
|
},
|
||||||
|
[]string{"search"},
|
||||||
|
)
|
||||||
|
searchDur := prometheus.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "trantor_search_duration_seconds",
|
||||||
|
Help: "Duration of the search in seconds.",
|
||||||
|
},
|
||||||
|
[]string{"search"},
|
||||||
|
)
|
||||||
|
|
||||||
prometheus.MustRegister(visits)
|
prometheus.MustRegister(visits)
|
||||||
prometheus.MustRegister(reqDur)
|
prometheus.MustRegister(reqDur)
|
||||||
|
prometheus.MustRegister(search)
|
||||||
|
prometheus.MustRegister(searchDur)
|
||||||
|
|
||||||
return &promInst{
|
return &promInst{
|
||||||
visits: visits,
|
visits: visits,
|
||||||
reqDur: reqDur,
|
reqDur: reqDur,
|
||||||
|
search: search,
|
||||||
|
searchDur: searchDur,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +76,8 @@ func promHandle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (in promInst) Request(req RequestData) {
|
func (in promInst) Request(req RequestData) {
|
||||||
in.visits.WithLabelValues(req.Section, req.ID, req.Search, req.Fmt).Inc()
|
in.visits.WithLabelValues(req.Section).Inc()
|
||||||
in.reqDur.WithLabelValues(req.Section).Observe(req.Duration.Seconds())
|
in.reqDur.WithLabelValues(req.Section).Observe(req.Duration.Seconds())
|
||||||
|
in.search.WithLabelValues(req.Search).Inc()
|
||||||
|
in.searchDur.WithLabelValues(req.Search).Set(req.Duration.Seconds())
|
||||||
}
|
}
|
||||||
|
|
10
lib/stats.go
10
lib/stats.go
|
@ -120,11 +120,11 @@ func (sg StatsGatherer) worker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
sg.instrument.Request(instrument.RequestData{
|
sg.instrument.Request(instrument.RequestData{
|
||||||
Section: section,
|
Section: section,
|
||||||
ID: id,
|
ID: id,
|
||||||
Search: search,
|
Search: search,
|
||||||
Fmt: fmt,
|
Fmt: fmt,
|
||||||
Duration: req.duration
|
Duration: req.duration,
|
||||||
})
|
})
|
||||||
switch section {
|
switch section {
|
||||||
case "download":
|
case "download":
|
||||||
|
|
Reference in a new issue