2019-05-22 21:16:55 +00:00
package vmstorage
import (
2021-10-08 11:15:52 +00:00
"errors"
2019-05-22 21:16:55 +00:00
"flag"
"fmt"
"net/http"
"strings"
"sync"
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/encoding"
2020-06-30 21:20:13 +00:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fasttime"
2020-10-20 11:29:26 +00:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
2020-04-01 20:08:58 +00:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fs"
2019-05-22 21:16:55 +00:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
2022-02-21 11:50:34 +00:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/mergeset"
2022-05-31 23:29:19 +00:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/querytracer"
2019-05-22 21:16:55 +00:00
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/syncwg"
"github.com/VictoriaMetrics/metrics"
)
var (
2022-10-24 00:02:14 +00:00
retentionPeriod = flagutil . NewDuration ( "retentionPeriod" , "1" , "Data with timestamps outside the retentionPeriod is automatically deleted. See also -retentionFilter" )
2020-09-17 11:21:39 +00:00
snapshotAuthKey = flag . String ( "snapshotAuthKey" , "" , "authKey, which must be passed in query string to /snapshot* pages" )
forceMergeAuthKey = flag . String ( "forceMergeAuthKey" , "" , "authKey, which must be passed in query string to /internal/force_merge pages" )
2020-11-11 12:40:27 +00:00
forceFlushAuthKey = flag . String ( "forceFlushAuthKey" , "" , "authKey, which must be passed in query string to /internal/force_flush pages" )
2022-05-05 16:43:21 +00:00
snapshotsMaxAge = flagutil . NewDuration ( "snapshotsMaxAge" , "0" , "Automatically delete snapshots older than -snapshotsMaxAge if it is set to non-zero duration. Make sure that backup process has enough time to finish the backup before the corresponding snapshot is automatically deleted" )
2019-05-22 21:16:55 +00:00
precisionBits = flag . Int ( "precisionBits" , 64 , "The number of precision bits to store per each value. Lower precision bits improves data compression at the cost of precision loss" )
// DataPath is a path to storage data.
DataPath = flag . String ( "storageDataPath" , "victoria-metrics-data" , "Path to storage data" )
2019-10-31 14:16:53 +00:00
2021-01-07 22:09:00 +00:00
finalMergeDelay = flag . Duration ( "finalMergeDelay" , 0 , "The delay before starting final merge for per-month partition after no new data is ingested into it. " +
"Final merge may require additional disk IO and CPU resources. Final merge may increase query speed and reduce disk space usage in some cases. " +
"Zero value disables final merge" )
2022-05-25 12:57:01 +00:00
bigMergeConcurrency = flag . Int ( "bigMergeConcurrency" , 0 , "The maximum number of CPU cores to use for big merges. Default value is used if set to 0" )
smallMergeConcurrency = flag . Int ( "smallMergeConcurrency" , 0 , "The maximum number of CPU cores to use for small merges. Default value is used if set to 0" )
retentionTimezoneOffset = flag . Duration ( "retentionTimezoneOffset" , 0 , "The offset for performing indexdb rotation. " +
"If set to 0, then the indexdb rotation is performed at 4am UTC time per each -retentionPeriod. " +
"If set to 2h, then the indexdb rotation is performed at 4am EET time (the timezone with +2h offset)" )
2020-06-30 21:20:13 +00:00
2021-03-15 20:38:50 +00:00
logNewSeries = flag . Bool ( "logNewSeries" , false , "Whether to log new series. This option is for debug purposes only. It can lead to performance issues " +
"when big number of new series are ingested into VictoriaMetrics" )
2020-06-30 21:20:13 +00:00
denyQueriesOutsideRetention = flag . Bool ( "denyQueriesOutsideRetention" , false , "Whether to deny queries outside of the configured -retentionPeriod. " +
"When set, then /api/v1/query_range would return '503 Service Unavailable' error for queries with 'from' value outside -retentionPeriod. " +
"This may be useful when multiple data sources with distinct retentions are hidden behind query-tee" )
2021-05-20 11:15:19 +00:00
maxHourlySeries = flag . Int ( "storage.maxHourlySeries" , 0 , "The maximum number of unique series can be added to the storage during the last hour. " +
2022-08-24 10:41:53 +00:00
"Excess series are logged and dropped. This can be useful for limiting series cardinality. See https://docs.victoriametrics.com/#cardinality-limiter . " +
"See also -storage.maxDailySeries" )
2021-05-20 11:15:19 +00:00
maxDailySeries = flag . Int ( "storage.maxDailySeries" , 0 , "The maximum number of unique series can be added to the storage during the last 24 hours. " +
2022-08-24 10:41:53 +00:00
"Excess series are logged and dropped. This can be useful for limiting series churn rate. See https://docs.victoriametrics.com/#cardinality-limiter . " +
"See also -storage.maxHourlySeries" )
2021-10-08 09:52:56 +00:00
2021-10-08 11:15:52 +00:00
minFreeDiskSpaceBytes = flagutil . NewBytes ( "storage.minFreeDiskSpaceBytes" , 10e6 , "The minimum free disk space at -storageDataPath after which the storage stops accepting new data" )
2022-02-21 11:50:34 +00:00
2022-10-23 09:15:24 +00:00
cacheSizeStorageTSID = flagutil . NewBytes ( "storage.cacheSizeStorageTSID" , 0 , "Overrides max size for storage/tsid cache. " +
"See https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#cache-tuning" )
cacheSizeIndexDBIndexBlocks = flagutil . NewBytes ( "storage.cacheSizeIndexDBIndexBlocks" , 0 , "Overrides max size for indexdb/indexBlocks cache. " +
"See https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#cache-tuning" )
cacheSizeIndexDBDataBlocks = flagutil . NewBytes ( "storage.cacheSizeIndexDBDataBlocks" , 0 , "Overrides max size for indexdb/dataBlocks cache. " +
"See https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#cache-tuning" )
cacheSizeIndexDBTagFilters = flagutil . NewBytes ( "storage.cacheSizeIndexDBTagFilters" , 0 , "Overrides max size for indexdb/tagFiltersToMetricIDs cache. " +
"See https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html#cache-tuning" )
2019-05-22 21:16:55 +00:00
)
2020-06-30 21:20:13 +00:00
// CheckTimeRange returns true if the given tr is denied for querying.
func CheckTimeRange ( tr storage . TimeRange ) error {
if ! * denyQueriesOutsideRetention {
return nil
}
2020-10-20 11:29:26 +00:00
minAllowedTimestamp := int64 ( fasttime . UnixTimestamp ( ) * 1000 ) - retentionPeriod . Msecs
2020-06-30 21:20:13 +00:00
if tr . MinTimestamp > minAllowedTimestamp {
return nil
}
return & httpserver . ErrorWithStatusCode {
2020-10-20 11:29:26 +00:00
Err : fmt . Errorf ( "the given time range %s is outside the allowed -retentionPeriod=%s according to -denyQueriesOutsideRetention" , & tr , retentionPeriod ) ,
2020-06-30 21:20:13 +00:00
StatusCode : http . StatusServiceUnavailable ,
}
}
2019-05-22 21:16:55 +00:00
// Init initializes vmstorage.
2020-12-14 11:08:22 +00:00
func Init ( resetCacheIfNeeded func ( mrs [ ] storage . MetricRow ) ) {
2019-05-22 21:16:55 +00:00
if err := encoding . CheckPrecisionBits ( uint8 ( * precisionBits ) ) ; err != nil {
logger . Fatalf ( "invalid `-precisionBits`: %s" , err )
}
2019-10-31 14:16:53 +00:00
2020-12-14 11:08:22 +00:00
resetResponseCacheIfNeeded = resetCacheIfNeeded
2021-03-15 20:38:50 +00:00
storage . SetLogNewSeries ( * logNewSeries )
2020-10-07 14:35:42 +00:00
storage . SetFinalMergeDelay ( * finalMergeDelay )
2019-10-31 14:16:53 +00:00
storage . SetBigMergeWorkersCount ( * bigMergeConcurrency )
2022-12-05 23:15:00 +00:00
storage . SetMergeWorkersCount ( * smallMergeConcurrency )
2022-05-25 12:57:01 +00:00
storage . SetRetentionTimezoneOffset ( * retentionTimezoneOffset )
2021-10-08 11:15:52 +00:00
storage . SetFreeDiskSpaceLimit ( minFreeDiskSpaceBytes . N )
2022-12-15 03:26:24 +00:00
storage . SetTSIDCacheSize ( cacheSizeStorageTSID . IntN ( ) )
storage . SetTagFiltersCacheSize ( cacheSizeIndexDBTagFilters . IntN ( ) )
mergeset . SetIndexBlocksCacheSize ( cacheSizeIndexDBIndexBlocks . IntN ( ) )
mergeset . SetDataBlocksCacheSize ( cacheSizeIndexDBDataBlocks . IntN ( ) )
2019-10-31 14:16:53 +00:00
2022-05-09 08:11:56 +00:00
if retentionPeriod . Msecs < 24 * 3600 * 1000 {
2022-05-06 21:51:24 +00:00
logger . Fatalf ( "-retentionPeriod cannot be smaller than a day; got %s" , retentionPeriod )
}
2020-10-20 11:29:26 +00:00
logger . Infof ( "opening storage at %q with -retentionPeriod=%s" , * DataPath , retentionPeriod )
2019-05-22 21:16:55 +00:00
startTime := time . Now ( )
2019-07-11 12:34:50 +00:00
WG = syncwg . WaitGroup { }
2021-05-20 11:15:19 +00:00
strg , err := storage . OpenStorage ( * DataPath , retentionPeriod . Msecs , * maxHourlySeries , * maxDailySeries )
2019-05-22 21:16:55 +00:00
if err != nil {
2020-10-20 11:29:26 +00:00
logger . Fatalf ( "cannot open a storage at %s with -retentionPeriod=%s: %s" , * DataPath , retentionPeriod , err )
2019-05-22 21:16:55 +00:00
}
Storage = strg
2022-05-04 20:56:09 +00:00
initStaleSnapshotsRemover ( strg )
2019-05-22 21:16:55 +00:00
var m storage . Metrics
2022-05-04 20:56:09 +00:00
strg . UpdateMetrics ( & m )
2019-05-22 21:16:55 +00:00
tm := & m . TableMetrics
partsCount := tm . SmallPartsCount + tm . BigPartsCount
blocksCount := tm . SmallBlocksCount + tm . BigBlocksCount
rowsCount := tm . SmallRowsCount + tm . BigRowsCount
2019-07-04 16:09:40 +00:00
sizeBytes := tm . SmallSizeBytes + tm . BigSizeBytes
2020-01-22 16:27:44 +00:00
logger . Infof ( "successfully opened storage %q in %.3f seconds; partsCount: %d; blocksCount: %d; rowsCount: %d; sizeBytes: %d" ,
* DataPath , time . Since ( startTime ) . Seconds ( ) , partsCount , blocksCount , rowsCount , sizeBytes )
2023-01-23 13:45:59 +00:00
registerStorageMetrics ( Storage )
2019-05-22 21:16:55 +00:00
}
// Storage is a storage.
//
// Every storage call must be wrapped into WG.Add(1) ... WG.Done()
// for proper graceful shutdown when Stop is called.
var Storage * storage . Storage
// WG must be incremented before Storage call.
//
// Use syncwg instead of sync, since Add is called from concurrent goroutines.
var WG syncwg . WaitGroup
2020-12-14 11:08:22 +00:00
// resetResponseCacheIfNeeded is a callback for automatic resetting of response cache if needed.
var resetResponseCacheIfNeeded func ( mrs [ ] storage . MetricRow )
2019-05-22 21:16:55 +00:00
// AddRows adds mrs to the storage.
2023-01-07 06:40:07 +00:00
//
// The caller should limit the number of concurrent calls to AddRows() in order to limit memory usage.
2019-05-22 21:16:55 +00:00
func AddRows ( mrs [ ] storage . MetricRow ) error {
2021-10-08 11:15:52 +00:00
if Storage . IsReadOnly ( ) {
return errReadOnly
}
2020-12-14 11:08:22 +00:00
resetResponseCacheIfNeeded ( mrs )
2019-05-22 21:16:55 +00:00
WG . Add ( 1 )
err := Storage . AddRows ( mrs , uint8 ( * precisionBits ) )
WG . Done ( )
return err
}
2021-10-08 11:15:52 +00:00
var errReadOnly = errors . New ( "the storage is in read-only mode; check -storage.minFreeDiskSpaceBytes command-line flag value" )
2020-11-15 22:42:27 +00:00
// RegisterMetricNames registers all the metrics from mrs in the storage.
2022-06-27 09:53:46 +00:00
func RegisterMetricNames ( qt * querytracer . Tracer , mrs [ ] storage . MetricRow ) error {
2020-11-15 22:42:27 +00:00
WG . Add ( 1 )
2022-06-27 09:53:46 +00:00
err := Storage . RegisterMetricNames ( qt , mrs )
2020-11-15 22:42:27 +00:00
WG . Done ( )
return err
}
2022-07-05 20:56:31 +00:00
// DeleteSeries deletes series matching tfss.
2019-05-22 21:16:55 +00:00
//
2022-07-05 20:56:31 +00:00
// Returns the number of deleted series.
func DeleteSeries ( qt * querytracer . Tracer , tfss [ ] * storage . TagFilters ) ( int , error ) {
2019-05-22 21:16:55 +00:00
WG . Add ( 1 )
2022-07-05 20:56:31 +00:00
n , err := Storage . DeleteSeries ( qt , tfss )
2019-05-22 21:16:55 +00:00
WG . Done ( )
return n , err
}
2020-11-16 08:55:55 +00:00
// SearchMetricNames returns metric names for the given tfss on the given tr.
2022-06-28 14:36:27 +00:00
func SearchMetricNames ( qt * querytracer . Tracer , tfss [ ] * storage . TagFilters , tr storage . TimeRange , maxMetrics int , deadline uint64 ) ( [ ] string , error ) {
2020-11-16 08:55:55 +00:00
WG . Add ( 1 )
2022-06-28 14:36:27 +00:00
metricNames , err := Storage . SearchMetricNames ( qt , tfss , tr , maxMetrics , deadline )
2020-11-16 08:55:55 +00:00
WG . Done ( )
2022-06-28 14:36:27 +00:00
return metricNames , err
2020-11-16 08:55:55 +00:00
}
2022-06-12 01:32:13 +00:00
// SearchLabelNamesWithFiltersOnTimeRange searches for tag keys matching the given tfss on tr.
func SearchLabelNamesWithFiltersOnTimeRange ( qt * querytracer . Tracer , tfss [ ] * storage . TagFilters , tr storage . TimeRange , maxTagKeys , maxMetrics int , deadline uint64 ) ( [ ] string , error ) {
2020-11-04 22:15:43 +00:00
WG . Add ( 1 )
2022-06-12 01:32:13 +00:00
labelNames , err := Storage . SearchLabelNamesWithFiltersOnTimeRange ( qt , tfss , tr , maxTagKeys , maxMetrics , deadline )
2020-11-04 22:15:43 +00:00
WG . Done ( )
2022-06-12 01:32:13 +00:00
return labelNames , err
2020-11-04 22:15:43 +00:00
}
2022-06-12 01:32:13 +00:00
// SearchLabelValuesWithFiltersOnTimeRange searches for label values for the given labelName, tfss and tr.
func SearchLabelValuesWithFiltersOnTimeRange ( qt * querytracer . Tracer , labelName string , tfss [ ] * storage . TagFilters ,
tr storage . TimeRange , maxLabelValues , maxMetrics int , deadline uint64 ) ( [ ] string , error ) {
2019-05-22 21:16:55 +00:00
WG . Add ( 1 )
2022-06-12 01:32:13 +00:00
labelValues , err := Storage . SearchLabelValuesWithFiltersOnTimeRange ( qt , labelName , tfss , tr , maxLabelValues , maxMetrics , deadline )
2019-05-22 21:16:55 +00:00
WG . Done ( )
2022-06-12 01:32:13 +00:00
return labelValues , err
2019-05-22 21:16:55 +00:00
}
2020-09-10 21:28:19 +00:00
// SearchTagValueSuffixes returns all the tag value suffixes for the given tagKey and tagValuePrefix on the given tr.
//
// This allows implementing https://graphite-api.readthedocs.io/en/latest/api.html#metrics-find or similar APIs.
2022-07-05 20:47:46 +00:00
func SearchTagValueSuffixes ( qt * querytracer . Tracer , tr storage . TimeRange , tagKey , tagValuePrefix string , delimiter byte , maxTagValueSuffixes int , deadline uint64 ) ( [ ] string , error ) {
2020-09-10 21:28:19 +00:00
WG . Add ( 1 )
2022-06-27 09:53:46 +00:00
suffixes , err := Storage . SearchTagValueSuffixes ( qt , tr , tagKey , tagValuePrefix , delimiter , maxTagValueSuffixes , deadline )
2020-09-10 21:28:19 +00:00
WG . Done ( )
return suffixes , err
}
2021-02-02 22:24:05 +00:00
// SearchGraphitePaths returns all the metric names matching the given Graphite query.
2022-06-27 09:53:46 +00:00
func SearchGraphitePaths ( qt * querytracer . Tracer , tr storage . TimeRange , query [ ] byte , maxPaths int , deadline uint64 ) ( [ ] string , error ) {
2021-02-02 22:24:05 +00:00
WG . Add ( 1 )
2022-06-27 09:53:46 +00:00
paths , err := Storage . SearchGraphitePaths ( qt , tr , query , maxPaths , deadline )
2021-02-02 22:24:05 +00:00
WG . Done ( )
return paths , err
}
2022-06-14 14:46:16 +00:00
// GetTSDBStatus returns TSDB status for given filters on the given date.
func GetTSDBStatus ( qt * querytracer . Tracer , tfss [ ] * storage . TagFilters , date uint64 , focusLabel string , topN , maxMetrics int , deadline uint64 ) ( * storage . TSDBStatus , error ) {
2020-04-22 16:57:36 +00:00
WG . Add ( 1 )
2022-06-14 14:46:16 +00:00
status , err := Storage . GetTSDBStatus ( qt , tfss , date , focusLabel , topN , maxMetrics , deadline )
2021-05-12 12:18:45 +00:00
WG . Done ( )
return status , err
}
2019-05-22 21:16:55 +00:00
// GetSeriesCount returns the number of time series in the storage.
2020-07-23 17:42:57 +00:00
func GetSeriesCount ( deadline uint64 ) ( uint64 , error ) {
2019-05-22 21:16:55 +00:00
WG . Add ( 1 )
2020-07-23 17:42:57 +00:00
n , err := Storage . GetSeriesCount ( deadline )
2019-05-22 21:16:55 +00:00
WG . Done ( )
return n , err
}
// Stop stops the vmstorage
func Stop ( ) {
logger . Infof ( "gracefully closing the storage at %s" , * DataPath )
startTime := time . Now ( )
WG . WaitAndBlock ( )
2022-05-02 08:00:15 +00:00
stopStaleSnapshotsRemover ( )
2019-05-22 21:16:55 +00:00
Storage . MustClose ( )
2020-01-22 16:27:44 +00:00
logger . Infof ( "successfully closed the storage in %.3f seconds" , time . Since ( startTime ) . Seconds ( ) )
2019-05-22 21:16:55 +00:00
logger . Infof ( "the storage has been stopped" )
}
// RequestHandler is a storage request handler.
func RequestHandler ( w http . ResponseWriter , r * http . Request ) bool {
path := r . URL . Path
2020-09-17 09:01:53 +00:00
if path == "/internal/force_merge" {
2023-01-10 23:51:55 +00:00
if ! httpserver . CheckAuthFlag ( w , r , * forceMergeAuthKey , "forceMergeAuthKey" ) {
2020-09-17 11:21:39 +00:00
return true
}
2020-09-17 09:01:53 +00:00
// Run force merge in background
partitionNamePrefix := r . FormValue ( "partition_prefix" )
go func ( ) {
activeForceMerges . Inc ( )
defer activeForceMerges . Dec ( )
logger . Infof ( "forced merge for partition_prefix=%q has been started" , partitionNamePrefix )
startTime := time . Now ( )
if err := Storage . ForceMergePartitions ( partitionNamePrefix ) ; err != nil {
logger . Errorf ( "error in forced merge for partition_prefix=%q: %s" , partitionNamePrefix , err )
}
logger . Infof ( "forced merge for partition_prefix=%q has been successfully finished in %.3f seconds" , partitionNamePrefix , time . Since ( startTime ) . Seconds ( ) )
} ( )
return true
}
2020-11-11 12:40:27 +00:00
if path == "/internal/force_flush" {
2023-01-10 23:51:55 +00:00
if ! httpserver . CheckAuthFlag ( w , r , * forceFlushAuthKey , "forceFlushAuthKey" ) {
2020-11-11 12:40:27 +00:00
return true
}
logger . Infof ( "flushing storage to make pending data available for reading" )
Storage . DebugFlush ( )
return true
}
2019-05-22 21:16:55 +00:00
prometheusCompatibleResponse := false
if path == "/api/v1/admin/tsdb/snapshot" {
// Handle Prometheus API - https://prometheus.io/docs/prometheus/latest/querying/api/#snapshot .
prometheusCompatibleResponse = true
path = "/snapshot/create"
}
if ! strings . HasPrefix ( path , "/snapshot" ) {
return false
}
2023-01-10 23:51:55 +00:00
if ! httpserver . CheckAuthFlag ( w , r , * snapshotAuthKey , "snapshotAuthKey" ) {
2019-05-22 21:16:55 +00:00
return true
}
path = path [ len ( "/snapshot" ) : ]
switch path {
case "/create" :
2021-11-09 16:03:50 +00:00
w . Header ( ) . Set ( "Content-Type" , "application/json" )
2019-05-22 21:16:55 +00:00
snapshotPath , err := Storage . CreateSnapshot ( )
if err != nil {
2020-06-30 19:58:18 +00:00
err = fmt . Errorf ( "cannot create snapshot: %w" , err )
2020-03-10 21:51:50 +00:00
jsonResponseError ( w , err )
2019-05-22 21:16:55 +00:00
return true
}
if prometheusCompatibleResponse {
fmt . Fprintf ( w , ` { "status":"success","data": { "name":%q}} ` , snapshotPath )
} else {
fmt . Fprintf ( w , ` { "status":"ok","snapshot":%q} ` , snapshotPath )
}
return true
case "/list" :
2021-11-09 16:03:50 +00:00
w . Header ( ) . Set ( "Content-Type" , "application/json" )
2019-05-22 21:16:55 +00:00
snapshots , err := Storage . ListSnapshots ( )
if err != nil {
2020-06-30 19:58:18 +00:00
err = fmt . Errorf ( "cannot list snapshots: %w" , err )
2020-03-10 21:51:50 +00:00
jsonResponseError ( w , err )
2019-05-22 21:16:55 +00:00
return true
}
fmt . Fprintf ( w , ` { "status":"ok","snapshots":[ ` )
if len ( snapshots ) > 0 {
for _ , snapshot := range snapshots [ : len ( snapshots ) - 1 ] {
fmt . Fprintf ( w , "\n%q," , snapshot )
}
fmt . Fprintf ( w , "\n%q\n" , snapshots [ len ( snapshots ) - 1 ] )
}
fmt . Fprintf ( w , ` ]} ` )
return true
case "/delete" :
2021-11-09 16:03:50 +00:00
w . Header ( ) . Set ( "Content-Type" , "application/json" )
2019-05-22 21:16:55 +00:00
snapshotName := r . FormValue ( "snapshot" )
2022-11-16 23:29:43 +00:00
snapshots , err := Storage . ListSnapshots ( )
if err != nil {
err = fmt . Errorf ( "cannot list snapshots: %w" , err )
2020-03-10 21:51:50 +00:00
jsonResponseError ( w , err )
2019-05-22 21:16:55 +00:00
return true
}
2022-11-16 23:29:43 +00:00
for _ , snName := range snapshots {
if snName == snapshotName {
if err := Storage . DeleteSnapshot ( snName ) ; err != nil {
err = fmt . Errorf ( "cannot delete snapshot %q: %w" , snName , err )
jsonResponseError ( w , err )
return true
}
fmt . Fprintf ( w , ` { "status":"ok"} ` )
return true
}
}
err = fmt . Errorf ( "cannot find snapshot %q: %w" , snapshotName , err )
jsonResponseError ( w , err )
2019-05-22 21:16:55 +00:00
return true
case "/delete_all" :
2021-11-09 16:03:50 +00:00
w . Header ( ) . Set ( "Content-Type" , "application/json" )
2019-05-22 21:16:55 +00:00
snapshots , err := Storage . ListSnapshots ( )
if err != nil {
2020-06-30 19:58:18 +00:00
err = fmt . Errorf ( "cannot list snapshots: %w" , err )
2020-03-10 21:51:50 +00:00
jsonResponseError ( w , err )
2019-05-22 21:16:55 +00:00
return true
}
for _ , snapshotName := range snapshots {
if err := Storage . DeleteSnapshot ( snapshotName ) ; err != nil {
2020-06-30 19:58:18 +00:00
err = fmt . Errorf ( "cannot delete snapshot %q: %w" , snapshotName , err )
2020-03-10 21:51:50 +00:00
jsonResponseError ( w , err )
2019-05-22 21:16:55 +00:00
return true
}
}
fmt . Fprintf ( w , ` { "status":"ok"} ` )
return true
default :
return false
}
}
2022-05-04 20:56:09 +00:00
func initStaleSnapshotsRemover ( strg * storage . Storage ) {
2022-05-02 08:00:15 +00:00
staleSnapshotsRemoverCh = make ( chan struct { } )
2022-05-05 16:43:21 +00:00
if snapshotsMaxAge . Msecs <= 0 {
2022-05-02 08:00:15 +00:00
return
}
2022-05-05 16:43:21 +00:00
snapshotsMaxAgeDur := time . Duration ( snapshotsMaxAge . Msecs ) * time . Millisecond
2022-05-02 08:00:15 +00:00
staleSnapshotsRemoverWG . Add ( 1 )
go func ( ) {
defer staleSnapshotsRemoverWG . Done ( )
t := time . NewTicker ( 11 * time . Second )
defer t . Stop ( )
for {
select {
case <- staleSnapshotsRemoverCh :
return
case <- t . C :
}
2022-05-05 16:43:21 +00:00
if err := strg . DeleteStaleSnapshots ( snapshotsMaxAgeDur ) ; err != nil {
2022-05-02 08:00:15 +00:00
// Use logger.Errorf instead of logger.Fatalf in the hope the error is temporary.
logger . Errorf ( "cannot delete stale snapshots: %s" , err )
}
}
} ( )
}
func stopStaleSnapshotsRemover ( ) {
close ( staleSnapshotsRemoverCh )
staleSnapshotsRemoverWG . Wait ( )
}
var (
staleSnapshotsRemoverCh chan struct { }
staleSnapshotsRemoverWG sync . WaitGroup
)
2020-09-17 09:01:53 +00:00
var activeForceMerges = metrics . NewCounter ( "vm_active_force_merges" )
2022-05-04 20:56:09 +00:00
func registerStorageMetrics ( strg * storage . Storage ) {
2019-05-22 21:16:55 +00:00
mCache := & storage . Metrics { }
var mCacheLock sync . Mutex
var lastUpdateTime time . Time
m := func ( ) * storage . Metrics {
mCacheLock . Lock ( )
defer mCacheLock . Unlock ( )
if time . Since ( lastUpdateTime ) < time . Second {
return mCache
}
var mc storage . Metrics
2022-05-04 20:56:09 +00:00
strg . UpdateMetrics ( & mc )
2019-05-22 21:16:55 +00:00
mCache = & mc
lastUpdateTime = time . Now ( )
return mCache
}
tm := func ( ) * storage . TableMetrics {
sm := m ( )
return & sm . TableMetrics
}
idbm := func ( ) * storage . IndexDBMetrics {
sm := m ( )
return & sm . IndexDBMetrics
}
2020-04-01 20:08:58 +00:00
metrics . NewGauge ( fmt . Sprintf ( ` vm_free_disk_space_bytes { path=%q} ` , * DataPath ) , func ( ) float64 {
return float64 ( fs . MustGetFreeSpace ( * DataPath ) )
} )
2021-10-08 11:15:52 +00:00
metrics . NewGauge ( fmt . Sprintf ( ` vm_free_disk_space_limit_bytes { path=%q} ` , * DataPath ) , func ( ) float64 {
return float64 ( minFreeDiskSpaceBytes . N )
2021-10-08 09:52:56 +00:00
} )
2021-10-08 11:15:52 +00:00
metrics . NewGauge ( fmt . Sprintf ( ` vm_storage_is_read_only { path=%q} ` , * DataPath ) , func ( ) float64 {
2022-05-04 20:56:09 +00:00
if strg . IsReadOnly ( ) {
2021-10-08 09:52:56 +00:00
return 1
}
return 0
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_active_merges { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . ActiveInmemoryMerges )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_active_merges { type="storage/small"} ` , func ( ) float64 {
return float64 ( tm ( ) . ActiveSmallMerges )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_active_merges { type="storage/big"} ` , func ( ) float64 {
return float64 ( tm ( ) . ActiveBigMerges )
} )
metrics . NewGauge ( ` vm_active_merges { type="indexdb/inmemory"} ` , func ( ) float64 {
return float64 ( idbm ( ) . ActiveInmemoryMerges )
} )
metrics . NewGauge ( ` vm_active_merges { type="indexdb/file"} ` , func ( ) float64 {
return float64 ( idbm ( ) . ActiveFileMerges )
2019-05-22 21:16:55 +00:00
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_merges_total { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . InmemoryMergesCount )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_merges_total { type="storage/small"} ` , func ( ) float64 {
return float64 ( tm ( ) . SmallMergesCount )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_merges_total { type="storage/big"} ` , func ( ) float64 {
return float64 ( tm ( ) . BigMergesCount )
} )
metrics . NewGauge ( ` vm_merges_total { type="indexdb/inmemory"} ` , func ( ) float64 {
return float64 ( idbm ( ) . InmemoryMergesCount )
} )
metrics . NewGauge ( ` vm_merges_total { type="indexdb/file"} ` , func ( ) float64 {
return float64 ( idbm ( ) . FileMergesCount )
2019-05-22 21:16:55 +00:00
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_rows_merged_total { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . InmemoryRowsMerged )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_rows_merged_total { type="storage/small"} ` , func ( ) float64 {
return float64 ( tm ( ) . SmallRowsMerged )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_rows_merged_total { type="storage/big"} ` , func ( ) float64 {
return float64 ( tm ( ) . BigRowsMerged )
} )
metrics . NewGauge ( ` vm_rows_merged_total { type="indexdb/inmemory"} ` , func ( ) float64 {
return float64 ( idbm ( ) . InmemoryItemsMerged )
} )
metrics . NewGauge ( ` vm_rows_merged_total { type="indexdb/file"} ` , func ( ) float64 {
return float64 ( idbm ( ) . FileItemsMerged )
2019-05-22 21:16:55 +00:00
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_rows_deleted_total { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . InmemoryRowsDeleted )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_rows_deleted_total { type="storage/small"} ` , func ( ) float64 {
return float64 ( tm ( ) . SmallRowsDeleted )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_rows_deleted_total { type="storage/big"} ` , func ( ) float64 {
return float64 ( tm ( ) . BigRowsDeleted )
} )
2019-05-22 21:16:55 +00:00
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_part_references { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . InmemoryPartsRefCount )
2019-05-22 21:16:55 +00:00
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_part_references { type="storage/small"} ` , func ( ) float64 {
2019-05-22 21:16:55 +00:00
return float64 ( tm ( ) . SmallPartsRefCount )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_part_references { type="storage/big"} ` , func ( ) float64 {
return float64 ( tm ( ) . BigPartsRefCount )
} )
metrics . NewGauge ( ` vm_partition_references { type="storage"} ` , func ( ) float64 {
2019-05-22 21:16:55 +00:00
return float64 ( tm ( ) . PartitionsRefCount )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_object_references { type="indexdb"} ` , func ( ) float64 {
2019-05-22 21:16:55 +00:00
return float64 ( idbm ( ) . IndexDBRefCount )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_part_references { type="indexdb"} ` , func ( ) float64 {
2019-05-22 21:16:55 +00:00
return float64 ( idbm ( ) . PartsRefCount )
} )
2019-11-08 17:57:57 +00:00
metrics . NewGauge ( ` vm_new_timeseries_created_total ` , func ( ) float64 {
return float64 ( idbm ( ) . NewTimeseriesCreated )
} )
lib/index: reduce read/write load after indexDB rotation (#2177)
* lib/index: reduce read/write load after indexDB rotation
IndexDB in VM is responsible for storing TSID - ID's used for identifying
time series. The index is stored on disk and used by both ingestion and read path.
IndexDB is stored separately to data parts and is global for all stored data.
It can't be deleted partially as VM deletes data parts. Instead, indexDB is
rotated once in `retention` interval.
The rotation procedure means that `current` indexDB becomes `previous`,
and new freshly created indexDB struct becomes `current`. So in any time,
VM holds indexDB for current and previous retention periods.
When time series is ingested or queried, VM checks if its TSID is present
in `current` indexDB. If it is missing, it checks the `previous` indexDB.
If TSID was found, it gets copied to the `current` indexDB. In this way
`current` indexDB stores only series which were active during the retention
period.
To improve indexDB lookups, VM uses a cache layer called `tsidCache`. Both
write and read path consult `tsidCache` and on miss the relad lookup happens.
When rotation happens, VM resets the `tsidCache`. This is needed for ingestion
path to trigger `current` indexDB re-population. Since index re-population
requires additional resources, every index rotation event may cause some extra
load on CPU and disk. While it may be unnoticeable for most of the cases,
for systems with very high number of unique series each rotation may lead
to performance degradation for some period of time.
This PR makes an attempt to smooth out resource usage after the rotation.
The changes are following:
1. `tsidCache` is no longer reset after the rotation;
2. Instead, each entry in `tsidCache` gains a notion of indexDB to which
they belong;
3. On ingestion path after the rotation we check if requested TSID was
found in `tsidCache`. Then we have 3 branches:
3.1 Fast path. It was found, and belongs to the `current` indexDB. Return TSID.
3.2 Slow path. It wasn't found, so we generate it from scratch,
add to `current` indexDB, add it to `tsidCache`.
3.3 Smooth path. It was found but does not belong to the `current` indexDB.
In this case, we add it to the `current` indexDB with some probability.
The probability is based on time passed since the last rotation with some threshold.
The more time has passed since rotation the higher is chance to re-populate `current` indexDB.
The default re-population interval in this PR is set to `1h`, during which entries from
`previous` index supposed to slowly re-populate `current` index.
The new metric `vm_timeseries_repopulated_total` was added to identify how many TSIDs
were moved from `previous` indexDB to the `current` indexDB. This metric supposed to
grow only during the first `1h` after the last rotation.
https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1401
Signed-off-by: hagen1778 <roman@victoriametrics.com>
* wip
* wip
Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
2022-02-11 22:30:08 +00:00
metrics . NewGauge ( ` vm_timeseries_repopulated_total ` , func ( ) float64 {
return float64 ( idbm ( ) . TimeseriesRepopulated )
} )
2019-05-22 21:16:55 +00:00
metrics . NewGauge ( ` vm_missing_tsids_for_metric_id_total ` , func ( ) float64 {
return float64 ( idbm ( ) . MissingTSIDsForMetricID )
} )
2019-11-06 12:24:48 +00:00
metrics . NewGauge ( ` vm_index_blocks_with_metric_ids_processed_total ` , func ( ) float64 {
return float64 ( idbm ( ) . IndexBlocksWithMetricIDsProcessed )
} )
metrics . NewGauge ( ` vm_index_blocks_with_metric_ids_incorrect_order_total ` , func ( ) float64 {
return float64 ( idbm ( ) . IndexBlocksWithMetricIDsIncorrectOrder )
} )
2021-02-10 14:53:26 +00:00
metrics . NewGauge ( ` vm_composite_index_min_timestamp ` , func ( ) float64 {
return float64 ( idbm ( ) . MinTimestampForCompositeIndex ) / 1e3
} )
2021-02-17 17:13:38 +00:00
metrics . NewGauge ( ` vm_composite_filter_success_conversions_total ` , func ( ) float64 {
return float64 ( idbm ( ) . CompositeFilterSuccessConversions )
} )
metrics . NewGauge ( ` vm_composite_filter_missing_conversions_total ` , func ( ) float64 {
return float64 ( idbm ( ) . CompositeFilterMissingConversions )
} )
2019-05-22 21:16:55 +00:00
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_assisted_merges_total { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . InmemoryAssistedMerges )
2019-05-22 21:16:55 +00:00
} )
2022-12-13 00:49:21 +00:00
metrics . NewGauge ( ` vm_assisted_merges_total { type="storage/small"} ` , func ( ) float64 {
return float64 ( tm ( ) . SmallAssistedMerges )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_assisted_merges_total { type="indexdb/inmemory"} ` , func ( ) float64 {
2022-12-13 00:49:21 +00:00
return float64 ( idbm ( ) . InmemoryAssistedMerges )
} )
metrics . NewGauge ( ` vm_assisted_merges_total { type="indexdb/file"} ` , func ( ) float64 {
return float64 ( idbm ( ) . FileAssistedMerges )
2019-05-22 21:16:55 +00:00
} )
2022-04-21 10:18:05 +00:00
metrics . NewGauge ( ` vm_indexdb_items_added_total ` , func ( ) float64 {
return float64 ( idbm ( ) . ItemsAdded )
} )
metrics . NewGauge ( ` vm_indexdb_items_added_size_bytes_total ` , func ( ) float64 {
return float64 ( idbm ( ) . ItemsAddedSizeBytes )
} )
2020-09-29 18:47:40 +00:00
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/686
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_merge_need_free_disk_space ` , func ( ) float64 {
return float64 ( tm ( ) . MergeNeedFreeDiskSpace )
2020-09-29 18:47:40 +00:00
} )
2019-05-22 21:16:55 +00:00
metrics . NewGauge ( ` vm_pending_rows { type="storage"} ` , func ( ) float64 {
return float64 ( tm ( ) . PendingRows )
} )
metrics . NewGauge ( ` vm_pending_rows { type="indexdb"} ` , func ( ) float64 {
return float64 ( idbm ( ) . PendingItems )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_parts { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . InmemoryPartsCount )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_parts { type="storage/small"} ` , func ( ) float64 {
return float64 ( tm ( ) . SmallPartsCount )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_parts { type="storage/big"} ` , func ( ) float64 {
return float64 ( tm ( ) . BigPartsCount )
} )
metrics . NewGauge ( ` vm_parts { type="indexdb/inmemory"} ` , func ( ) float64 {
return float64 ( idbm ( ) . InmemoryPartsCount )
} )
metrics . NewGauge ( ` vm_parts { type="indexdb/file"} ` , func ( ) float64 {
return float64 ( idbm ( ) . FilePartsCount )
2019-05-22 21:16:55 +00:00
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_blocks { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . InmemoryBlocksCount )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_blocks { type="storage/small"} ` , func ( ) float64 {
return float64 ( tm ( ) . SmallBlocksCount )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_blocks { type="storage/big"} ` , func ( ) float64 {
return float64 ( tm ( ) . BigBlocksCount )
} )
metrics . NewGauge ( ` vm_blocks { type="indexdb/inmemory"} ` , func ( ) float64 {
return float64 ( idbm ( ) . InmemoryBlocksCount )
} )
metrics . NewGauge ( ` vm_blocks { type="indexdb/file"} ` , func ( ) float64 {
return float64 ( idbm ( ) . FileBlocksCount )
2019-05-22 21:16:55 +00:00
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_data_size_bytes { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . InmemorySizeBytes )
2019-07-04 16:09:40 +00:00
} )
metrics . NewGauge ( ` vm_data_size_bytes { type="storage/small"} ` , func ( ) float64 {
return float64 ( tm ( ) . SmallSizeBytes )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_data_size_bytes { type="storage/big"} ` , func ( ) float64 {
return float64 ( tm ( ) . BigSizeBytes )
} )
metrics . NewGauge ( ` vm_data_size_bytes { type="indexdb/inmemory"} ` , func ( ) float64 {
return float64 ( idbm ( ) . InmemorySizeBytes )
} )
metrics . NewGauge ( ` vm_data_size_bytes { type="indexdb/file"} ` , func ( ) float64 {
return float64 ( idbm ( ) . FileSizeBytes )
2019-07-04 16:09:40 +00:00
} )
2020-10-09 10:35:48 +00:00
metrics . NewGauge ( ` vm_rows_added_to_storage_total ` , func ( ) float64 {
return float64 ( m ( ) . RowsAddedTotal )
} )
2020-02-27 21:47:05 +00:00
metrics . NewGauge ( ` vm_deduplicated_samples_total { type="merge"} ` , func ( ) float64 {
return float64 ( m ( ) . DedupsDuringMerge )
} )
2019-07-26 17:00:35 +00:00
metrics . NewGauge ( ` vm_rows_ignored_total { reason="big_timestamp"} ` , func ( ) float64 {
2019-07-26 11:10:25 +00:00
return float64 ( m ( ) . TooBigTimestampRows )
} )
2019-07-26 17:00:35 +00:00
metrics . NewGauge ( ` vm_rows_ignored_total { reason="small_timestamp"} ` , func ( ) float64 {
2019-07-26 11:10:25 +00:00
return float64 ( m ( ) . TooSmallTimestampRows )
} )
2020-05-15 10:44:23 +00:00
metrics . NewGauge ( ` vm_slow_row_inserts_total ` , func ( ) float64 {
return float64 ( m ( ) . SlowRowInserts )
} )
metrics . NewGauge ( ` vm_slow_per_day_index_inserts_total ` , func ( ) float64 {
return float64 ( m ( ) . SlowPerDayIndexInserts )
} )
2020-05-15 11:11:39 +00:00
metrics . NewGauge ( ` vm_slow_metric_name_loads_total ` , func ( ) float64 {
return float64 ( m ( ) . SlowMetricNameLoads )
} )
2020-05-15 10:44:23 +00:00
2022-08-24 10:41:53 +00:00
if * maxHourlySeries > 0 {
metrics . NewGauge ( ` vm_hourly_series_limit_current_series ` , func ( ) float64 {
return float64 ( m ( ) . HourlySeriesLimitCurrentSeries )
} )
metrics . NewGauge ( ` vm_hourly_series_limit_max_series ` , func ( ) float64 {
return float64 ( m ( ) . HourlySeriesLimitMaxSeries )
} )
metrics . NewGauge ( ` vm_hourly_series_limit_rows_dropped_total ` , func ( ) float64 {
return float64 ( m ( ) . HourlySeriesLimitRowsDropped )
} )
}
if * maxDailySeries > 0 {
metrics . NewGauge ( ` vm_daily_series_limit_current_series ` , func ( ) float64 {
return float64 ( m ( ) . DailySeriesLimitCurrentSeries )
} )
metrics . NewGauge ( ` vm_daily_series_limit_max_series ` , func ( ) float64 {
return float64 ( m ( ) . DailySeriesLimitMaxSeries )
} )
metrics . NewGauge ( ` vm_daily_series_limit_rows_dropped_total ` , func ( ) float64 {
return float64 ( m ( ) . DailySeriesLimitRowsDropped )
} )
}
2021-05-20 11:15:19 +00:00
2020-09-09 20:18:32 +00:00
metrics . NewGauge ( ` vm_timestamps_blocks_merged_total ` , func ( ) float64 {
return float64 ( m ( ) . TimestampsBlocksMerged )
} )
metrics . NewGauge ( ` vm_timestamps_bytes_saved_total ` , func ( ) float64 {
return float64 ( m ( ) . TimestampsBytesSaved )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_rows { type="storage/inmemory"} ` , func ( ) float64 {
return float64 ( tm ( ) . InmemoryRowsCount )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_rows { type="storage/small"} ` , func ( ) float64 {
return float64 ( tm ( ) . SmallRowsCount )
} )
2022-12-05 23:15:00 +00:00
metrics . NewGauge ( ` vm_rows { type="storage/big"} ` , func ( ) float64 {
return float64 ( tm ( ) . BigRowsCount )
} )
metrics . NewGauge ( ` vm_rows { type="indexdb/inmemory"} ` , func ( ) float64 {
return float64 ( idbm ( ) . InmemoryItemsCount )
} )
metrics . NewGauge ( ` vm_rows { type="indexdb/file"} ` , func ( ) float64 {
return float64 ( idbm ( ) . FileItemsCount )
2019-05-22 21:16:55 +00:00
} )
2019-11-09 21:17:42 +00:00
metrics . NewGauge ( ` vm_date_range_search_calls_total ` , func ( ) float64 {
return float64 ( idbm ( ) . DateRangeSearchCalls )
} )
metrics . NewGauge ( ` vm_date_range_hits_total ` , func ( ) float64 {
return float64 ( idbm ( ) . DateRangeSearchHits )
} )
2021-07-30 05:37:10 +00:00
metrics . NewGauge ( ` vm_global_search_calls_total ` , func ( ) float64 {
return float64 ( idbm ( ) . GlobalSearchCalls )
} )
2019-11-09 21:17:42 +00:00
2019-12-02 18:44:18 +00:00
metrics . NewGauge ( ` vm_missing_metric_names_for_metric_id_total ` , func ( ) float64 {
return float64 ( idbm ( ) . MissingMetricNamesForMetricID )
} )
2019-11-11 11:21:05 +00:00
metrics . NewGauge ( ` vm_date_metric_id_cache_syncs_total ` , func ( ) float64 {
return float64 ( m ( ) . DateMetricIDCacheSyncsCount )
} )
metrics . NewGauge ( ` vm_date_metric_id_cache_resets_total ` , func ( ) float64 {
return float64 ( m ( ) . DateMetricIDCacheResetsCount )
} )
2019-05-22 21:16:55 +00:00
metrics . NewGauge ( ` vm_cache_entries { type="storage/tsid"} ` , func ( ) float64 {
return float64 ( m ( ) . TSIDCacheSize )
} )
metrics . NewGauge ( ` vm_cache_entries { type="storage/metricIDs"} ` , func ( ) float64 {
return float64 ( m ( ) . MetricIDCacheSize )
} )
metrics . NewGauge ( ` vm_cache_entries { type="storage/metricName"} ` , func ( ) float64 {
return float64 ( m ( ) . MetricNameCacheSize )
} )
metrics . NewGauge ( ` vm_cache_entries { type="storage/date_metricID"} ` , func ( ) float64 {
return float64 ( m ( ) . DateMetricIDCacheSize )
} )
2019-06-19 15:36:47 +00:00
metrics . NewGauge ( ` vm_cache_entries { type="storage/hour_metric_ids"} ` , func ( ) float64 {
return float64 ( m ( ) . HourMetricIDCacheSize )
} )
2020-05-11 22:06:17 +00:00
metrics . NewGauge ( ` vm_cache_entries { type="storage/next_day_metric_ids"} ` , func ( ) float64 {
return float64 ( m ( ) . NextDayMetricIDCacheSize )
} )
2022-01-20 16:34:59 +00:00
metrics . NewGauge ( ` vm_cache_entries { type="storage/indexBlocks"} ` , func ( ) float64 {
return float64 ( tm ( ) . IndexBlocksCacheSize )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_cache_entries { type="indexdb/dataBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . DataBlocksCacheSize )
} )
metrics . NewGauge ( ` vm_cache_entries { type="indexdb/indexBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . IndexBlocksCacheSize )
} )
2022-10-23 09:15:24 +00:00
metrics . NewGauge ( ` vm_cache_entries { type="indexdb/tagFiltersToMetricIDs"} ` , func ( ) float64 {
return float64 ( idbm ( ) . TagFiltersToMetricIDsCacheSize )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_cache_entries { type="storage/regexps"} ` , func ( ) float64 {
return float64 ( storage . RegexpCacheSize ( ) )
} )
2022-03-26 10:54:50 +00:00
metrics . NewGauge ( ` vm_cache_entries { type="storage/regexpPrefixes"} ` , func ( ) float64 {
return float64 ( storage . RegexpPrefixesCacheSize ( ) )
} )
2020-08-06 13:30:15 +00:00
metrics . NewGauge ( ` vm_cache_entries { type="storage/prefetchedMetricIDs"} ` , func ( ) float64 {
2020-01-29 23:59:43 +00:00
return float64 ( m ( ) . PrefetchedMetricIDsSize )
} )
2019-05-22 21:16:55 +00:00
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/tsid"} ` , func ( ) float64 {
2019-07-09 21:47:29 +00:00
return float64 ( m ( ) . TSIDCacheSizeBytes )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/metricIDs"} ` , func ( ) float64 {
2019-07-09 21:47:29 +00:00
return float64 ( m ( ) . MetricIDCacheSizeBytes )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/metricName"} ` , func ( ) float64 {
2019-07-09 21:47:29 +00:00
return float64 ( m ( ) . MetricNameCacheSizeBytes )
2019-05-22 21:16:55 +00:00
} )
2022-01-20 16:34:59 +00:00
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/indexBlocks"} ` , func ( ) float64 {
return float64 ( tm ( ) . IndexBlocksCacheSizeBytes )
2021-02-08 22:34:18 +00:00
} )
metrics . NewGauge ( ` vm_cache_size_bytes { type="indexdb/dataBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . DataBlocksCacheSizeBytes )
} )
metrics . NewGauge ( ` vm_cache_size_bytes { type="indexdb/indexBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . IndexBlocksCacheSizeBytes )
} )
2019-11-13 15:58:05 +00:00
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/date_metricID"} ` , func ( ) float64 {
return float64 ( m ( ) . DateMetricIDCacheSizeBytes )
} )
2019-11-13 17:00:02 +00:00
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/hour_metric_ids"} ` , func ( ) float64 {
return float64 ( m ( ) . HourMetricIDCacheSizeBytes )
} )
2020-05-11 22:06:17 +00:00
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/next_day_metric_ids"} ` , func ( ) float64 {
return float64 ( m ( ) . NextDayMetricIDCacheSizeBytes )
} )
2022-10-23 09:15:24 +00:00
metrics . NewGauge ( ` vm_cache_size_bytes { type="indexdb/tagFiltersToMetricIDs"} ` , func ( ) float64 {
return float64 ( idbm ( ) . TagFiltersToMetricIDsCacheSizeBytes )
2019-05-22 21:16:55 +00:00
} )
2022-03-26 10:54:50 +00:00
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/regexps"} ` , func ( ) float64 {
return float64 ( storage . RegexpCacheSizeBytes ( ) )
} )
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/regexpPrefixes"} ` , func ( ) float64 {
return float64 ( storage . RegexpPrefixesCacheSizeBytes ( ) )
} )
2020-01-29 23:59:43 +00:00
metrics . NewGauge ( ` vm_cache_size_bytes { type="storage/prefetchedMetricIDs"} ` , func ( ) float64 {
return float64 ( m ( ) . PrefetchedMetricIDsSizeBytes )
} )
2019-05-22 21:16:55 +00:00
2021-12-02 08:28:45 +00:00
metrics . NewGauge ( ` vm_cache_size_max_bytes { type="storage/tsid"} ` , func ( ) float64 {
return float64 ( m ( ) . TSIDCacheSizeMaxBytes )
} )
metrics . NewGauge ( ` vm_cache_size_max_bytes { type="storage/metricIDs"} ` , func ( ) float64 {
return float64 ( m ( ) . MetricIDCacheSizeMaxBytes )
} )
metrics . NewGauge ( ` vm_cache_size_max_bytes { type="storage/metricName"} ` , func ( ) float64 {
return float64 ( m ( ) . MetricNameCacheSizeMaxBytes )
} )
2022-01-20 16:34:59 +00:00
metrics . NewGauge ( ` vm_cache_size_max_bytes { type="storage/indexBlocks"} ` , func ( ) float64 {
return float64 ( tm ( ) . IndexBlocksCacheSizeMaxBytes )
2021-12-02 08:28:45 +00:00
} )
metrics . NewGauge ( ` vm_cache_size_max_bytes { type="indexdb/dataBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . DataBlocksCacheSizeMaxBytes )
} )
metrics . NewGauge ( ` vm_cache_size_max_bytes { type="indexdb/indexBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . IndexBlocksCacheSizeMaxBytes )
} )
2022-10-23 09:15:24 +00:00
metrics . NewGauge ( ` vm_cache_size_max_bytes { type="indexdb/tagFiltersToMetricIDs"} ` , func ( ) float64 {
return float64 ( idbm ( ) . TagFiltersToMetricIDsCacheSizeMaxBytes )
2021-12-02 08:28:45 +00:00
} )
2022-03-26 10:54:50 +00:00
metrics . NewGauge ( ` vm_cache_size_max_bytes { type="storage/regexps"} ` , func ( ) float64 {
return float64 ( storage . RegexpCacheMaxSizeBytes ( ) )
} )
metrics . NewGauge ( ` vm_cache_size_max_bytes { type="storage/regexpPrefixes"} ` , func ( ) float64 {
return float64 ( storage . RegexpPrefixesCacheMaxSizeBytes ( ) )
} )
2021-12-02 08:28:45 +00:00
2019-05-22 21:16:55 +00:00
metrics . NewGauge ( ` vm_cache_requests_total { type="storage/tsid"} ` , func ( ) float64 {
return float64 ( m ( ) . TSIDCacheRequests )
} )
metrics . NewGauge ( ` vm_cache_requests_total { type="storage/metricIDs"} ` , func ( ) float64 {
return float64 ( m ( ) . MetricIDCacheRequests )
} )
metrics . NewGauge ( ` vm_cache_requests_total { type="storage/metricName"} ` , func ( ) float64 {
return float64 ( m ( ) . MetricNameCacheRequests )
} )
2022-01-20 16:34:59 +00:00
metrics . NewGauge ( ` vm_cache_requests_total { type="storage/indexBlocks"} ` , func ( ) float64 {
return float64 ( tm ( ) . IndexBlocksCacheRequests )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_cache_requests_total { type="indexdb/dataBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . DataBlocksCacheRequests )
} )
metrics . NewGauge ( ` vm_cache_requests_total { type="indexdb/indexBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . IndexBlocksCacheRequests )
} )
2022-10-23 09:15:24 +00:00
metrics . NewGauge ( ` vm_cache_requests_total { type="indexdb/tagFiltersToMetricIDs"} ` , func ( ) float64 {
return float64 ( idbm ( ) . TagFiltersToMetricIDsCacheRequests )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_cache_requests_total { type="storage/regexps"} ` , func ( ) float64 {
return float64 ( storage . RegexpCacheRequests ( ) )
} )
2022-03-26 10:54:50 +00:00
metrics . NewGauge ( ` vm_cache_requests_total { type="storage/regexpPrefixes"} ` , func ( ) float64 {
return float64 ( storage . RegexpPrefixesCacheRequests ( ) )
} )
2019-05-22 21:16:55 +00:00
metrics . NewGauge ( ` vm_cache_misses_total { type="storage/tsid"} ` , func ( ) float64 {
return float64 ( m ( ) . TSIDCacheMisses )
} )
metrics . NewGauge ( ` vm_cache_misses_total { type="storage/metricIDs"} ` , func ( ) float64 {
return float64 ( m ( ) . MetricIDCacheMisses )
} )
metrics . NewGauge ( ` vm_cache_misses_total { type="storage/metricName"} ` , func ( ) float64 {
return float64 ( m ( ) . MetricNameCacheMisses )
} )
2022-01-20 16:34:59 +00:00
metrics . NewGauge ( ` vm_cache_misses_total { type="storage/indexBlocks"} ` , func ( ) float64 {
return float64 ( tm ( ) . IndexBlocksCacheMisses )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_cache_misses_total { type="indexdb/dataBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . DataBlocksCacheMisses )
} )
metrics . NewGauge ( ` vm_cache_misses_total { type="indexdb/indexBlocks"} ` , func ( ) float64 {
return float64 ( idbm ( ) . IndexBlocksCacheMisses )
} )
2022-10-23 09:15:24 +00:00
metrics . NewGauge ( ` vm_cache_misses_total { type="indexdb/tagFiltersToMetricIDs"} ` , func ( ) float64 {
return float64 ( idbm ( ) . TagFiltersToMetricIDsCacheMisses )
2019-05-22 21:16:55 +00:00
} )
metrics . NewGauge ( ` vm_cache_misses_total { type="storage/regexps"} ` , func ( ) float64 {
return float64 ( storage . RegexpCacheMisses ( ) )
} )
2022-03-26 10:54:50 +00:00
metrics . NewGauge ( ` vm_cache_misses_total { type="storage/regexpPrefixes"} ` , func ( ) float64 {
return float64 ( storage . RegexpPrefixesCacheMisses ( ) )
} )
2019-05-22 21:16:55 +00:00
metrics . NewGauge ( ` vm_deleted_metrics_total { type="indexdb"} ` , func ( ) float64 {
return float64 ( idbm ( ) . DeletedMetricsCount )
} )
metrics . NewGauge ( ` vm_cache_collisions_total { type="storage/tsid"} ` , func ( ) float64 {
return float64 ( m ( ) . TSIDCacheCollisions )
} )
metrics . NewGauge ( ` vm_cache_collisions_total { type="storage/metricName"} ` , func ( ) float64 {
return float64 ( m ( ) . MetricNameCacheCollisions )
} )
2022-07-13 09:37:04 +00:00
metrics . NewGauge ( ` vm_next_retention_seconds ` , func ( ) float64 {
return float64 ( m ( ) . NextRetentionSeconds )
} )
2019-05-22 21:16:55 +00:00
}
2020-03-10 21:51:50 +00:00
func jsonResponseError ( w http . ResponseWriter , err error ) {
logger . Errorf ( "%s" , err )
w . WriteHeader ( http . StatusInternalServerError )
fmt . Fprintf ( w , ` { "status":"error","msg":%q} ` , err )
}