diff --git a/README.md b/README.md index 5a4b91d65..f7b51bd38 100644 --- a/README.md +++ b/README.md @@ -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])` diff --git a/src/stats/bitswap.js b/src/stats/bitswap.js new file mode 100644 index 000000000..619bd0809 --- /dev/null +++ b/src/stats/bitswap.js @@ -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) + }) +} diff --git a/src/stats/bw.js b/src/stats/bw.js new file mode 100644 index 000000000..d9a5155a6 --- /dev/null +++ b/src/stats/bw.js @@ -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) + }) +} diff --git a/src/stats/index.js b/src/stats/index.js new file mode 100644 index 000000000..60b752587 --- /dev/null +++ b/src/stats/index.js @@ -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) + } +} diff --git a/src/stats/repo.js b/src/stats/repo.js new file mode 100644 index 000000000..71a180363 --- /dev/null +++ b/src/stats/repo.js @@ -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) + }) +} diff --git a/src/utils/load-commands.js b/src/utils/load-commands.js index ff46271c9..f80b1427c 100644 --- a/src/utils/load-commands.js +++ b/src/utils/load-commands.js @@ -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'), diff --git a/test/sub-modules.spec.js b/test/sub-modules.spec.js index a74ac1234..3512731cc 100644 --- a/test/sub-modules.spec.js +++ b/test/sub-modules.spec.js @@ -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)