github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/apps/sys.monitor/site.main.src/src/data/EmuProvider.js (about) 1 /* 2 * Copyright (c) 2022-present unTill Pro, Ltd. 3 */ 4 5 import { ResMetrics, ResWorstApps } from "./Resources"; 6 7 const SCRAPE_INTVL = 15 8 9 const emuValues = { 10 /////////////////////////////////// 11 // HTTP 12 heeus_http_status_2xx_total: 200 * SCRAPE_INTVL, 13 heeus_http_status_4xx_total: 50 * SCRAPE_INTVL, 14 heeus_http_status_5xx_total: 50 * SCRAPE_INTVL, 15 heeus_http_status_503_total: 20 * SCRAPE_INTVL, 16 /////////////////////////////////// 17 // IStorageCache 18 heeus_istoragecache_get_total: 100 * SCRAPE_INTVL, 19 heeus_istoragecache_get_cached_total: { 20 value: 35 * SCRAPE_INTVL, 21 max: 'heeus_istoragecache_get_total', 22 }, 23 heeus_istoragecache_getbatch_total: 120 * SCRAPE_INTVL, 24 heeus_istoragecache_getbatch_cached_total: { 25 value: 60 * SCRAPE_INTVL, 26 max: 'heeus_istoragecache_getbatch_total', 27 }, 28 heeus_istoragecache_put_total: 50 * SCRAPE_INTVL, 29 heeus_istoragecache_putbatch_total: 60 * SCRAPE_INTVL, 30 heeus_istoragecache_read_total: 80 * SCRAPE_INTVL, 31 heeus_istoragecache_get_seconds: 2 * SCRAPE_INTVL, 32 heeus_istoragecache_getbatch_seconds: 7 * SCRAPE_INTVL, 33 heeus_istoragecache_put_seconds: 3 * SCRAPE_INTVL, 34 heeus_istoragecache_putbatch_seconds: 12 * SCRAPE_INTVL, 35 heeus_istoragecache_read_seconds: 6 * SCRAPE_INTVL, 36 37 /////////////////////////////////// 38 // Command Processor 39 heeus_cp_commands_total: 100 * SCRAPE_INTVL, 40 heeus_cp_commands_seconds: 2 * SCRAPE_INTVL, 41 heeus_cp_exec_seconds: 1 * SCRAPE_INTVL, 42 heeus_cp_validate_seconds: 0.5 * SCRAPE_INTVL, 43 heeus_cp_putplog_seconds: 0.5 * SCRAPE_INTVL, 44 45 /////////////////////////////////// 46 // Query Processor 47 heeus_qp_queries_total: 200 * SCRAPE_INTVL, 48 heeus_qp_queries_seconds: 4 * SCRAPE_INTVL, 49 heeus_qp_build_seconds: 1 * SCRAPE_INTVL, 50 heeus_qp_exec_seconds: 3 * SCRAPE_INTVL, 51 heeus_qp_exec_fields_seconds: 0.5 * SCRAPE_INTVL, 52 heeus_qp_exec_enrich_seconds: 0.5 * SCRAPE_INTVL, 53 heeus_qp_exec_filter_seconds: 0.5 * SCRAPE_INTVL, 54 heeus_qp_exec_order_seconds: 0.5 * SCRAPE_INTVL, 55 heeus_qp_exec_count_seconds: 0.5 * SCRAPE_INTVL, 56 heeus_qp_exec_send_seconds: 0.5 * SCRAPE_INTVL, 57 58 /////////////////////////////////// 59 // Node Metrics 60 node_cpu_idle_seconds_total: 0.2 * SCRAPE_INTVL, 61 node_memory_memavailable_bytes: { 62 value: 32000000000, 63 gauge: true, 64 max: 64000000000, 65 min: 3000000000, 66 offs: 100000000, 67 }, 68 node_memory_memtotal_bytes: { 69 value: 64000000000, 70 fixed: true, 71 }, 72 node_filesystem_free_bytes: { 73 value: 2000000000000, 74 gauge: true, 75 max: 4000000000000, 76 min: 10000000000, 77 offs: 800000000, 78 }, 79 node_filesystem_size_bytes: { 80 value: 4000000000000, 81 fixed: true, 82 }, 83 node_disk_read_bytes_total: 100000, 84 node_disk_write_bytes_total: 50000, 85 node_disk_reads_completed_total: 20000, 86 node_disk_writes_completed_total: 10000, 87 } 88 89 const EMULATE_LOADING_SEC = 1 90 91 export function rnd(min, max) { 92 return min + Math.random() * (max - min); 93 } 94 95 export function EmuMetrics(app, metrics, interval, hvms) { 96 var result = [] 97 const now = new Date() 98 const before = new Date(now.getTime() - interval * 1000) 99 var t = new Date(before.getTime()) 100 var values = {} 101 var offsets = {} 102 if (!hvms) { 103 hvms = [""] 104 } 105 while (t < now) { 106 metrics.map((metric) => { 107 const emuVal = emuValues[metric] 108 var init = emuVal 109 var min = null 110 var max = null 111 var offs = null 112 var fixed = false 113 var gauge = false 114 if (typeof emuVal !== 'number') { 115 init = emuVal.value 116 min = emuVal.min 117 max = emuVal.max 118 if (typeof emuVal.offs === 'number') { 119 offs = emuVal.offs 120 } 121 fixed = emuVal.fixed 122 gauge = emuVal.gauge 123 } 124 if (!offs) { 125 offs = init / 5 126 } 127 128 129 hvms.map((hvm) => { 130 const keyprefix = hvm + "__" 131 const key = keyprefix + metric 132 133 if (values[key]===undefined || fixed) { 134 values[key] = init 135 } else { 136 if (offsets[key]===undefined) { 137 offsets[key] = gauge ? 1 : offs 138 } else { 139 if (gauge) { 140 offsets[key] = offsets[key]+rnd(-offs, offs) 141 } else { 142 offsets[key] = Math.max(0, offsets[key]+rnd(-offs, offs)) 143 } 144 } 145 146 if (gauge) { 147 values[key] = values[key] + offsets[key] 148 if (typeof max === 'number' && values[key] > max) { 149 values[key] = max 150 offsets[key] = 0 151 } 152 if (typeof min === 'number' && values[key] < min) { 153 values[key] = min 154 offsets[key] = 0 155 } 156 } else { // counter 157 if (typeof max === 'string' && offsets[key] > offsets[keyprefix+max]) { 158 offsets[key] = offsets[keyprefix+max] 159 } else if (typeof max === 'number' && offsets[key] > max) { 160 offsets[key] = max 161 } 162 values[key] = values[key] + offsets[key] 163 } 164 } 165 166 167 168 var mv = { 169 id: 0, 170 time: t.getTime(), 171 metric: metric, 172 hvm: hvm, 173 app: app, 174 value: values[key], 175 } 176 result.push(mv) 177 return true 178 }) 179 }) 180 t.setSeconds(t.getSeconds() + SCRAPE_INTVL) 181 } 182 return result 183 } 184 185 function EmuWorstApps() { 186 return { 187 moreGetTop5AppsByRT : [ 188 {app: 'untill/air', value: 940}, 189 {app: 'sys/monitor', value: 20430}, 190 {app: 'sys/registry', value: 2114640}, 191 ], 192 moreGetTop5AppsByRPS: [ 193 {app: 'untill/air', value: 12034}, 194 {app: 'sys/registry', value: 456}, 195 {app: 'sys/monitor', value: 67}, 196 ], 197 moreGetBottom5AppsByCacheHits: [ 198 {app: 'untill/air', value: 45}, 199 {app: 'sys/registry', value: 32}, 200 {app: 'sys/monitor', value: 8}, 201 ], 202 moreGetBatchTop5AppsByRT : [ 203 {app: 'untill/air', value: 30}, 204 {app: 'sys/monitor', value: 41}, 205 {app: 'sys/registry', value: 62}, 206 ], 207 moreGetBatchTop5AppsByRPS : [ 208 {app: 'untill/air', value: 12034}, 209 {app: 'sys/registry', value: 456}, 210 {app: 'sys/monitor', value: 67}, 211 ], 212 moreGetBatchBottom5AppsByCacheHits : [ 213 {app: 'untill/air', value: 45}, 214 {app: 'sys/registry', value: 32}, 215 {app: 'sys/monitor', value: 8}, 216 ], 217 morePutTop5AppsByRT : [ 218 {app: 'untill/air', value: 940}, 219 {app: 'sys/monitor', value: 20430}, 220 {app: 'sys/registry', value: 2114640}, 221 ], 222 morePutTop5AppsByRPS: [ 223 {app: 'untill/air', value: 12034}, 224 {app: 'sys/registry', value: 456}, 225 {app: 'sys/monitor', value: 67}, 226 ], 227 moreReadTop5AppsByRT : [ 228 {app: 'untill/air', value: 940}, 229 {app: 'sys/monitor', value: 20430}, 230 {app: 'sys/registry', value: 2114640}, 231 ], 232 moreReadTop5AppsByRPS: [ 233 {app: 'untill/air', value: 12034}, 234 {app: 'sys/registry', value: 456}, 235 {app: 'sys/monitor', value: 67}, 236 ], 237 morePutBatchTop5AppsByRT : [ 238 {app: 'untill/air', value: 940}, 239 {app: 'sys/monitor', value: 20430}, 240 {app: 'sys/registry', value: 2114640}, 241 ], 242 morePutBatchTop5AppsByRPS: [ 243 {app: 'untill/air', value: 12034}, 244 {app: 'sys/registry', value: 456}, 245 {app: 'sys/monitor', value: 67}, 246 ], 247 morePutBatchTop5AppsByBatchSize: [ 248 {app: 'untill/air', value: 60}, 249 {app: 'sys/registry', value: 12}, 250 {app: 'sys/monitor', value: 6}, 251 ] 252 } 253 } 254 255 export default { 256 getList: (resource, params) => { 257 }, 258 259 getOne: (resource, params) => { 260 return new Promise((resolve, reject) => { 261 setTimeout(() => { 262 var emuData 263 switch (resource) { 264 case ResWorstApps: 265 emuData = EmuWorstApps(); 266 break; 267 default: 268 emuData = null; 269 } 270 emuData.id = 0 271 resolve({ 272 data: emuData 273 }) 274 }, rnd(EMULATE_LOADING_SEC - EMULATE_LOADING_SEC/4, EMULATE_LOADING_SEC + EMULATE_LOADING_SEC/4)*1000); 275 }); 276 }, 277 278 getMany: (resource, params) => { 279 return new Promise((resolve, reject) => { 280 const { app, metrics, interval, hvms } = params.meta; 281 setTimeout(() => { 282 var emuData 283 switch (resource) { 284 case ResMetrics: 285 emuData = EmuMetrics(app, metrics, interval, hvms); 286 break; 287 default: 288 emuData = null; 289 } 290 resolve({ 291 data: emuData 292 }) 293 }, rnd(EMULATE_LOADING_SEC - EMULATE_LOADING_SEC/4, EMULATE_LOADING_SEC + EMULATE_LOADING_SEC/4)*1000); 294 }); 295 }, 296 297 getManyReference: () => {}, 298 299 create: () => {}, 300 301 update: () => {}, 302 303 updateMany: () => {}, 304 305 delete: () => {}, 306 307 deleteMany: () => {}, 308 };