{"record":{"id":"10247dadd0541c98","repo":"microsoft/garnet","slug":"latencymonitor-requires-metricssamplingfrequency-t","errorCode":null,"errorMessage":"LatencyMonitor requires MetricsSamplingFrequency to be set","messagePattern":"LatencyMonitor requires MetricsSamplingFrequency to be set","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/server/Servers/GarnetServerOptions.cs","lineNumber":755,"sourceCode":"                logger?.LogInformation(\"[Store] Hash index max size is optimized for up to ~{distinctKeys} distinct keys\", PrettySize(AdjustedIndexMaxCacheLines * 4L));\n            }\n            logger?.LogInformation(\"[Store] Using log mutable percentage of {MutablePercent}%\", MutablePercent);\n\n            if (DeviceType == DeviceType.Default)\n                DeviceType = Devices.GetDefaultDeviceType();\n            DeviceFactoryCreator ??= new LocalStorageNamedDeviceFactoryCreator(\n                deviceType: DeviceType,\n                ioBackend: DeviceIoBackend,\n                numCompletionThreads: DeviceCompletionThreads,\n                throttleLimit: DeviceThrottleLimit > 0 ? DeviceThrottleLimit : null,\n                logger: logger);\n            if (DeviceType == DeviceType.Native && OperatingSystem.IsLinux())\n                logger?.LogInformation(\"Using device type {deviceType} (io-backend={ioBackend}, completion-threads={ct}, throttle-limit={tl})\", DeviceType, DeviceIoBackend, DeviceCompletionThreads, DeviceThrottleLimit > 0 ? DeviceThrottleLimit.ToString() : \"device-default\");\n            else\n                logger?.LogInformation(\"Using device type {deviceType} (throttle-limit={tl})\", DeviceType, DeviceThrottleLimit > 0 ? DeviceThrottleLimit.ToString() : \"device-default\");\n\n            if (LatencyMonitor && MetricsSamplingFrequency == 0)\n                throw new Exception(\"LatencyMonitor requires MetricsSamplingFrequency to be set\");\n\n            // Read cache related settings\n            if (EnableReadCache)\n            {\n                if (!EnableStorageTier)\n                    throw new Exception(\"Read cache requires storage tiering to be enabled\");\n                kvSettings.ReadCacheEnabled = true;\n\n                if (ReadCachePageCount != 0)\n                    kvSettings.ReadCachePageCount = ReadCachePageCount;\n\n                kvSettings.ReadCachePageSize = 1L << ReadCachePageSizeBits();\n                kvSettings.ReadCacheMemorySize = ParseSize(ReadCacheMemorySize, out _);\n\n                if (kvSettings.ReadCacheMemorySize > 0)\n                {\n                    var pageCount = kvSettings.ReadCacheMemorySize / kvSettings.ReadCachePageSize;\n                    if (kvSettings.PageCount > pageCount)","sourceCodeStart":737,"sourceCodeEnd":773,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/server/Servers/GarnetServerOptions.cs#L737-L773","documentation":"Latency tracking (LatencyMonitor) depends on the periodic metrics sampling task, which is driven by MetricsSamplingFrequency in seconds. If you enable latency monitoring but leave the sampling frequency at 0, the sampling task never runs, so the check at GetSettings refuses to start rather than silently producing no latency data.","triggerScenarios":"Starting with --latency-monitor but with --metrics-sampling-freq unset or 0. Thrown at GarnetServerOptions.cs:754-755.","commonSituations":"Enabling latency monitoring in isolation without also turning on the metrics sampling cadence; assuming --latency-monitor self-schedules.","solutions":["Set a positive --metrics-sampling-freq (seconds), e.g. --metrics-sampling-freq 1, alongside --latency-monitor.","If you do not actually need latency tracking, drop --latency-monitor.","Document the pairing in your deployment config so the two flags are always set together."],"exampleFix":"# before (fails)\ngarnet-server --latency-monitor\n\n# after\ngarnet-server --latency-monitor --metrics-sampling-freq 1","handlingStrategy":"validation","validationCode":"if (options.LatencyMonitor && options.MetricsSamplingFrequency == 0) {\n    throw new InvalidOperationException(\"LatencyMonitor requires MetricsSamplingFrequency > 0\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair --latency-monitor with a positive --metrics-sampling-freq.","Add a deployment-template check that the two are set together."],"tags":["garnet","config","metrics","dotnet"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}