mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
Add max concurrent and current queries engine metrics (#2326)
* Add max concurrent and current queries engine metrics This commit adds two metrics to the promql/engine: the number of max concurrent queries, as configured by the flag, and the number of current queries being served+blocked in the engine.
This commit is contained in:
parent
f9e581907a
commit
c43dfaba1c
|
@ -21,6 +21,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
@ -31,12 +32,35 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
namespace = "prometheus"
|
||||||
|
subsystem = "engine"
|
||||||
|
|
||||||
// The largest SampleValue that can be converted to an int64 without overflow.
|
// The largest SampleValue that can be converted to an int64 without overflow.
|
||||||
maxInt64 model.SampleValue = 9223372036854774784
|
maxInt64 model.SampleValue = 9223372036854774784
|
||||||
// The smallest SampleValue that can be converted to an int64 without underflow.
|
// The smallest SampleValue that can be converted to an int64 without underflow.
|
||||||
minInt64 model.SampleValue = -9223372036854775808
|
minInt64 model.SampleValue = -9223372036854775808
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
currentQueries = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "queries",
|
||||||
|
Help: "The current number of queries being executed or waiting.",
|
||||||
|
})
|
||||||
|
maxConcurrentQueries = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "queries_concurrent_max",
|
||||||
|
Help: "The max number of concurrent queries.",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
prometheus.MustRegister(currentQueries)
|
||||||
|
prometheus.MustRegister(maxConcurrentQueries)
|
||||||
|
}
|
||||||
|
|
||||||
// convertibleToInt64 returns true if v does not over-/underflow an int64.
|
// convertibleToInt64 returns true if v does not over-/underflow an int64.
|
||||||
func convertibleToInt64(v model.SampleValue) bool {
|
func convertibleToInt64(v model.SampleValue) bool {
|
||||||
return v <= maxInt64 && v >= minInt64
|
return v <= maxInt64 && v >= minInt64
|
||||||
|
@ -247,6 +271,7 @@ func NewEngine(queryable Queryable, o *EngineOptions) *Engine {
|
||||||
if o == nil {
|
if o == nil {
|
||||||
o = DefaultEngineOptions
|
o = DefaultEngineOptions
|
||||||
}
|
}
|
||||||
|
maxConcurrentQueries.Set(float64(o.MaxConcurrentQueries))
|
||||||
return &Engine{
|
return &Engine{
|
||||||
queryable: queryable,
|
queryable: queryable,
|
||||||
gate: newQueryGate(o.MaxConcurrentQueries),
|
gate: newQueryGate(o.MaxConcurrentQueries),
|
||||||
|
@ -331,6 +356,8 @@ func (ng *Engine) newTestQuery(f func(context.Context) error) Query {
|
||||||
// At this point per query only one EvalStmt is evaluated. Alert and record
|
// At this point per query only one EvalStmt is evaluated. Alert and record
|
||||||
// statements are not handled by the Engine.
|
// statements are not handled by the Engine.
|
||||||
func (ng *Engine) exec(ctx context.Context, q *query) (model.Value, error) {
|
func (ng *Engine) exec(ctx context.Context, q *query) (model.Value, error) {
|
||||||
|
currentQueries.Inc()
|
||||||
|
defer currentQueries.Dec()
|
||||||
ctx, cancel := context.WithTimeout(ctx, ng.options.Timeout)
|
ctx, cancel := context.WithTimeout(ctx, ng.options.Timeout)
|
||||||
q.cancel = cancel
|
q.cancel = cancel
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue