From e28154aa086c7fa6cc0f8cd3db6decb247cd14fa Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 4 Dec 2017 19:38:53 +0000 Subject: [PATCH 1/3] Add Stat Commands --- src/stats/bitswap.js | 17 +++++++++++++++++ src/stats/bw.js | 17 +++++++++++++++++ src/stats/index.js | 13 +++++++++++++ src/stats/repo.js | 18 ++++++++++++++++++ src/utils/load-commands.js | 1 + 5 files changed, 66 insertions(+) create mode 100644 src/stats/bitswap.js create mode 100644 src/stats/bw.js create mode 100644 src/stats/index.js create mode 100644 src/stats/repo.js 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'), From e70b6a5d9cf40f912163a0a7e7f743b6dc4d3c1f Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Mon, 4 Dec 2017 23:28:52 +0000 Subject: [PATCH 2/3] add submodules spec --- test/sub-modules.spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) 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) From 72df6bf7d9ac395ad15c8472fa168ccfca56af30 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 5 Dec 2017 07:58:58 +0000 Subject: [PATCH 3/3] Add Stats commands --- README.md | 4 ++++ 1 file changed, 4 insertions(+) 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])`