Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Daemon monitoring + Dockerfile #913

Merged
merged 11 commits into from
Aug 31, 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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:6

RUN apt-get update
RUN apt-get install --yes python2.7 git-all pkg-config libncurses5-dev libssl-dev libnss3-dev libexpat-dev libc6

WORKDIR /usr/src/app

COPY package.json /usr/src/app/package.json

RUN npm install
RUN npm install wrtc

COPY . /usr/src/app

ENV IPFS_WRTC_LINUX_WINDOWS=1
ENV IPFS_BOOTSTRAP=1
ENV IPFS_MONITORING=1
ENV IPFS_PATH=/root/.jsipfs

EXPOSE 4002
EXPOSE 4003
EXPOSE 5002
EXPOSE 9090

CMD ./init-and-daemon.sh
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,20 @@ src # Main source code folder
└── ...
```

### Monitoring

The HTTP API exposed with js-ipfs can also be used for exposing metrics about
the running js-ipfs node and other nodejs metrics.

To enable it, you need to set the environment variable `IPFS_MONITORING` (any value)

Once environment variable is set and the js-ipfs daemon is running, you can get
the metrics (in prometheus format) by making a GET request to the following endpoint:

```
http://localhost:5002/debug/metrics/prometheus
```

### IPFS Core Architecture

![](/img/core.png)
Expand Down
6 changes: 6 additions & 0 deletions init-and-daemon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/sh -e
node src/cli/bin.js init

sed -i.bak 's/127.0.0.1/0.0.0.0/g' $IPFS_PATH/config

node src/cli/bin.js daemon
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
"update-notifier": "^2.2.0",
"yargs": "8.0.2"
},
"optionalDependencies": {
"prom-client": "^10.0.2",
"prometheus-gc-stats": "^0.5.0"
},
"contributors": [
"Andrew de Andrade <[email protected]>",
"CHEVALAY JOSSELIN <[email protected]>",
Expand All @@ -161,7 +165,6 @@
"Daniel J. O'Quinn <[email protected]>",
"Daniela Borges Matos de Carvalho <[email protected]>",
"David Dias <[email protected]>",
"Dzmitry Das <[email protected]>",
"Enrico Marino <[email protected]>",
"Felix Yan <[email protected]>",
"Francisco Baio Dias <[email protected]>",
Expand All @@ -171,12 +174,10 @@
"Greenkeeper <[email protected]>",
"Haad <[email protected]>",
"Harsh Vakharia <[email protected]>",
"Johannes Wikner <[email protected]>",
"Jon Schlinkert <[email protected]>",
"João Antunes <[email protected]>",
"Kevin Wang <[email protected]>",
"Lars Gierth <[email protected]>",
"Maciej Krüger <[email protected]>",
"Marius Darila <[email protected]>",
"Michelle Lee <[email protected]>",
"Mikeal Rogers <[email protected]>",
Expand All @@ -185,17 +186,14 @@
"Oskar Nyberg <[email protected]>",
"Pau Ramon Revilla <[email protected]>",
"Pedro Teixeira <[email protected]>",
"RasmusErik Voel Jensen <[email protected]>",
"Richard Littauer <[email protected]>",
"Rod Keys <[email protected]>",
"Sid Harder <[email protected]>",
"SidHarder <[email protected]>",
"Stephen Whitmore <[email protected]>",
"Stephen Whitmore <[email protected]>",
"Terence Pae <[email protected]>",
"Uroš Jurglič <[email protected]>",
"Xiao Liang <[email protected]>",
"bitspill <[email protected]>",
"haad <[email protected]>",
"jbenet <[email protected]>",
"kumavis <[email protected]>",
Expand All @@ -204,4 +202,4 @@
"tcme <[email protected]>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <[email protected]>"
]
}
}
11 changes: 11 additions & 0 deletions src/http-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ function HttpApi (repo, config, cliArgs) {
this.log = debug('jsipfs:http-api')
this.log.error = debug('jsipfs:http-api:error')

if (process.env.IPFS_MONITORING) {
// Setup debug metrics collection
const prometheusClient = require('prom-client')
const prometheusGcStats = require('prometheus-gc-stats')
const collectDefaultMetrics = prometheusClient.collectDefaultMetrics
collectDefaultMetrics({ timeout: 5000 })
prometheusGcStats(prometheusClient.register)()
}

this.start = (init, callback) => {
if (typeof init === 'function') {
callback = init
Expand All @@ -41,6 +50,8 @@ function HttpApi (repo, config, cliArgs) {
try { wrtc = require('wrtc') } catch (err) {}

if (wrtc || electronWebRTC) {
const using = wrtc ? 'wrtc' : 'electron-webrtc'
console.log(`Using ${using} for webrtc support`)
const wstar = new WStar({ wrtc: (wrtc || electronWebRTC) })
libp2p.modules.transport = [wstar]
libp2p.modules.discovery = [wstar.discovery]
Expand Down
31 changes: 31 additions & 0 deletions src/http-api/routes/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict'

const register = require('prom-client').register
const client = require('prom-client')

// Endpoint for handling debug metrics
module.exports = (server) => {
const api = server.select('API')
// Clear the register to make sure we're not registering multiple ones
register.clear()
const gauge = new client.Gauge({ name: 'number_of_peers', help: 'the_number_of_currently_connected_peers' })

api.route({
method: 'GET',
path: '/debug/metrics/prometheus',
handler: (request, reply) => {
if (!process.env.IPFS_MONITORING) {
return reply('Monitoring is disabled. Enable it by setting environment variable IPFS_MONITORING')
.code(501) // 501 = Not Implemented
}
server.app.ipfs.swarm.peers((err, res) => {
if (err) {
return reply(err).code(500)
}
const count = res.length
gauge.set(count)
reply(register.metrics()).header('Content-Type', register.contentType)
})
}
})
}
1 change: 1 addition & 0 deletions src/http-api/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ module.exports = (server) => {
require('./bitswap')(server)
require('./files')(server)
require('./pubsub')(server)
require('./debug')(server)
}