2019-05-22 23:23:23 +02:00
package main
2019-05-22 23:16:55 +02:00
import (
2021-07-07 16:04:23 +02:00
"embed"
2020-06-30 23:02:02 +02:00
"errors"
2019-05-22 23:16:55 +02:00
"flag"
2019-08-23 08:46:45 +02:00
"fmt"
2019-05-22 23:16:55 +02:00
"net/http"
2020-05-16 10:59:30 +02:00
"os"
2019-05-22 23:16:55 +02:00
"strings"
"time"
2020-09-10 23:29:26 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/graphite"
2019-05-22 23:16:55 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/netstorage"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/prometheus"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/promql"
2020-09-22 00:21:20 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmselect/searchutils"
2019-05-22 23:23:23 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/auth"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
2020-08-11 21:54:13 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
2020-02-10 12:26:18 +01:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/envflag"
2019-05-22 23:23:23 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
2019-05-22 23:16:55 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
2019-05-22 23:23:23 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil"
2020-02-10 12:03:52 +01:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
2021-02-16 22:25:27 +01:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/tenantmetrics"
2019-05-28 16:17:19 +02:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/timerpool"
2019-05-22 23:16:55 +02:00
"github.com/VictoriaMetrics/metrics"
)
var (
2019-05-22 23:23:23 +02:00
httpListenAddr = flag . String ( "httpListenAddr" , ":8481" , "Address to listen for http connections" )
cacheDataPath = flag . String ( "cacheDataPath" , "" , "Path to directory for cache files. Cache isn't saved if empty" )
2020-01-17 14:43:47 +01:00
maxConcurrentRequests = flag . Int ( "search.maxConcurrentRequests" , getDefaultMaxConcurrentRequests ( ) , "The maximum number of concurrent search requests. " +
2020-02-04 14:46:13 +01:00
"It shouldn't be high, since a single request can saturate all the CPU cores. See also -search.maxQueueDuration" )
2020-09-22 00:21:20 +02:00
maxQueueDuration = flag . Duration ( "search.maxQueueDuration" , 10 * time . Second , "The maximum time the request waits for execution when -search.maxConcurrentRequests " +
"limit is reached; see also -search.maxQueryDuration" )
2021-07-02 14:02:24 +02:00
minScrapeInterval = flag . Duration ( "dedup.minScrapeInterval" , 0 , "Leave only the first sample in every time series per each discrete interval " +
"equal to -dedup.minScrapeInterval > 0. See https://docs.victoriametrics.com/#deduplication for details" )
2021-06-18 18:04:42 +02:00
resetCacheAuthKey = flag . String ( "search.resetCacheAuthKey" , "" , "Optional authKey for resetting rollup cache via /internal/resetRollupResultCache call" )
logSlowQueryDuration = flag . Duration ( "search.logSlowQueryDuration" , 5 * time . Second , "Log queries with execution time exceeding this value. Zero disables slow query logging" )
storageNodes = flagutil . NewArray ( "storageNode" , "Addresses of vmstorage nodes; usage: -storageNode=vmstorage-host1:8401 -storageNode=vmstorage-host2:8401" )
2019-05-22 23:16:55 +02:00
)
2021-06-18 18:04:42 +02:00
var slowQueries = metrics . NewCounter ( ` vm_slow_queries_total ` )
2020-01-17 14:43:47 +01:00
func getDefaultMaxConcurrentRequests ( ) int {
2020-12-08 19:49:32 +01:00
n := cgroup . AvailableCPUs ( )
2020-01-17 14:43:47 +01:00
if n <= 4 {
n *= 2
}
if n > 16 {
// A single request can saturate all the CPU cores, so there is no sense
// in allowing higher number of concurrent requests - they will just contend
// for unavailable CPU time.
n = 16
}
return n
}
2019-05-22 23:23:23 +02:00
func main ( ) {
2020-05-16 10:59:30 +02:00
// Write flags and help message to stdout, since it is easier to grep or pipe.
flag . CommandLine . SetOutput ( os . Stdout )
2020-12-03 20:40:30 +01:00
flag . Usage = usage
2020-02-10 12:26:18 +01:00
envflag . Parse ( )
2019-05-22 23:23:23 +02:00
buildinfo . Init ( )
logger . Init ( )
2019-07-20 09:21:59 +02:00
logger . Infof ( "starting netstorage at storageNodes %s" , * storageNodes )
2019-05-22 23:23:23 +02:00
startTime := time . Now ( )
2020-02-10 12:03:52 +01:00
storage . SetMinScrapeIntervalForDeduplication ( * minScrapeInterval )
2019-06-18 09:26:44 +02:00
if len ( * storageNodes ) == 0 {
2019-07-20 09:21:59 +02:00
logger . Fatalf ( "missing -storageNode arg" )
2019-05-22 23:23:23 +02:00
}
2019-06-18 09:26:44 +02:00
netstorage . InitStorageNodes ( * storageNodes )
2020-01-22 17:27:44 +01:00
logger . Infof ( "started netstorage in %.3f seconds" , time . Since ( startTime ) . Seconds ( ) )
2019-05-22 23:23:23 +02:00
if len ( * cacheDataPath ) > 0 {
tmpDataPath := * cacheDataPath + "/tmp"
fs . RemoveDirContents ( tmpDataPath )
netstorage . InitTmpBlocksDir ( tmpDataPath )
promql . InitRollupResultCache ( * cacheDataPath + "/rollupResult" )
} else {
netstorage . InitTmpBlocksDir ( "" )
promql . InitRollupResultCache ( "" )
}
2019-05-22 23:16:55 +02:00
concurrencyCh = make ( chan struct { } , * maxConcurrentRequests )
2019-05-22 23:23:23 +02:00
go func ( ) {
httpserver . Serve ( * httpListenAddr , requestHandler )
} ( )
2019-05-22 23:16:55 +02:00
2019-05-22 23:23:23 +02:00
sig := procutil . WaitForSigterm ( )
logger . Infof ( "service received signal %s" , sig )
app/vmstorage: add missing shutdown for http server on graceful shutdown
This could result in the following panic during graceful shutdown when `/metrics` page is requested:
http: panic serving 10.101.66.5:57366: runtime error: invalid memory address or nil pointer dereference
goroutine 2050 [running]:
net/http.(*conn).serve.func1(0xc00ef22000)
net/http/server.go:1772 +0x139
panic(0xa0fc00, 0xe91d80)
runtime/panic.go:973 +0x3e3
github.com/VictoriaMetrics/VictoriaMetrics/lib/workingsetcache.(*Cache).UpdateStats(0x0, 0xc0000516c8)
github.com/VictoriaMetrics/VictoriaMetrics/lib/workingsetcache/cache.go:224 +0x37
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage.(*indexDB).UpdateMetrics(0xc00b931d00, 0xc02c41acf8)
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage/index_db.go:258 +0x9f
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage.(*Storage).UpdateMetrics(0xc0000bc7e0, 0xc02c41ac00)
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage/storage.go:413 +0x4c5
main.registerStorageMetrics.func1(0x0)
github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage/main.go:186 +0xd9
main.registerStorageMetrics.func3(0xc00008c380)
github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage/main.go:196 +0x26
main.registerStorageMetrics.func7(0xc)
github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage/main.go:211 +0x26
github.com/VictoriaMetrics/metrics.(*Gauge).marshalTo(0xc000010148, 0xaa407d, 0x20, 0xb50d60, 0xc005319890)
github.com/VictoriaMetrics/metrics@v1.11.2/gauge.go:38 +0x3f
github.com/VictoriaMetrics/metrics.(*Set).WritePrometheus(0xc000084300, 0x7fd56809c940, 0xc005319860)
github.com/VictoriaMetrics/metrics@v1.11.2/set.go:51 +0x1e1
github.com/VictoriaMetrics/metrics.WritePrometheus(0x7fd56809c940, 0xc005319860, 0xa16f01)
github.com/VictoriaMetrics/metrics@v1.11.2/metrics.go:42 +0x41
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver.writePrometheusMetrics(0x7fd56809c940, 0xc005319860)
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver/metrics.go:16 +0x44
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver.handlerWrapper(0xb5a120, 0xc005319860, 0xc005018f00, 0xc00002cc90)
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver/httpserver.go:154 +0x58d
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver.gzipHandler.func1(0xb5a120, 0xc005319860, 0xc005018f00)
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver/httpserver.go:119 +0x8e
net/http.HandlerFunc.ServeHTTP(0xc00002d110, 0xb5a660, 0xc0044141c0, 0xc005018f00)
net/http/server.go:2012 +0x44
net/http.serverHandler.ServeHTTP(0xc004414000, 0xb5a660, 0xc0044141c0, 0xc005018f00)
net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc00ef22000, 0xb5bf60, 0xc010532080)
net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
net/http/server.go:2933 +0x35c
2020-04-02 20:07:59 +02:00
logger . Infof ( "gracefully shutting down http service at %q" , * httpListenAddr )
2019-05-22 23:23:23 +02:00
startTime = time . Now ( )
if err := httpserver . Stop ( * httpListenAddr ) ; err != nil {
app/vmstorage: add missing shutdown for http server on graceful shutdown
This could result in the following panic during graceful shutdown when `/metrics` page is requested:
http: panic serving 10.101.66.5:57366: runtime error: invalid memory address or nil pointer dereference
goroutine 2050 [running]:
net/http.(*conn).serve.func1(0xc00ef22000)
net/http/server.go:1772 +0x139
panic(0xa0fc00, 0xe91d80)
runtime/panic.go:973 +0x3e3
github.com/VictoriaMetrics/VictoriaMetrics/lib/workingsetcache.(*Cache).UpdateStats(0x0, 0xc0000516c8)
github.com/VictoriaMetrics/VictoriaMetrics/lib/workingsetcache/cache.go:224 +0x37
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage.(*indexDB).UpdateMetrics(0xc00b931d00, 0xc02c41acf8)
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage/index_db.go:258 +0x9f
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage.(*Storage).UpdateMetrics(0xc0000bc7e0, 0xc02c41ac00)
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage/storage.go:413 +0x4c5
main.registerStorageMetrics.func1(0x0)
github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage/main.go:186 +0xd9
main.registerStorageMetrics.func3(0xc00008c380)
github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage/main.go:196 +0x26
main.registerStorageMetrics.func7(0xc)
github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage/main.go:211 +0x26
github.com/VictoriaMetrics/metrics.(*Gauge).marshalTo(0xc000010148, 0xaa407d, 0x20, 0xb50d60, 0xc005319890)
github.com/VictoriaMetrics/metrics@v1.11.2/gauge.go:38 +0x3f
github.com/VictoriaMetrics/metrics.(*Set).WritePrometheus(0xc000084300, 0x7fd56809c940, 0xc005319860)
github.com/VictoriaMetrics/metrics@v1.11.2/set.go:51 +0x1e1
github.com/VictoriaMetrics/metrics.WritePrometheus(0x7fd56809c940, 0xc005319860, 0xa16f01)
github.com/VictoriaMetrics/metrics@v1.11.2/metrics.go:42 +0x41
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver.writePrometheusMetrics(0x7fd56809c940, 0xc005319860)
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver/metrics.go:16 +0x44
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver.handlerWrapper(0xb5a120, 0xc005319860, 0xc005018f00, 0xc00002cc90)
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver/httpserver.go:154 +0x58d
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver.gzipHandler.func1(0xb5a120, 0xc005319860, 0xc005018f00)
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver/httpserver.go:119 +0x8e
net/http.HandlerFunc.ServeHTTP(0xc00002d110, 0xb5a660, 0xc0044141c0, 0xc005018f00)
net/http/server.go:2012 +0x44
net/http.serverHandler.ServeHTTP(0xc004414000, 0xb5a660, 0xc0044141c0, 0xc005018f00)
net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc00ef22000, 0xb5bf60, 0xc010532080)
net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
net/http/server.go:2933 +0x35c
2020-04-02 20:07:59 +02:00
logger . Fatalf ( "cannot stop http service: %s" , err )
2019-05-22 23:23:23 +02:00
}
app/vmstorage: add missing shutdown for http server on graceful shutdown
This could result in the following panic during graceful shutdown when `/metrics` page is requested:
http: panic serving 10.101.66.5:57366: runtime error: invalid memory address or nil pointer dereference
goroutine 2050 [running]:
net/http.(*conn).serve.func1(0xc00ef22000)
net/http/server.go:1772 +0x139
panic(0xa0fc00, 0xe91d80)
runtime/panic.go:973 +0x3e3
github.com/VictoriaMetrics/VictoriaMetrics/lib/workingsetcache.(*Cache).UpdateStats(0x0, 0xc0000516c8)
github.com/VictoriaMetrics/VictoriaMetrics/lib/workingsetcache/cache.go:224 +0x37
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage.(*indexDB).UpdateMetrics(0xc00b931d00, 0xc02c41acf8)
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage/index_db.go:258 +0x9f
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage.(*Storage).UpdateMetrics(0xc0000bc7e0, 0xc02c41ac00)
github.com/VictoriaMetrics/VictoriaMetrics/lib/storage/storage.go:413 +0x4c5
main.registerStorageMetrics.func1(0x0)
github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage/main.go:186 +0xd9
main.registerStorageMetrics.func3(0xc00008c380)
github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage/main.go:196 +0x26
main.registerStorageMetrics.func7(0xc)
github.com/VictoriaMetrics/VictoriaMetrics/app/vmstorage/main.go:211 +0x26
github.com/VictoriaMetrics/metrics.(*Gauge).marshalTo(0xc000010148, 0xaa407d, 0x20, 0xb50d60, 0xc005319890)
github.com/VictoriaMetrics/metrics@v1.11.2/gauge.go:38 +0x3f
github.com/VictoriaMetrics/metrics.(*Set).WritePrometheus(0xc000084300, 0x7fd56809c940, 0xc005319860)
github.com/VictoriaMetrics/metrics@v1.11.2/set.go:51 +0x1e1
github.com/VictoriaMetrics/metrics.WritePrometheus(0x7fd56809c940, 0xc005319860, 0xa16f01)
github.com/VictoriaMetrics/metrics@v1.11.2/metrics.go:42 +0x41
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver.writePrometheusMetrics(0x7fd56809c940, 0xc005319860)
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver/metrics.go:16 +0x44
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver.handlerWrapper(0xb5a120, 0xc005319860, 0xc005018f00, 0xc00002cc90)
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver/httpserver.go:154 +0x58d
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver.gzipHandler.func1(0xb5a120, 0xc005319860, 0xc005018f00)
github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver/httpserver.go:119 +0x8e
net/http.HandlerFunc.ServeHTTP(0xc00002d110, 0xb5a660, 0xc0044141c0, 0xc005018f00)
net/http/server.go:2012 +0x44
net/http.serverHandler.ServeHTTP(0xc004414000, 0xb5a660, 0xc0044141c0, 0xc005018f00)
net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc00ef22000, 0xb5bf60, 0xc010532080)
net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
net/http/server.go:2933 +0x35c
2020-04-02 20:07:59 +02:00
logger . Infof ( "successfully shut down http service in %.3f seconds" , time . Since ( startTime ) . Seconds ( ) )
2019-05-22 23:23:23 +02:00
logger . Infof ( "shutting down neststorage..." )
startTime = time . Now ( )
netstorage . Stop ( )
if len ( * cacheDataPath ) > 0 {
promql . StopRollupResultCache ( )
}
2020-01-22 17:27:44 +01:00
logger . Infof ( "successfully stopped netstorage in %.3f seconds" , time . Since ( startTime ) . Seconds ( ) )
2019-05-22 23:23:23 +02:00
2019-11-12 15:29:43 +01:00
fs . MustStopDirRemover ( )
2019-05-22 23:23:23 +02:00
logger . Infof ( "the vmselect has been stopped" )
2019-05-22 23:16:55 +02:00
}
2019-05-22 23:23:23 +02:00
var concurrencyCh chan struct { }
2019-08-05 17:27:50 +02:00
var (
concurrencyLimitReached = metrics . NewCounter ( ` vm_concurrent_select_limit_reached_total ` )
concurrencyLimitTimeout = metrics . NewCounter ( ` vm_concurrent_select_limit_timeout_total ` )
_ = metrics . NewGauge ( ` vm_concurrent_select_capacity ` , func ( ) float64 {
return float64 ( cap ( concurrencyCh ) )
} )
_ = metrics . NewGauge ( ` vm_concurrent_select_current ` , func ( ) float64 {
return float64 ( len ( concurrencyCh ) )
} )
)
2019-05-22 23:23:23 +02:00
func requestHandler ( w http . ResponseWriter , r * http . Request ) bool {
2020-12-14 13:02:57 +01:00
if r . URL . Path == "/" {
2021-04-02 21:54:06 +02:00
if r . Method != "GET" {
return false
}
2021-07-07 16:28:06 +02:00
fmt . Fprintf ( w , ` vmselect - a component of VictoriaMetrics cluster < br / >
< a href = "https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html" > docs < / a > < br >
` )
2020-10-06 14:00:38 +02:00
return true
}
2021-07-07 16:28:06 +02:00
2020-02-04 15:13:59 +01:00
startTime := time . Now ( )
2021-07-07 16:28:06 +02:00
defer requestDuration . UpdateDuration ( startTime )
2019-05-22 23:16:55 +02:00
// Limit the number of concurrent queries.
select {
case concurrencyCh <- struct { } { } :
defer func ( ) { <- concurrencyCh } ( )
2019-08-05 17:27:50 +02:00
default :
// Sleep for a while until giving up. This should resolve short bursts in requests.
concurrencyLimitReached . Inc ( )
2020-09-22 00:21:20 +02:00
d := searchutils . GetMaxQueryDuration ( r )
if d > * maxQueueDuration {
d = * maxQueueDuration
}
t := timerpool . Get ( d )
2019-08-05 17:27:50 +02:00
select {
case concurrencyCh <- struct { } { } :
timerpool . Put ( t )
defer func ( ) { <- concurrencyCh } ( )
case <- t . C :
timerpool . Put ( t )
concurrencyLimitTimeout . Inc ( )
2019-08-23 08:46:45 +02:00
err := & httpserver . ErrorWithStatusCode {
2020-01-17 12:24:37 +01:00
Err : fmt . Errorf ( "cannot handle more than %d concurrent search requests during %s; possible solutions: " +
2020-09-22 00:21:20 +02:00
"increase `-search.maxQueueDuration`; increase `-search.maxQueryDuration`; increase `-search.maxConcurrentRequests`; " +
"increase server capacity" ,
* maxConcurrentRequests , d ) ,
2019-08-23 08:46:45 +02:00
StatusCode : http . StatusServiceUnavailable ,
}
2020-07-20 13:00:33 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2019-08-05 17:27:50 +02:00
return true
}
2019-05-22 23:16:55 +02:00
}
2021-06-18 18:04:42 +02:00
if * logSlowQueryDuration > 0 {
actualStartTime := time . Now ( )
defer func ( ) {
d := time . Since ( actualStartTime )
if d >= * logSlowQueryDuration {
remoteAddr := httpserver . GetQuotedRemoteAddr ( r )
2021-07-07 11:59:03 +02:00
requestURI := httpserver . GetRequestURI ( r )
2021-06-18 18:04:42 +02:00
logger . Warnf ( "slow query according to -search.logSlowQueryDuration=%s: remoteAddr=%s, duration=%.3f seconds; requestURI: %q" ,
* logSlowQueryDuration , remoteAddr , d . Seconds ( ) , requestURI )
slowQueries . Inc ( )
}
} ( )
}
2020-02-21 12:53:18 +01:00
path := strings . Replace ( r . URL . Path , "//" , "/" , - 1 )
2020-07-08 18:09:16 +02:00
if path == "/internal/resetRollupResultCache" {
if len ( * resetCacheAuthKey ) > 0 && r . FormValue ( "authKey" ) != * resetCacheAuthKey {
sendPrometheusError ( w , r , fmt . Errorf ( "invalid authKey=%q for %q" , r . FormValue ( "authKey" ) , path ) )
return true
}
promql . ResetRollupResultCache ( )
return true
2019-05-22 23:23:23 +02:00
}
2020-12-25 15:44:26 +01:00
if path == "/api/v1/status/top_queries" {
2020-12-27 11:53:50 +01:00
globalTopQueriesRequests . Inc ( )
if err := prometheus . QueryStatsHandler ( startTime , nil , w , r ) ; err != nil {
globalTopQueriesErrors . Inc ( )
sendPrometheusError ( w , r , err )
2020-12-25 15:44:26 +01:00
return true
}
return true
}
2019-05-22 23:23:23 +02:00
p , err := httpserver . ParsePath ( path )
if err != nil {
2020-07-20 13:00:33 +02:00
httpserver . Errorf ( w , r , "cannot parse path %q: %s" , path , err )
2019-05-22 23:23:23 +02:00
return true
}
at , err := auth . NewToken ( p . AuthToken )
if err != nil {
2020-07-20 13:00:33 +02:00
httpserver . Errorf ( w , r , "auth error: %s" , err )
2019-05-22 23:23:23 +02:00
return true
}
switch p . Prefix {
case "select" :
2020-02-04 15:13:59 +01:00
return selectHandler ( startTime , w , r , p , at )
2019-05-22 23:23:23 +02:00
case "delete" :
2020-02-04 15:13:59 +01:00
return deleteHandler ( startTime , w , r , p , at )
2019-05-22 23:23:23 +02:00
default :
// This is not our link
return false
}
}
2021-07-10 11:32:09 +02:00
//go:embed vmui
var vmuiFiles embed . FS
var vmuiFileServer = http . FileServer ( http . FS ( vmuiFiles ) )
2020-02-04 15:13:59 +01:00
func selectHandler ( startTime time . Time , w http . ResponseWriter , r * http . Request , p * httpserver . Path , at * auth . Token ) bool {
2021-02-16 22:25:27 +01:00
defer func ( ) {
// Count per-tenant cumulative durations and total requests
httpRequests . Get ( at ) . Inc ( )
httpRequestsDuration . Get ( at ) . Add ( int ( time . Since ( startTime ) . Milliseconds ( ) ) )
} ( )
2021-07-12 08:07:50 +02:00
if strings . HasPrefix ( p . Suffix , "vmui" ) {
2021-07-09 16:04:28 +02:00
// vmui access.
2021-07-10 11:32:09 +02:00
prefix := strings . Join ( [ ] string { "" , p . Prefix , p . AuthToken } , "/" )
2021-07-09 16:04:28 +02:00
http . StripPrefix ( prefix , vmuiFileServer ) . ServeHTTP ( w , r )
2021-07-08 12:13:01 +02:00
return true
}
2019-05-22 23:23:23 +02:00
if strings . HasPrefix ( p . Suffix , "prometheus/api/v1/label/" ) {
s := p . Suffix [ len ( "prometheus/api/v1/label/" ) : ]
2019-05-22 23:16:55 +02:00
if strings . HasSuffix ( s , "/values" ) {
labelValuesRequests . Inc ( )
labelName := s [ : len ( s ) - len ( "/values" ) ]
httpserver . EnableCORS ( w , r )
2020-02-04 15:13:59 +01:00
if err := prometheus . LabelValuesHandler ( startTime , at , labelName , w , r ) ; err != nil {
2019-05-22 23:16:55 +02:00
labelValuesErrors . Inc ( )
sendPrometheusError ( w , r , err )
return true
}
return true
}
}
2020-11-16 13:49:46 +01:00
if strings . HasPrefix ( p . Suffix , "graphite/tags/" ) && ! isGraphiteTagsPath ( p . Suffix [ len ( "graphite" ) : ] ) {
2020-11-16 02:31:09 +01:00
tagName := p . Suffix [ len ( "graphite/tags/" ) : ]
graphiteTagValuesRequests . Inc ( )
if err := graphite . TagValuesHandler ( startTime , at , tagName , w , r ) ; err != nil {
graphiteTagValuesErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-11-16 02:31:09 +01:00
return true
}
return true
}
2019-05-22 23:16:55 +02:00
2019-05-22 23:23:23 +02:00
switch p . Suffix {
case "prometheus/api/v1/query" :
2019-05-22 23:16:55 +02:00
queryRequests . Inc ( )
httpserver . EnableCORS ( w , r )
2020-02-04 15:13:59 +01:00
if err := prometheus . QueryHandler ( startTime , at , w , r ) ; err != nil {
2019-05-22 23:16:55 +02:00
queryErrors . Inc ( )
sendPrometheusError ( w , r , err )
return true
}
return true
2019-05-22 23:23:23 +02:00
case "prometheus/api/v1/query_range" :
2019-05-22 23:16:55 +02:00
queryRangeRequests . Inc ( )
httpserver . EnableCORS ( w , r )
2020-02-04 15:13:59 +01:00
if err := prometheus . QueryRangeHandler ( startTime , at , w , r ) ; err != nil {
2019-05-22 23:16:55 +02:00
queryRangeErrors . Inc ( )
sendPrometheusError ( w , r , err )
return true
}
return true
2019-05-22 23:23:23 +02:00
case "prometheus/api/v1/series" :
2019-05-22 23:16:55 +02:00
seriesRequests . Inc ( )
httpserver . EnableCORS ( w , r )
2020-02-04 15:13:59 +01:00
if err := prometheus . SeriesHandler ( startTime , at , w , r ) ; err != nil {
2019-05-22 23:16:55 +02:00
seriesErrors . Inc ( )
sendPrometheusError ( w , r , err )
return true
}
return true
2019-05-22 23:23:23 +02:00
case "prometheus/api/v1/series/count" :
2019-05-22 23:16:55 +02:00
seriesCountRequests . Inc ( )
httpserver . EnableCORS ( w , r )
2020-02-04 15:13:59 +01:00
if err := prometheus . SeriesCountHandler ( startTime , at , w , r ) ; err != nil {
2019-05-22 23:16:55 +02:00
seriesCountErrors . Inc ( )
sendPrometheusError ( w , r , err )
return true
}
return true
2019-05-22 23:23:23 +02:00
case "prometheus/api/v1/labels" :
2019-05-22 23:16:55 +02:00
labelsRequests . Inc ( )
httpserver . EnableCORS ( w , r )
2020-02-04 15:13:59 +01:00
if err := prometheus . LabelsHandler ( startTime , at , w , r ) ; err != nil {
2019-05-22 23:16:55 +02:00
labelsErrors . Inc ( )
sendPrometheusError ( w , r , err )
return true
}
return true
2019-06-10 17:55:20 +02:00
case "prometheus/api/v1/labels/count" :
labelsCountRequests . Inc ( )
httpserver . EnableCORS ( w , r )
2020-02-04 15:13:59 +01:00
if err := prometheus . LabelsCountHandler ( startTime , at , w , r ) ; err != nil {
2019-06-10 17:55:20 +02:00
labelsCountErrors . Inc ( )
sendPrometheusError ( w , r , err )
return true
}
return true
2020-04-22 18:57:36 +02:00
case "prometheus/api/v1/status/tsdb" :
2020-07-08 18:09:16 +02:00
statusTSDBRequests . Inc ( )
2020-04-22 18:57:36 +02:00
if err := prometheus . TSDBStatusHandler ( startTime , at , w , r ) ; err != nil {
2020-07-08 18:09:16 +02:00
statusTSDBErrors . Inc ( )
2020-04-22 18:57:36 +02:00
sendPrometheusError ( w , r , err )
return true
}
return true
2020-07-08 18:09:16 +02:00
case "prometheus/api/v1/status/active_queries" :
statusActiveQueriesRequests . Inc ( )
promql . WriteActiveQueries ( w )
return true
2020-12-27 11:53:50 +01:00
case "prometheus/api/v1/status/top_queries" :
topQueriesRequests . Inc ( )
if err := prometheus . QueryStatsHandler ( startTime , at , w , r ) ; err != nil {
topQueriesErrors . Inc ( )
sendPrometheusError ( w , r , err )
return true
}
return true
2019-05-22 23:23:23 +02:00
case "prometheus/api/v1/export" :
2019-05-22 23:16:55 +02:00
exportRequests . Inc ( )
2020-02-04 15:13:59 +01:00
if err := prometheus . ExportHandler ( startTime , at , w , r ) ; err != nil {
2019-05-22 23:16:55 +02:00
exportErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2019-05-22 23:16:55 +02:00
return true
}
return true
2020-09-26 03:29:45 +02:00
case "prometheus/api/v1/export/native" :
exportNativeRequests . Inc ( )
if err := prometheus . ExportNativeHandler ( startTime , at , w , r ) ; err != nil {
exportNativeErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-09-26 03:29:45 +02:00
return true
}
return true
2020-10-12 19:01:51 +02:00
case "prometheus/api/v1/export/csv" :
exportCSVRequests . Inc ( )
if err := prometheus . ExportCSVHandler ( startTime , at , w , r ) ; err != nil {
exportCSVErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-10-12 19:01:51 +02:00
return true
}
return true
2019-05-22 23:23:23 +02:00
case "prometheus/federate" :
2019-05-22 23:16:55 +02:00
federateRequests . Inc ( )
2020-02-04 15:13:59 +01:00
if err := prometheus . FederateHandler ( startTime , at , w , r ) ; err != nil {
2019-05-22 23:16:55 +02:00
federateErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2019-05-22 23:16:55 +02:00
return true
}
return true
2020-09-10 23:29:26 +02:00
case "graphite/metrics/find" , "graphite/metrics/find/" :
graphiteMetricsFindRequests . Inc ( )
httpserver . EnableCORS ( w , r )
if err := graphite . MetricsFindHandler ( startTime , at , w , r ) ; err != nil {
graphiteMetricsFindErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-09-10 23:29:26 +02:00
return true
}
return true
case "graphite/metrics/expand" , "graphite/metrics/expand/" :
graphiteMetricsExpandRequests . Inc ( )
httpserver . EnableCORS ( w , r )
if err := graphite . MetricsExpandHandler ( startTime , at , w , r ) ; err != nil {
graphiteMetricsExpandErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-09-10 23:29:26 +02:00
return true
}
return true
case "graphite/metrics/index.json" , "graphite/metrics/index.json/" :
graphiteMetricsIndexRequests . Inc ( )
httpserver . EnableCORS ( w , r )
if err := graphite . MetricsIndexHandler ( startTime , at , w , r ) ; err != nil {
graphiteMetricsIndexErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-09-10 23:29:26 +02:00
return true
}
return true
2020-11-23 11:33:17 +01:00
case "graphite/tags/tagSeries" :
graphiteTagsTagSeriesRequests . Inc ( )
if err := graphite . TagsTagSeriesHandler ( startTime , at , w , r ) ; err != nil {
graphiteTagsTagSeriesErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-11-23 11:33:17 +01:00
return true
}
return true
case "graphite/tags/tagMultiSeries" :
graphiteTagsTagMultiSeriesRequests . Inc ( )
if err := graphite . TagsTagMultiSeriesHandler ( startTime , at , w , r ) ; err != nil {
graphiteTagsTagMultiSeriesErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-11-23 11:33:17 +01:00
return true
}
return true
2020-11-16 00:25:38 +01:00
case "graphite/tags" :
graphiteTagsRequests . Inc ( )
if err := graphite . TagsHandler ( startTime , at , w , r ) ; err != nil {
graphiteTagsErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-11-16 00:25:38 +01:00
return true
}
return true
2020-11-16 09:55:55 +01:00
case "graphite/tags/findSeries" :
graphiteTagsFindSeriesRequests . Inc ( )
if err := graphite . TagsFindSeriesHandler ( startTime , at , w , r ) ; err != nil {
graphiteTagsFindSeriesErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-11-16 09:55:55 +01:00
return true
}
return true
2020-11-16 16:56:19 +01:00
case "graphite/tags/autoComplete/tags" :
2020-11-16 13:49:46 +01:00
graphiteTagsAutoCompleteTagsRequests . Inc ( )
httpserver . EnableCORS ( w , r )
if err := graphite . TagsAutoCompleteTagsHandler ( startTime , at , w , r ) ; err != nil {
graphiteTagsAutoCompleteTagsErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-11-16 13:49:46 +01:00
return true
}
return true
2020-11-16 16:56:19 +01:00
case "graphite/tags/autoComplete/values" :
2020-11-16 14:22:36 +01:00
graphiteTagsAutoCompleteValuesRequests . Inc ( )
httpserver . EnableCORS ( w , r )
if err := graphite . TagsAutoCompleteValuesHandler ( startTime , at , w , r ) ; err != nil {
graphiteTagsAutoCompleteValuesErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-11-16 14:22:36 +01:00
return true
}
return true
2020-11-23 14:26:20 +01:00
case "graphite/tags/delSeries" :
graphiteTagsDelSeriesRequests . Inc ( )
if err := graphite . TagsDelSeriesHandler ( startTime , at , w , r ) ; err != nil {
graphiteTagsDelSeriesErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2020-11-23 14:26:20 +01:00
return true
}
return true
2021-07-29 08:48:43 +02:00
case "prometheus/api/v1/rules" , "prometheus/rules" :
2021-07-29 05:15:35 +02:00
// Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#rules
rulesRequests . Inc ( )
w . Header ( ) . Set ( "Content-Type" , "application/json; charset=utf-8" )
fmt . Fprintf ( w , "%s" , ` { "status":"success","data": { "groups":[]}} ` )
return true
2019-12-03 18:32:57 +01:00
case "prometheus/api/v1/alerts" :
2021-04-05 22:25:05 +02:00
// Return dumb placehloder for https://prometheus.io/docs/prometheus/latest/querying/api/#alerts
2019-12-03 18:32:57 +01:00
alertsRequests . Inc ( )
2020-11-13 09:25:39 +01:00
w . Header ( ) . Set ( "Content-Type" , "application/json; charset=utf-8" )
2019-12-03 18:32:57 +01:00
fmt . Fprintf ( w , "%s" , ` { "status":"success","data": { "alerts":[]}} ` )
return true
2020-02-04 14:53:15 +01:00
case "prometheus/api/v1/metadata" :
2021-04-05 22:25:05 +02:00
// Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#querying-metric-metadata
2020-02-04 14:53:15 +01:00
metadataRequests . Inc ( )
2020-11-13 09:25:39 +01:00
w . Header ( ) . Set ( "Content-Type" , "application/json; charset=utf-8" )
2020-02-04 14:53:15 +01:00
fmt . Fprintf ( w , "%s" , ` { "status":"success","data": { }} ` )
return true
2021-04-05 22:25:05 +02:00
case "prometheus/api/v1/query_exemplars" :
// Return dumb placeholder for https://prometheus.io/docs/prometheus/latest/querying/api/#querying-exemplars
queryExemplarsRequests . Inc ( )
w . Header ( ) . Set ( "Content-Type" , "application/json; charset=utf-8" )
2021-04-07 22:33:40 +02:00
fmt . Fprintf ( w , "%s" , ` { "status":"success","data":null} ` )
2021-04-05 22:25:05 +02:00
return true
2019-05-22 23:23:23 +02:00
default :
return false
}
}
2020-02-04 15:13:59 +01:00
func deleteHandler ( startTime time . Time , w http . ResponseWriter , r * http . Request , p * httpserver . Path , at * auth . Token ) bool {
2019-05-22 23:23:23 +02:00
switch p . Suffix {
case "prometheus/api/v1/admin/tsdb/delete_series" :
2019-05-22 23:16:55 +02:00
deleteRequests . Inc ( )
2020-02-04 15:13:59 +01:00
if err := prometheus . DeleteHandler ( startTime , at , r ) ; err != nil {
2019-05-22 23:16:55 +02:00
deleteErrors . Inc ( )
2021-07-07 11:59:03 +02:00
httpserver . Errorf ( w , r , "%s" , err )
2019-05-22 23:16:55 +02:00
return true
}
w . WriteHeader ( http . StatusNoContent )
return true
default :
return false
}
}
2020-11-16 13:49:46 +01:00
func isGraphiteTagsPath ( path string ) bool {
switch path {
// See https://graphite.readthedocs.io/en/stable/tags.html for a list of Graphite Tags API paths.
// Do not include `/tags/<tag_name>` here, since this will fool the caller.
case "/tags/tagSeries" , "/tags/tagMultiSeries" , "/tags/findSeries" ,
"/tags/autoComplete/tags" , "/tags/autoComplete/values" , "/tags/delSeries" :
return true
default :
return false
}
}
2019-05-22 23:16:55 +02:00
func sendPrometheusError ( w http . ResponseWriter , r * http . Request , err error ) {
2021-07-07 11:59:03 +02:00
logger . Warnf ( "error in %q: %s" , httpserver . GetRequestURI ( r ) , err )
2019-05-22 23:16:55 +02:00
2020-11-13 09:25:39 +01:00
w . Header ( ) . Set ( "Content-Type" , "application/json; charset=utf-8" )
2019-08-23 08:46:45 +02:00
statusCode := http . StatusUnprocessableEntity
2020-06-30 23:02:02 +02:00
var esc * httpserver . ErrorWithStatusCode
if errors . As ( err , & esc ) {
2019-08-23 08:46:45 +02:00
statusCode = esc . StatusCode
}
2019-05-22 23:16:55 +02:00
w . WriteHeader ( statusCode )
prometheus . WriteErrorResponse ( w , statusCode , err )
}
var (
2021-07-07 12:25:16 +02:00
requestDuration = metrics . NewHistogram ( ` vmselect_request_duration_seconds ` )
2019-05-22 23:23:23 +02:00
labelValuesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/label/ { }/values"} ` )
2020-02-10 21:15:21 +01:00
labelValuesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/label/ { }/values"} ` )
2019-05-22 23:16:55 +02:00
2019-05-22 23:23:23 +02:00
queryRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/query"} ` )
queryErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/query"} ` )
2019-05-22 23:16:55 +02:00
2020-02-10 21:15:21 +01:00
queryRangeRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/query_range"} ` )
2019-05-22 23:23:23 +02:00
queryRangeErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/query_range"} ` )
2019-05-22 23:16:55 +02:00
2019-05-22 23:23:23 +02:00
seriesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/series"} ` )
seriesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/series"} ` )
2019-05-22 23:16:55 +02:00
2019-05-22 23:23:23 +02:00
seriesCountRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/series/count"} ` )
seriesCountErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/series/count"} ` )
2019-05-22 23:16:55 +02:00
2019-05-22 23:23:23 +02:00
labelsRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/labels"} ` )
labelsErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/labels"} ` )
2019-05-22 23:16:55 +02:00
2019-06-10 17:55:20 +02:00
labelsCountRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/labels/count"} ` )
labelsCountErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/labels/count"} ` )
2020-07-08 18:09:16 +02:00
statusTSDBRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/status/tsdb"} ` )
statusTSDBErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/status/tsdb"} ` )
statusActiveQueriesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }prometheus/api/v1/status/active_queries"} ` )
2020-04-22 18:57:36 +02:00
2020-12-27 11:53:50 +01:00
topQueriesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/status/top_queries"} ` )
topQueriesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/status/top_queries"} ` )
globalTopQueriesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/api/v1/status/top_queries"} ` )
globalTopQueriesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/api/v1/status/top_queries"} ` )
2019-05-22 23:23:23 +02:00
deleteRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/delete/ { }/prometheus/api/v1/admin/tsdb/delete_series"} ` )
deleteErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/delete/ { }/prometheus/api/v1/admin/tsdb/delete_series"} ` )
2019-05-22 23:16:55 +02:00
2019-05-22 23:23:23 +02:00
exportRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/export"} ` )
exportErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/export"} ` )
2019-05-22 23:16:55 +02:00
2020-09-26 03:29:45 +02:00
exportNativeRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/export/native"} ` )
exportNativeErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/export/native"} ` )
2020-10-12 19:01:51 +02:00
exportCSVRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/export/csv"} ` )
exportCSVErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/api/v1/export/csv"} ` )
2019-05-22 23:23:23 +02:00
federateRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/federate"} ` )
federateErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/prometheus/federate"} ` )
2019-12-03 18:32:57 +01:00
2020-09-10 23:29:26 +02:00
graphiteMetricsFindRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/metrics/find"} ` )
graphiteMetricsFindErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/metrics/find"} ` )
graphiteMetricsExpandRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/metrics/expand"} ` )
graphiteMetricsExpandErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/metrics/expand"} ` )
graphiteMetricsIndexRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/metrics/index.json"} ` )
graphiteMetricsIndexErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/metrics/index.json"} ` )
2020-11-23 11:33:17 +01:00
graphiteTagsTagSeriesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/tags/tagSeries"} ` )
graphiteTagsTagSeriesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/tags/tagSeries"} ` )
graphiteTagsTagMultiSeriesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/tags/tagMultiSeries"} ` )
graphiteTagsTagMultiSeriesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/tags/tagMultiSeries"} ` )
2020-11-16 00:25:38 +01:00
graphiteTagsRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/tags"} ` )
graphiteTagsErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/tags"} ` )
2020-11-16 02:31:09 +01:00
graphiteTagValuesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/tags/<tag_name>"} ` )
graphiteTagValuesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/tags/<tag_name>"} ` )
2020-11-16 09:55:55 +01:00
graphiteTagsFindSeriesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/tags/findSeries"} ` )
graphiteTagsFindSeriesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/tags/findSeries"} ` )
2020-11-16 13:49:46 +01:00
graphiteTagsAutoCompleteTagsRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/tags/autoComplete/tags"} ` )
graphiteTagsAutoCompleteTagsErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/tags/autoComplete/tags"} ` )
2020-11-16 14:22:36 +01:00
graphiteTagsAutoCompleteValuesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/tags/autoComplete/values"} ` )
graphiteTagsAutoCompleteValuesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/tags/autoComplete/values"} ` )
2020-11-23 14:26:20 +01:00
graphiteTagsDelSeriesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/graphite/tags/delSeries"} ` )
graphiteTagsDelSeriesErrors = metrics . NewCounter ( ` vm_http_request_errors_total { path="/select/ { }/graphite/tags/delSeries"} ` )
2021-04-05 22:25:05 +02:00
rulesRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/rules"} ` )
alertsRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/alerts"} ` )
metadataRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/metadata"} ` )
queryExemplarsRequests = metrics . NewCounter ( ` vm_http_requests_total { path="/select/ { }/prometheus/api/v1/query_exemplars"} ` )
2021-02-16 22:25:27 +01:00
2021-03-29 10:59:04 +02:00
httpRequests = tenantmetrics . NewCounterMap ( ` vm_tenant_select_requests_total ` )
httpRequestsDuration = tenantmetrics . NewCounterMap ( ` vm_tenant_select_requests_duration_ms_total ` )
2019-05-22 23:16:55 +02:00
)
2020-12-03 20:40:30 +01:00
func usage ( ) {
const s = `
vmselect processes incoming queries by fetching the requested data from vmstorage nodes configured via - storageNode .
2021-04-20 19:16:17 +02:00
See the docs at https : //docs.victoriametrics.com/Cluster-VictoriaMetrics.html .
2020-12-03 20:40:30 +01:00
`
flagutil . Usage ( s )
}