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

Commit

Permalink
feat: add the stat commands (#639)
Browse files Browse the repository at this point in the history
* Add Stat Commands

* add submodules spec

* Add Stats commands
  • Loading branch information
hacdias authored and daviddias committed Dec 5, 2017
1 parent 2f1ccdc commit 76c3068
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ $ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods "[\"PUT\", \"P
- [`ipfs.config.get([key, callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/CONFIG.md#configget)
- [`ipfs.config.set(key, value, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/CONFIG.md#configset)
- [`ipfs.config.replace(config, [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/CONFIG.md#configreplace)
- stats:
- `ipfs.stats.bitswap([callback])`
- `ipfs.stats.bw([options, callback])`
- `ipfs.stats.repo([options, callback])`
- log:
- `ipfs.log.ls([callback])`
- `ipfs.log.tail([callback])`
Expand Down
17 changes: 17 additions & 0 deletions src/stats/bitswap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const promisify = require('promisify-es6')

module.exports = (send) => {
return promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

send({
path: 'stats/bitswap',
qs: opts
}, callback)
})
}
17 changes: 17 additions & 0 deletions src/stats/bw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const promisify = require('promisify-es6')

module.exports = (send) => {
return promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

send({
path: 'stats/bw',
qs: opts
}, callback)
})
}
13 changes: 13 additions & 0 deletions src/stats/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

const moduleConfig = require('../utils/module-config')

module.exports = (arg) => {
const send = moduleConfig(arg)

return {
bitswap: require('./bitswap')(send),
bw: require('./bw')(send),
repo: require('./repo')(send)
}
}
18 changes: 18 additions & 0 deletions src/stats/repo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

'use strict'

const promisify = require('promisify-es6')

module.exports = (send) => {
return promisify((opts, callback) => {
if (typeof (opts) === 'function') {
callback = opts
opts = {}
}

send({
path: 'stats/repo',
qs: opts
}, callback)
})
}
1 change: 1 addition & 0 deletions src/utils/load-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function requireCommands () {
ping: require('../ping'),
refs: require('../refs'),
repo: require('../repo'),
stats: require('../stats'),
swarm: require('../swarm'),
pubsub: require('../pubsub'),
update: require('../update'),
Expand Down
8 changes: 8 additions & 0 deletions test/sub-modules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ describe('submodules', () => {
expect(repo.stat).to.be.a('function')
})

it('stats', () => {
const stats = require('../src/stats')(config)

expect(stats.bitswap).to.be.a('function')
expect(stats.bw).to.be.a('function')
expect(stats.repo).to.be.a('function')
})

it('swarm', () => {
const swarm = require('../src/swarm')(config)

Expand Down

0 comments on commit 76c3068

Please sign in to comment.