Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cloud_Computing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Alexander Tim Hobelsberger
Cloud_Computing
Commits
0f937061
Commit
0f937061
authored
Nov 24, 2022
by
Alexander Tim Hobelsberger
Browse files
Options
Downloads
Patches
Plain Diff
Custom Metrics
parent
dcc83ab7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
index.js
+23
-1
23 additions, 1 deletion
index.js
prometheus/prometheus.yml
+1
-1
1 addition, 1 deletion
prometheus/prometheus.yml
routes/login.js
+4
-1
4 additions, 1 deletion
routes/login.js
with
28 additions
and
3 deletions
index.js
+
23
−
1
View file @
0f937061
...
@@ -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
)
{
//
client
ConnectionCount
er.inc(1);
client
ActiveUs
er
s
.
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
);
});
});
...
...
...
...
This diff is collapsed.
Click to expand it.
prometheus/prometheus.yml
+
1
−
1
View file @
0f937061
...
@@ -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
This diff is collapsed.
Click to expand it.
routes/login.js
+
4
−
1
View file @
0f937061
...
@@ -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
);
}
}
})
})
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment