This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 4 files changed +117
-3
lines changed
4 files changed +117
-3
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const print = require ( '../../utils' ) . print
4
+
5
+ module . exports = {
6
+ command : 'bw' ,
7
+
8
+ describe : 'Get bandwidth information.' ,
9
+
10
+ builder : {
11
+ peer : {
12
+ type : 'string' ,
13
+ default : ''
14
+ } ,
15
+ proto : {
16
+ type : 'string' ,
17
+ default : ''
18
+ } ,
19
+ poll : {
20
+ type : 'boolean' ,
21
+ default : false
22
+ } ,
23
+ interval : {
24
+ type : 'string' ,
25
+ default : ''
26
+ }
27
+ } ,
28
+
29
+ handler ( argv ) {
30
+ argv . ipfs . stats . bw ( {
31
+ peer : argv . peer ,
32
+ proto : argv . proto ,
33
+ poll : argv . poll ,
34
+ interval : argv . interval
35
+ } , ( err , stats ) => {
36
+ if ( err ) {
37
+ throw err
38
+ }
39
+
40
+ print ( `bandwidth status
41
+ total in: ${ stats . totalIn } B
42
+ total out: ${ stats . totalOut } B
43
+ rate in: ${ stats . rateIn } B/s
44
+ rate out: ${ stats . rateOut } B/s` )
45
+ } )
46
+ }
47
+ }
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
+ const promisify = require ( 'promisify-es6' )
4
+
3
5
module . exports = function stats ( self ) {
4
6
return {
5
7
bitswap : require ( './bitswap' ) ( self ) . stat ,
6
- repo : require ( './repo' ) ( self ) . stat
8
+
9
+ repo : require ( './repo' ) ( self ) . stat ,
10
+
11
+ bw : promisify ( ( options , callback ) => {
12
+ if ( typeof options === 'function' ) {
13
+ callback = options
14
+ options = { }
15
+ }
16
+
17
+ let stats
18
+
19
+ if ( options . peer ) {
20
+ // TODO: stats for a specific peer
21
+ } else if ( options . proto ) {
22
+ // TODO: stats for a specific proto
23
+ } else {
24
+ const stat = self . _bitswap . stat ( )
25
+ const snapshot = stat . snapshot
26
+ const movingAverages = stat . movingAverages
27
+
28
+ stats = {
29
+ totalIn : snapshot . dataReceived ,
30
+ totalOut : snapshot . dataSent ,
31
+ rateIn : movingAverages . dataReceived [ 60000 ] . movingAverage ( ) / 60 , // Bytes per second
32
+ rateOut : movingAverages . dataSent [ 60000 ] . movingAverage ( ) / 60 // Bytes per second
33
+ }
34
+ }
35
+
36
+ callback ( null , stats )
37
+ } )
7
38
}
8
39
}
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
+ const Readable = require ( 'readable-stream' ) . Readable
4
+
3
5
exports = module . exports
4
6
5
7
exports . bitswap = require ( './bitswap' ) . stat
8
+
6
9
exports . repo = require ( './repo' ) . stat
10
+
11
+ exports . bw = ( request , reply ) => {
12
+ const ipfs = request . server . app . ipfs
13
+ const human = request . query . human === 'true'
14
+
15
+ const options = {
16
+ peer : request . query . peer ,
17
+ proto : request . query . proto ,
18
+ poll : request . query . poll === 'true' ,
19
+ interval : request . query . interval
20
+ }
21
+
22
+ ipfs . stats . bw ( options , ( err , stat ) => {
23
+ if ( err ) {
24
+ return reply ( {
25
+ Message : err . toString ( ) ,
26
+ Code : 0
27
+ } ) . code ( 500 )
28
+ }
29
+
30
+ reply ( {
31
+ TotalIn : stat . totalIn ,
32
+ TotalOut : stat . totalOut ,
33
+ RateIn : stat . rateIn ,
34
+ RateOut : stat . rateOut ,
35
+ } )
36
+ } )
37
+ }
38
+
Original file line number Diff line number Diff line change @@ -21,11 +21,15 @@ module.exports = (server) => {
21
21
}
22
22
} )
23
23
24
- /* api.route({
24
+ api . route ( {
25
25
method : '*' ,
26
26
path : '/api/v0/stats/bw' ,
27
27
config : {
28
+ payload : {
29
+ output : 'stream' ,
30
+ parse : false
31
+ } ,
28
32
handler : resources . stats . bw
29
33
}
30
- }) */
34
+ } )
31
35
}
You can’t perform that action at this time.
0 commit comments