@@ -21,50 +21,17 @@ const updateCollectorMeta = (name, patch) => {
2121 return next
2222}
2323
24- // Metric files capacity weights per metric
25- const CAPACITY_WEIGHTS = {
26- memory : 0.30 ,
27- monitor : 0.25 ,
28- commandlog_slow : 0.10 ,
29- commandlog_large_reply : 0.10 ,
30- commandlog_large_request : 0.10 ,
31- cpu : 0.10 ,
32- slowlog_len : 0.05 ,
33- }
34-
3524const MIN_FILE_SIZE = 256 * 1024 // 256 KB
3625const MAX_FILE_SIZE = 10 * 1024 * 1024 // 10 MB
3726const MIN_FILES = 4
3827
39- const computeCapacity = ( weight , totalMb ) => {
40- const capacityBytes = weight * totalMb * 1024 * 1024
28+ const computeCapacity = ( retentionMb ) => {
29+ const capacityBytes = retentionMb * 1024 * 1024
4130 const maxFileSize = Math . min ( MAX_FILE_SIZE , Math . max ( MIN_FILE_SIZE , Math . floor ( capacityBytes / MIN_FILES ) ) )
4231 const maxFiles = Math . max ( MIN_FILES , Math . floor ( capacityBytes / maxFileSize ) )
4332 return { maxFiles, maxFileSize }
4433}
4534
46- const warnIfStorageTooSmall = ( retentionSizeMb , weights ) => {
47- const smallestWeight = Math . min ( ...Object . values ( weights ) )
48- const minTotalBytes = ( MIN_FILE_SIZE * MIN_FILES ) / smallestWeight
49- const minTotalMb = Math . ceil ( minTotalBytes / ( 1024 * 1024 ) )
50- if ( retentionSizeMb < minTotalMb ) {
51- console . warn (
52- `retention_size_mb ${ retentionSizeMb } is below minimum ${ minTotalMb } for active epics — ` +
53- `per-metric capacity will be clamped to at least ${ MIN_FILES } files × ${ MIN_FILE_SIZE / 1024 } KB` ,
54- )
55- }
56- }
57-
58- const normalizeWeights = ( epics ) => {
59- const activeEpicPrefixes = epics . map ( ( e ) => e . file_prefix || e . name )
60- const rawTotal = activeEpicPrefixes . reduce ( ( sum , epicPrefix ) => sum + ( CAPACITY_WEIGHTS [ epicPrefix ] ?? 0 ) , 0 )
61- if ( rawTotal === 0 ) {
62- const equal = 1 / activeEpicPrefixes . length
63- return Object . fromEntries ( activeEpicPrefixes . map ( ( p ) => [ p , equal ] ) )
64- }
65- return Object . fromEntries ( activeEpicPrefixes . map ( ( p ) => [ p , ( CAPACITY_WEIGHTS [ p ] ?? 0 ) / rawTotal ] ) )
66- }
67-
6835// Use it in endpoints to return metadata to server then to UI
6936// to show when the data was collected and will be refreshed
7037export const getCollectorMeta = ( name ) => collectorsState [ name ]
@@ -75,18 +42,15 @@ updateCollectorMeta(MONITOR, {
7542 isRunning : false ,
7643} )
7744const startMonitor = ( cfg ) => {
78- const weights = normalizeWeights ( cfg . epics )
79- warnIfStorageTooSmall ( cfg . storage . retention_size_mb , weights )
80- const { maxFiles, maxFileSize } = computeCapacity ( weights [ MONITOR ] , cfg . storage . retention_size_mb )
45+ const monitorEpic = cfg . epics . find ( ( e ) => e . name === MONITOR )
46+ const { maxFiles, maxFileSize } = computeCapacity ( monitorEpic . data_retention_mb )
8147 const nd = makeNdjsonWriter ( {
8248 dataDir : cfg . server . data_dir ,
83- filePrefix : MONITOR ,
49+ filePrefix : monitorEpic . file_prefix || MONITOR ,
8450 maxFiles,
8551 maxFileSize,
8652 } )
8753
88- const monitorEpic = cfg . epics . find ( ( e ) => e . name === MONITOR )
89-
9054 const sink = {
9155 appendRows : async ( rows ) => {
9256 await nd . appendRows ( rows )
@@ -145,15 +109,13 @@ const startMonitor = (cfg) => {
145109const stopMonitor = async ( ) => await monitorStopper ( )
146110
147111const setupCollectors = async ( client , cfg ) => {
148- const weights = normalizeWeights ( cfg . epics )
149- warnIfStorageTooSmall ( cfg . storage . retention_size_mb , weights )
150112 const fetcher = makeFetcher ( client )
151113 await Promise . all ( cfg . epics
152114 . filter ( ( f ) => f . name !== MONITOR && fetcher [ f . type ] )
153115 . map ( async ( f ) => {
154116 const fn = fetcher [ f . type ]
155117 const prefix = f . file_prefix || f . name
156- const { maxFiles, maxFileSize } = computeCapacity ( weights [ prefix ] , cfg . storage . retention_size_mb )
118+ const { maxFiles, maxFileSize } = computeCapacity ( f . data_retention_mb )
157119 const nd = makeNdjsonWriter ( {
158120 dataDir : cfg . server . data_dir ,
159121 filePrefix : prefix ,
0 commit comments