|
| 1 | +import { SchemaComposer, ObjectTypeComposerFieldConfigDefinition } from 'graphql-compose'; |
| 2 | +import { Options } from '../../definitions'; |
| 3 | +import { getBullConnection } from '../../helpers/getBullConnection'; |
| 4 | + |
| 5 | +export function createMemoryFC( |
| 6 | + sc: SchemaComposer<any>, |
| 7 | + opts: Options |
| 8 | +): ObjectTypeComposerFieldConfigDefinition<any, any> { |
| 9 | + const { typePrefix } = opts; |
| 10 | + |
| 11 | + return { |
| 12 | + type: sc.createObjectTC({ |
| 13 | + name: `${typePrefix}InfoMemory`, |
| 14 | + fields: { |
| 15 | + used_memory: 'String', |
| 16 | + used_memory_human: 'String', |
| 17 | + used_memory_rss: 'String', |
| 18 | + used_memory_rss_human: 'String', |
| 19 | + used_memory_peak: 'String', |
| 20 | + used_memory_peak_human: 'String', |
| 21 | + used_memory_peak_perc: 'String', |
| 22 | + used_memory_overhead: 'String', |
| 23 | + used_memory_startup: 'String', |
| 24 | + used_memory_dataset: 'String', |
| 25 | + used_memory_dataset_perc: 'String', |
| 26 | + allocator_allocated: 'String', |
| 27 | + allocator_active: 'String', |
| 28 | + allocator_resident: 'String', |
| 29 | + total_system_memory: 'String', |
| 30 | + total_system_memory_human: 'String', |
| 31 | + used_memory_lua: 'String', |
| 32 | + used_memory_lua_human: 'String', |
| 33 | + used_memory_scripts: 'String', |
| 34 | + used_memory_scripts_human: 'String', |
| 35 | + number_of_cached_scripts: 'String', |
| 36 | + maxmemory: 'String', |
| 37 | + maxmemory_human: 'String', |
| 38 | + maxmemory_policy: 'String', |
| 39 | + allocator_frag_ratio: 'String', |
| 40 | + allocator_frag_bytes: 'String', |
| 41 | + allocator_rss_ratio: 'String', |
| 42 | + allocator_rss_bytes: 'String', |
| 43 | + rss_overhead_ratio: 'String', |
| 44 | + rss_overhead_bytes: 'String', |
| 45 | + mem_fragmentation_ratio: 'String', |
| 46 | + mem_fragmentation_bytes: 'String', |
| 47 | + mem_not_counted_for_evict: 'String', |
| 48 | + mem_replication_backlog: 'String', |
| 49 | + mem_clients_slaves: 'String', |
| 50 | + mem_clients_normal: 'String', |
| 51 | + mem_aof_buffer: 'String', |
| 52 | + mem_allocator: 'String', |
| 53 | + active_defrag_running: 'String', |
| 54 | + lazyfree_pending_objects: 'String', |
| 55 | + }, |
| 56 | + }), |
| 57 | + resolve: async () => { |
| 58 | + const redis = getBullConnection(opts); |
| 59 | + const memoryInfo = await redis.info('memory'); |
| 60 | + return memoryInfo |
| 61 | + .split('\r\n') |
| 62 | + .filter((item) => item.includes(':')) |
| 63 | + .map((item) => item.split(':')) |
| 64 | + .reduce((acc, metric) => ({ ...acc, [metric[0]]: metric[1] }), {}); |
| 65 | + }, |
| 66 | + }; |
| 67 | +} |
0 commit comments