Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 76c3068

Browse files
hacdiasdaviddias
authored andcommittedDec 5, 2017
feat: add the stat commands (#639)
* Add Stat Commands * add submodules spec * Add Stats commands
1 parent 2f1ccdc commit 76c3068

File tree

7 files changed

+78
-0
lines changed

7 files changed

+78
-0
lines changed
 

‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods "[\"PUT\", \"P
250250
- [`ipfs.config.get([key, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/CONFIG.md#configget)
251251
- [`ipfs.config.set(key, value, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/CONFIG.md#configset)
252252
- [`ipfs.config.replace(config, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/CONFIG.md#configreplace)
253+
- stats:
254+
- `ipfs.stats.bitswap([callback])`
255+
- `ipfs.stats.bw([options, callback])`
256+
- `ipfs.stats.repo([options, callback])`
253257
- log:
254258
- `ipfs.log.ls([callback])`
255259
- `ipfs.log.tail([callback])`

‎src/stats/bitswap.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
const promisify = require('promisify-es6')
4+
5+
module.exports = (send) => {
6+
return promisify((opts, callback) => {
7+
if (typeof (opts) === 'function') {
8+
callback = opts
9+
opts = {}
10+
}
11+
12+
send({
13+
path: 'stats/bitswap',
14+
qs: opts
15+
}, callback)
16+
})
17+
}

‎src/stats/bw.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict'
2+
3+
const promisify = require('promisify-es6')
4+
5+
module.exports = (send) => {
6+
return promisify((opts, callback) => {
7+
if (typeof (opts) === 'function') {
8+
callback = opts
9+
opts = {}
10+
}
11+
12+
send({
13+
path: 'stats/bw',
14+
qs: opts
15+
}, callback)
16+
})
17+
}

‎src/stats/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict'
2+
3+
const moduleConfig = require('../utils/module-config')
4+
5+
module.exports = (arg) => {
6+
const send = moduleConfig(arg)
7+
8+
return {
9+
bitswap: require('./bitswap')(send),
10+
bw: require('./bw')(send),
11+
repo: require('./repo')(send)
12+
}
13+
}

‎src/stats/repo.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
'use strict'
3+
4+
const promisify = require('promisify-es6')
5+
6+
module.exports = (send) => {
7+
return promisify((opts, callback) => {
8+
if (typeof (opts) === 'function') {
9+
callback = opts
10+
opts = {}
11+
}
12+
13+
send({
14+
path: 'stats/repo',
15+
qs: opts
16+
}, callback)
17+
})
18+
}

‎src/utils/load-commands.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function requireCommands () {
3333
ping: require('../ping'),
3434
refs: require('../refs'),
3535
repo: require('../repo'),
36+
stats: require('../stats'),
3637
swarm: require('../swarm'),
3738
pubsub: require('../pubsub'),
3839
update: require('../update'),

‎test/sub-modules.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ describe('submodules', () => {
110110
expect(repo.stat).to.be.a('function')
111111
})
112112

113+
it('stats', () => {
114+
const stats = require('../src/stats')(config)
115+
116+
expect(stats.bitswap).to.be.a('function')
117+
expect(stats.bw).to.be.a('function')
118+
expect(stats.repo).to.be.a('function')
119+
})
120+
113121
it('swarm', () => {
114122
const swarm = require('../src/swarm')(config)
115123

0 commit comments

Comments
 (0)
This repository has been archived.