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

Add Stat Commands #639

Merged
merged 3 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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