@@ -26,10 +26,12 @@ function metrics({name, live}){
2626 . then ( response => response . json ( ) ) )
2727 . then ( data => Boolean ( data . message ) ? Promise . reject ( new Error ( data . message ) ) : data )
2828 . then ( data => {
29- console . log ( chalk . gray ( `| SUMMARY | Bytes in: ${ data . inBytes || 0 } | Bytes out: ${ data . outBytes || 0 } |` ) ) ;
29+ console . log ( chalk . green ( `Summary - ${ pad ( 16 , `Requests: ${ methodCounts ( data . methods ) } ` , ' ' ) } ${ pad ( 20 , `Incoming: ${ ( data . inBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB` , ' ' ) } ${ pad ( 20 , `Outgoing: ${ ( data . outBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB` , ' ' ) } \n` ) ) ;
30+
3031 Object . keys ( data . services )
3132 . map ( x => data . services [ x ] )
32- . forEach ( x => console . log ( chalk . gray ( `| ${ x . name } | Bytes in: ${ x . inBytes || 0 } | Bytes out: ${ x . outBytes || 0 } |` ) ) ) ;
33+ . filter ( x => name ? x . name === name : true )
34+ . forEach ( x => console . log ( chalk . gray ( `${ chalk . green ( x . name ) } - ${ pad ( 16 , `Requests: ${ methodCounts ( x . methods ) } ` , ' ' ) } ${ pad ( 20 , `Incoming: ${ ( x . inBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB` , ' ' ) } ${ pad ( 20 , `Outgoing: ${ ( x . outBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB` , ' ' ) } ` ) ) ) ;
3335 } )
3436 . catch ( err => {
3537 process . stderr . write ( '\x1B[?25h' ) ; //show terminal cursor
@@ -77,22 +79,24 @@ function metricsLive(name){
7779 } catch ( e ) { } ;
7880 if ( ! data . services ) return ;
7981
80- const allMethodsCount = methodCounts ( data . methods ) ;
81- process . stdout . clearLine ( ) ;
8282 process . stdout . cursorTo ( 0 ) ;
83- console . log ( chalk . green ( `Requests: ${ allMethodsCount } Incoming: ${ ( data . inBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB Outgoing: ${ ( data . outBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB` ) ) ;
84- const services = Object . keys ( data . services ) . map ( x => data . services [ x ] ) ;
83+ process . stdout . clearLine ( ) ;
84+ console . log ( chalk . green ( `Summary - ${ pad ( 16 , `Requests: ${ methodCounts ( data . methods ) } ` , ' ' ) } ${ pad ( 20 , `Incoming: ${ ( data . inBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB` , ' ' ) } ${ pad ( 20 , `Outgoing: ${ ( data . outBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB` , ' ' ) } \n` ) ) ;
85+
86+ const services = Object . keys ( data . services ) . map ( x => data . services [ x ] ) . filter ( x => name ? x . name === name : true ) ;
8587 services
8688 . forEach ( x => {
8789 process . stdout . cursorTo ( 0 ) ;
8890 process . stdout . clearLine ( ) ;
89- console . log ( chalk . gray ( `| ${ x . name } | Bytes in: ${ x . inBytes || 0 } | Bytes out: ${ x . outBytes || 0 } |` ) ) ;
90-
91+ console . log ( chalk . gray ( `${ chalk . green ( x . name ) } - ${ pad ( 16 , `Requests: ${ methodCounts ( x . methods ) } ` , ' ' ) } ${ pad ( 20 , `Incoming: ${ ( x . inBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB` , ' ' ) } ${ pad ( 20 , `Outgoing: ${ ( x . outBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) || 0 } MB` , ' ' ) } ` ) ) ;
9192 } ) ;
92- process . stdout . moveCursor ( 0 , ( services . length + 1 ) * - 1 ) ;
93+ process . stdout . moveCursor ( 0 , ( services . length + 2 ) * - 1 ) ;
9394 } ;
9495
95- es . onerror = ( ) => console . log ( chalk . red ( '\nSorry, unexpected server communication error. Retry later please!' ) ) ;
96+ es . onerror = ( ) => {
97+ process . stderr . write ( '\x1B[?25h' ) ; //show terminal cursor
98+ console . log ( chalk . red ( '\nSorry, unexpected server communication error. Retry later please!' ) ) ;
99+ } ;
96100 } )
97101 . catch ( err => {
98102 process . stderr . write ( '\x1B[?25h' ) ; //show terminal cursor
@@ -117,8 +121,8 @@ function metricsLive(name){
117121 process . exit ( 1 ) ;
118122 }
119123
120- if ( err . message === 'Server communication error' ) {
121- console . error ( chalk . red ( `\nSorry, server communication error occured . Retry later please!` ) )
124+ if ( err . message === 'Unexpected server communication error' ) {
125+ console . error ( chalk . red ( `\nSorry, unexpected server communication error. Retry later please!` ) )
122126 return process . exit ( 1 ) ;
123127 }
124128
0 commit comments