(client)
| 85 | } |
| 86 | |
| 87 | function visualizeMonitoringEvents(client) { |
| 88 | function print(msg) { |
| 89 | console.error(`${chalk.white(new Date().toISOString())} ${msg}`); |
| 90 | } |
| 91 | |
| 92 | client.on('serverHeartbeatStarted', event => |
| 93 | print(`${chalk.yellow('heartbeat')} ${chalk.bold('started')} host: '${event.connectionId}`) |
| 94 | ); |
| 95 | |
| 96 | client.on('serverHeartbeatSucceeded', event => |
| 97 | print( |
| 98 | `${chalk.yellow('heartbeat')} ${chalk.green('succeeded')} host: '${ |
| 99 | event.connectionId |
| 100 | }' ${chalk.gray(`(${event.duration} ms)`)}` |
| 101 | ) |
| 102 | ); |
| 103 | |
| 104 | client.on('serverHeartbeatFailed', event => |
| 105 | print( |
| 106 | `${chalk.yellow('heartbeat')} ${chalk.red('failed')} host: '${ |
| 107 | event.connectionId |
| 108 | }' ${chalk.gray(`(${event.duration} ms)`)}` |
| 109 | ) |
| 110 | ); |
| 111 | |
| 112 | // server information |
| 113 | client.on('serverOpening', event => { |
| 114 | print( |
| 115 | `${chalk.cyan('server')} [${event.address}] ${chalk.bold('opening')} in topology#${ |
| 116 | event.topologyId |
| 117 | }` |
| 118 | ); |
| 119 | }); |
| 120 | |
| 121 | client.on('serverClosed', event => { |
| 122 | print( |
| 123 | `${chalk.cyan('server')} [${event.address}] ${chalk.bold('closed')} in topology#${ |
| 124 | event.topologyId |
| 125 | }` |
| 126 | ); |
| 127 | }); |
| 128 | |
| 129 | client.on('serverDescriptionChanged', event => { |
| 130 | print(`${chalk.cyan('server')} [${event.address}] changed:`); |
| 131 | console.error(serverDescriptionDiff(event.previousDescription, event.newDescription)); |
| 132 | }); |
| 133 | |
| 134 | // topology information |
| 135 | client.on('topologyOpening', event => { |
| 136 | print(`${chalk.magenta('topology')} adding topology#${event.topologyId}`); |
| 137 | }); |
| 138 | |
| 139 | client.on('topologyClosed', event => { |
| 140 | print(`${chalk.magenta('topology')} removing topology#${event.topologyId}`); |
| 141 | }); |
| 142 | |
| 143 | client.on('topologyDescriptionChanged', event => { |
| 144 | const diff = topologyDescriptionDiff(event.previousDescription, event.newDescription); |
no test coverage detected