diff --git a/gatewayservice/monitoring/prometheus/prometheus.yml b/gatewayservice/monitoring/prometheus/prometheus.yml index a1bb7fb..e20232c 100644 --- a/gatewayservice/monitoring/prometheus/prometheus.yml +++ b/gatewayservice/monitoring/prometheus/prometheus.yml @@ -3,4 +3,4 @@ global: scrape_configs: - job_name: "example-nodejs-app" static_configs: - - targets: ["gatewayservice-wiq5a:8000","questionservice-wiq5a:8003","userservice-wiq5a:8001","authservice-wiq5a:8002"] \ No newline at end of file + - targets: ["gatewayservice-wiq5a:8000","userservice-wiq5a:8001","authservice-wiq5a:8002","questionservice-wiq5a:8003"] \ No newline at end of file diff --git a/userservice/authservice/auth-service.js b/userservice/authservice/auth-service.js index 2904720..88e102e 100644 --- a/userservice/authservice/auth-service.js +++ b/userservice/authservice/auth-service.js @@ -4,6 +4,8 @@ const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const jwt = require('jsonwebtoken'); const User = require('./auth-model') +const promBundle = require('express-prom-bundle'); + const app = express(); const port = 8002; @@ -15,6 +17,10 @@ app.use(express.json()); const mongoUri = process.env.MONGODB_URI; mongoose.connect(mongoUri); +//Prometheus configuration +const metricsMiddleware = promBundle({includeMethod: true}); +app.use(metricsMiddleware); + // Function to validate required fields in the request body function validateRequiredFields(req, requiredFields) { for (const field of requiredFields) { diff --git a/userservice/userservice/user-service.js b/userservice/userservice/user-service.js index a991412..5fe4f2e 100644 --- a/userservice/userservice/user-service.js +++ b/userservice/userservice/user-service.js @@ -5,6 +5,7 @@ const mongoose = require('mongoose'); const bcrypt = require('bcrypt'); const bodyParser = require('body-parser'); const User = require('./user-model'); +const promBundle = require('express-prom-bundle'); const app = express(); const port = 8001; @@ -12,6 +13,10 @@ const port = 8001; // Middleware to parse JSON in request body app.use(bodyParser.json()); +//Prometheus configuration +const metricsMiddleware = promBundle({includeMethod: true}); +app.use(metricsMiddleware); + // Connect to MongoDB //const mongoUri = process.env.MONGODB_URI || 'mongodb://localhost:27017/userdb'; const mongoUri = process.env.MONGODB_URI;