Skip to content

Commit

Permalink
Added api gateway and prometheus services
Browse files Browse the repository at this point in the history
  • Loading branch information
mKeRix committed Jul 9, 2018
1 parent 0b84522 commit a1a8922
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"schema": {
"services": ["str"],
"room": "str",
"api": {
"port": "port?"
},
"mqtt": {
"url": "str",
"username": "str",
Expand Down
3 changes: 3 additions & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"room": "ROOM",
"api": {
"port": "API_PORT"
},
"mqtt": {
"url": "MQTT_URL",
"username": "MQTT_USERNAME",
Expand Down
3 changes: 3 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"services": [],
"room": "default-room",
"api": {
"port": "3000"
},
"mqtt": {
"url": "mqtt://localhost",
"username": "",
Expand Down
6 changes: 6 additions & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@
],
"gpio": [
"onoff@3.1.0"
],
"api": [
"moleculer-web@0.8.0"
],
"prometheus": [
"prom-client@11.1.1"
]
}
27 changes: 27 additions & 0 deletions services/api.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const config = require('config');

const ApiGatewayService = require('moleculer-web');

module.exports = {
name: 'api',

mixins: [ApiGatewayService],

settings: {
port: config.get('api.port'),

routes: [
{
mappingPolicy: 'restrict',
aliases: {
'GET metrics': 'prometheus.metrics'
},
bodyParsers: {
json: false
}
}
]
}
};
16 changes: 16 additions & 0 deletions services/prometheus.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const promClient = require('prom-client');

module.exports = {
name: 'prometheus',

actions: {
metrics(ctx) {
ctx.meta.$responseType = 'text/plain';
return promClient.register.metrics();
}
},

created() {
promClient.collectDefaultMetrics();
}
};

0 comments on commit a1a8922

Please sign in to comment.