Skip to content
Snippets Groups Projects
Commit 0f937061 authored by Alexander Tim Hobelsberger's avatar Alexander Tim Hobelsberger
Browse files

Custom Metrics

parent dcc83ab7
Branches
No related tags found
No related merge requests found
...@@ -77,6 +77,23 @@ const messageGroup = new client.Counter({ ...@@ -77,6 +77,23 @@ const messageGroup = new client.Counter({
help: 'Counts the amount of times group message is used' help: 'Counts the amount of times group message is used'
}); });
const clientActiveUsers = new client.Gauge({
name: 'node_active_users',
help: 'Active Users'
});
const successfullLogIns = new client.Counter({
name: 'node_successful_logins',
help: 'Successfull LogIns total'
});
global.SUCCESSFULLLOG = successfullLogIns;
const notSuccessfullLogIns = new client.Counter({
name: 'node_not_successful_logins',
help: 'Not successfull LogIns total'
});
global.NOTSUCCESSFULLLOG = notSuccessfullLogIns;
const histogram = new client.Histogram({ const histogram = new client.Histogram({
name: 'node_request_duration_seconds', name: 'node_request_duration_seconds',
help: 'Own Metric: Histogram for the duration in seconds.', help: 'Own Metric: Histogram for the duration in seconds.',
...@@ -89,6 +106,10 @@ register.registerMetric(messageAll); ...@@ -89,6 +106,10 @@ register.registerMetric(messageAll);
register.registerMetric(messagePrivate); register.registerMetric(messagePrivate);
register.registerMetric(messageGroup); register.registerMetric(messageGroup);
register.registerMetric(histogram); register.registerMetric(histogram);
register.registerMetric(successfullLogIns);
register.registerMetric(notSuccessfullLogIns);
register.registerMetric(clientActiveUsers);
app.use(bodyParser.json()); app.use(bodyParser.json());
//Routes //Routes
...@@ -132,12 +153,13 @@ app.get('/login', (req, res) => { ...@@ -132,12 +153,13 @@ app.get('/login', (req, res) => {
io.on('connection', (socket) => { io.on('connection', (socket) => {
socket.on('userLogin', async function(response) { socket.on('userLogin', async function(response) {
//clientConnectionCounter.inc(1); clientActiveUsers.inc(1);
console.log("Connection"); console.log("Connection");
await addUserToActiveUsers(response, socket); await addUserToActiveUsers(response, socket);
}); });
socket.on('disconnect', async function(response) { socket.on('disconnect', async function(response) {
clientActiveUsers.dec(1);
await deleteUserFromActiveUsers(response, socket); await deleteUserFromActiveUsers(response, socket);
}); });
... ...
......
...@@ -14,5 +14,5 @@ scrape_configs: ...@@ -14,5 +14,5 @@ scrape_configs:
scrape_interval: 5s scrape_interval: 5s
# scheme: https # scheme: https
static_configs: static_configs:
- targets: ['192.168.2.34:5000'] - targets: ['192.168.0.230:5000']
\ No newline at end of file
...@@ -32,21 +32,24 @@ router.post('/', async(req, res) => { ...@@ -32,21 +32,24 @@ router.post('/', async(req, res) => {
if(user){ if(user){
bcrypt.compare(password, user.password, function (err, result) { bcrypt.compare(password, user.password, function (err, result) {
if(err){ if(err){
NOTSUCCESSFULLLOG.inc(1);
res.json(err); res.json(err);
} }
if(result){ if(result){
SUCCESSFULLLOG.inc(1);
const user = { name: name }; const user = { name: name };
const accessToken = jwt.sign(user, process.env.ACCESS_TOKEN_SECRET) const accessToken = jwt.sign(user, process.env.ACCESS_TOKEN_SECRET)
res.json({ res.json({
statusCode: '200', statusCode: '200',
accessToken: accessToken, accessToken: accessToken,
}) })
}else{ }else{
NOTSUCCESSFULLLOG.inc(1);
res.status(401); res.status(401);
} }
}) })
}else{ }else{
NOTSUCCESSFULLLOG.inc(1);
res.status(401); res.status(401);
} }
}) })
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment