@@ -8,15 +8,19 @@ const EventSource = require('eventsource');
88const configuration = require ( '../lib/settings' ) ( ) ;
99
1010program
11- . arguments ( '<name>' )
12- . option ( '-l, --live' , 'Output as Live-Stream.' )
13- . action ( name => metrics ( Object . assign ( { name : name } , program ) ) )
11+ . arguments ( '[name]' )
12+ . option ( '-f, --nofollow' , 'Do not follow stream' )
13+ . option ( '-a, --all' , 'Show online and offline deployments.' )
14+ . action ( name => metricsLive ( {
15+ name : name ,
16+ all : program . all ,
17+ nofollow : program . nofollow ,
18+ } ) )
1419 . parse ( process . argv ) ;
1520
16- if ( ! program . args . length ) metrics ( program . opts ( ) ) ;
21+ if ( ! program . args . length ) metricsLive ( program . opts ( ) ) ;
1722
18- function metrics ( { name, live} ) {
19- if ( live ) return metricsLive ( name )
23+ function metrics ( { name, all} ) {
2024 configuration
2125 . load ( )
2226 . then ( settings => { console . log ( `Metrics for ${ chalk . green . underline ( settings . username ) } ` ) ; return settings ; } )
@@ -26,12 +30,13 @@ function metrics({name, live}){
2630 . then ( response => response . json ( ) ) )
2731 . then ( data => Boolean ( data . message ) ? Promise . reject ( new Error ( data . message ) ) : data )
2832 . then ( data => {
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` ) ) ;
33+ 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` ) ) ;
3034
3135 Object . keys ( data . services )
3236 . map ( x => data . services [ x ] )
3337 . 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` , ' ' ) } ` ) ) ) ;
38+ . filter ( x => ! all ? x . active : true )
39+ . forEach ( x => console . log ( chalk . gray ( `${ x . active ? chalk . green ( 'online ' ) : chalk . red ( 'offline' ) } - ${ x . active ? chalk . green ( x . name ) : chalk . gray ( 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` , ' ' ) } ` ) ) ) ;
3540 } )
3641 . catch ( err => {
3742 process . stderr . write ( '\x1B[?25h' ) ; //show terminal cursor
@@ -56,7 +61,9 @@ function metrics({name, live}){
5661 } ) ;
5762}
5863
59- function metricsLive ( name ) {
64+ function metricsLive ( { name, all, nofollow} ) {
65+ if ( nofollow ) return metrics ( { name, all} ) ;
66+
6067 configuration
6168 . load ( )
6269 . then ( settings => { console . log ( `Live metrics for ${ chalk . green . underline ( settings . username ) } ` ) ; return settings ; } )
@@ -81,14 +88,17 @@ function metricsLive(name){
8188
8289 process . stdout . cursorTo ( 0 ) ;
8390 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` ) ) ;
91+ 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` ) ) ;
92+
93+ const services = Object . keys ( data . services ) . map ( x => data . services [ x ] )
94+ . filter ( x => name ? x . name === name : true )
95+ . filter ( x => ! all ? x . active : true ) ;
8596
86- const services = Object . keys ( data . services ) . map ( x => data . services [ x ] ) . filter ( x => name ? x . name === name : true ) ;
8797 services
8898 . forEach ( x => {
8999 process . stdout . cursorTo ( 0 ) ;
90100 process . stdout . clearLine ( ) ;
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` , ' ' ) } ` ) ) ;
101+ console . log ( chalk . gray ( `${ x . active ? chalk . green ( 'online ' ) : chalk . red ( 'offline' ) } - ${ x . active ? chalk . green ( x . name ) : chalk . gray ( 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` , ' ' ) } ` ) ) ;
92102 } ) ;
93103 process . stdout . moveCursor ( 0 , ( services . length + 2 ) * - 1 ) ;
94104 } ;
0 commit comments