🔀」 merge(Prometheus/Graphana): added for monitoring module (closes #23)

This commit is contained in:
Adam
2025-07-23 14:07:08 +02:00
committed by GitHub
36 changed files with 19530 additions and 65 deletions

View File

View File

@ -23,4 +23,6 @@ EXPOSE 3000
RUN mkdir /db
STOPSIGNAL SIGINT
CMD [ "node", "/app/src/start.js" ]

View File

@ -0,0 +1,33 @@
services:
user-api:
container_name: transcendence-api-user
build:
dockerfile: docker/api-base/Dockerfile
context: ../../
volumes:
- db-user:/db
networks:
- front
- back
- prom-exporter
environment:
- TZ=Europe/Paris
- API_TARGET=user
- JWT_SECRET=${JWT_SECRET}
restart: unless-stopped
auth-api:
container_name: transcendence-api-auth
build:
dockerfile: docker/api-base/Dockerfile
context: ../../
volumes:
- db-auth:/db
networks:
- front
- back
- prom-exporter
environment:
- TZ=Europe/Paris
- API_TARGET=auth
- JWT_SECRET=${JWT_SECRET}
restart: unless-stopped

View File

@ -1,64 +1,8 @@
name: ft_transcendence
services:
front:
container_name: transcendence-front
build:
dockerfile: docker/front/Dockerfile
context: ..
ports:
- ${OUT_PORT}:443
environment:
SERVER_NAME: localhost
depends_on:
user-api:
condition: service_started
auth-api:
condition: service_started
networks:
- front
environment:
- TZ=Europe/Paris
restart: unless-stopped
user-api:
container_name: transcendence-api-user
build:
dockerfile: docker/api-base/Dockerfile
context: ..
volumes:
- db-user:/db
networks:
- front
- back
environment:
- TZ=Europe/Paris
- API_TARGET=user
- JWT_SECRET=${JWT_SECRET}
restart: unless-stopped
auth-api:
container_name: transcendence-api-auth
build:
dockerfile: docker/api-base/Dockerfile
context: ..
volumes:
- db-auth:/db
networks:
- front
- back
environment:
- TZ=Europe/Paris
- API_TARGET=auth
- JWT_SECRET=${JWT_SECRET}
restart: unless-stopped
networks:
front:
name: transcendence-front
back:
name: transcendence-back
volumes:
db-auth:
name: transcendence-api-auth-db
db-user:
name: transcendence-api-user-db
include:
- ./volumes.yml
- ./networks.yml
- ./monitoring/compose.yml
- ./api-base/compose.yml
- ./front/compose.yml

19
docker/front/compose.yml Normal file
View File

@ -0,0 +1,19 @@
services:
front:
container_name: transcendence-front
build:
dockerfile: docker/front/Dockerfile
context: ../../
ports:
- ${OUT_PORT}:443
environment:
- SERVER_NAME=localhost
- TZ=Europe/Paris
depends_on:
user-api:
condition: service_started
auth-api:
condition: service_started
networks:
- front
restart: unless-stopped

View File

@ -24,6 +24,9 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /api/v1/user/metrics {
return 403;
}
location /api/v1/auth/ {
proxy_pass http://transcendence-api-auth:3000/;
@ -32,6 +35,9 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /api/v1/auth/metrics {
return 403;
}
}
server {
@ -39,3 +45,10 @@ server {
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 8080;
location /nginx_status {
stub_status;
}
}

View File

@ -0,0 +1,15 @@
FROM prom/alertmanager:latest
ARG SMTP_SMARTHOST
ARG SMTP_FROM
ARG SMTP_AUTH_USERNAME
ARG SMTP_AUTH_PASSWORD
ARG EMAIL_TO
COPY alertmanager.yml /etc/alertmanager/alertmanager.yml
RUN sed -i "s|smtp_smarthost: *|smtp_smarthost: '${SMTP_SMARTHOST}'|" /etc/alertmanager/alertmanager.yml && \
sed -i "s|smtp_from: *|smtp_from: '${SMTP_FROM}'|" /etc/alertmanager/alertmanager.yml && \
sed -i "s|smtp_auth_username: *|smtp_auth_username: '${SMTP_AUTH_USERNAME}'|" /etc/alertmanager/alertmanager.yml && \
sed -i "s|smtp_auth_password: *|smtp_auth_password: '${SMTP_AUTH_PASSWORD}'|" /etc/alertmanager/alertmanager.yml && \
sed -i "s|to: *|to: '${EMAIL_TO}'|" /etc/alertmanager/alertmanager.yml

View File

@ -0,0 +1,18 @@
global:
smtp_smarthost:
smtp_from:
smtp_auth_username:
smtp_auth_password:
route:
receiver: 'email-alerts'
group_by: ['alertname']
group_wait: 30s
group_interval: 5m
repeat_interval: 1h
receivers:
- name: 'email-alerts'
email_configs:
- to:
send_resolved: true

View File

@ -0,0 +1,22 @@
services:
alert-manager:
container_name: transcendence-alert
build:
dockerfile: Dockerfile
context: .
args:
SMTP_SMARTHOST: ${SMTP_SMARTHOST}
SMTP_FROM: ${SMTP_FROM}
SMTP_AUTH_USERNAME: ${SMTP_AUTH_USERNAME}
SMTP_AUTH_PASSWORD: ${SMTP_AUTH_PASSWORD}
EMAIL_TO: ${EMAIL_TO}
# ports:
# - 9093:9093
environment:
- TZ=Europe/Paris
depends_on:
prometheus:
condition: service_started
networks:
- prom
restart: unless-stopped

View File

@ -0,0 +1,5 @@
include:
- ./prometheus/compose.yml
- ./exporters/compose.yml
- ./alert-manager/compose.yml
- ./graphana/compose.yml

View File

@ -0,0 +1,3 @@
include:
- ./nginx/compose.yml
- ./node/compose.yml

View File

@ -0,0 +1,12 @@
services:
nginx-exporter:
container_name: transcendence-nginx-exporter
image: nginx/nginx-prometheus-exporter:latest
command:
- '-nginx.scrape-uri=http://transcendence-front:8080/status/format/json'
depends_on:
front:
condition: service_started
networks:
- front
- prom-exporter

View File

@ -0,0 +1,16 @@
services:
node-exporter:
container_name: transcendence-node-exporter
image: prom/node-exporter:latest
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- '--path.procfs=/host/proc'
- '--path.rootfs=/rootfs'
- '--path.sysfs=/host/sys'
- '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
networks:
- prom-exporter
restart: unless-stopped

View File

@ -0,0 +1,9 @@
FROM grafana/grafana-oss
ARG PROM_ADMIN_PASSWD
COPY sources /etc/grafana/provisioning/datasources
COPY dashboards /dashboards
COPY dash-providers /etc/grafana/provisioning/dashboards
RUN sed -i "s|basicAuthPassword:|basicAuthPassword: $PROM_ADMIN_PASSWD|" /etc/grafana/provisioning/datasources/prometheus.yml

View File

@ -0,0 +1,15 @@
services:
graphana:
container_name: transcendence-graphana
build:
dockerfile: Dockerfile
context: .
args:
PROM_ADMIN_PASSWD: ${PROM_PASS}
ports:
- ${GRAPH_PORT}:3000
environment:
- TZ=Europe/Paris
networks:
- prom
restart: unless-stopped

View File

@ -0,0 +1,15 @@
apiVersion: 1
providers:
- name: 'knl_meowscendence dashhhh'
# <bool> disable dashboard deletion
disableDeletion: false
# <int> how often Grafana will scan for changed dashboards
updateIntervalSeconds: 30
# <bool> allow updating provisioned dashboards from the UI
allowUiUpdates: false
options:
# <string, required> path to dashboard files on disk. Required when using the 'file' type
path: /dashboards
# <bool> use folder names from filesystem to create folders in Grafana
foldersFromFilesStructure: true

View File

@ -0,0 +1,933 @@
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "6.0.1"
},
{
"type": "panel",
"id": "graph",
"name": "Graph",
"version": "5.0.0"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "5.0.0"
},
{
"type": "panel",
"id": "singlestat",
"name": "Singlestat",
"version": "5.0.0"
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"description": "node.js prometheus client basic metrics",
"editable": true,
"gnetId": 11159,
"graphTooltip": 0,
"id": null,
"iteration": 1573392431370,
"links": [],
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 7,
"w": 10,
"x": 0,
"y": 0
},
"id": 6,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"paceLength": 10,
"percentage": false,
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "irate(process_cpu_user_seconds_total{instance=~\"$instance\"}[2m]) * 100",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "User CPU - {{instance}}",
"refId": "A"
},
{
"expr": "irate(process_cpu_system_seconds_total{instance=~\"$instance\"}[2m]) * 100",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Sys CPU - {{instance}}",
"refId": "B"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Process CPU Usage",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "percent",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 7,
"w": 9,
"x": 10,
"y": 0
},
"id": 8,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"paceLength": 10,
"percentage": false,
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "nodejs_eventloop_lag_seconds{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "{{instance}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Event Loop Lag",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "s",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"cacheTimeout": null,
"colorBackground": false,
"colorValue": false,
"colors": [
"#299c46",
"rgba(237, 129, 40, 0.89)",
"#d44a3a"
],
"datasource": "${DS_PROMETHEUS}",
"format": "none",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"gridPos": {
"h": 3,
"w": 5,
"x": 19,
"y": 0
},
"id": 2,
"interval": "",
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "rgb(31, 120, 193)",
"show": false
},
"tableColumn": "__name__",
"targets": [
{
"expr": "sum(nodejs_version_info{instance=~\"$instance\"}) by (version)",
"format": "time_series",
"instant": false,
"interval": "",
"intervalFactor": 1,
"legendFormat": "{{version}}",
"refId": "A"
}
],
"thresholds": "",
"timeFrom": null,
"timeShift": null,
"title": "Node.js Version",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "name"
},
{
"cacheTimeout": null,
"colorBackground": false,
"colorValue": false,
"colors": [
"#299c46",
"rgba(237, 129, 40, 0.89)",
"#d44a3a"
],
"datasource": "${DS_PROMETHEUS}",
"format": "none",
"gauge": {
"maxValue": 100,
"minValue": 0,
"show": false,
"thresholdLabels": false,
"thresholdMarkers": true
},
"gridPos": {
"h": 4,
"w": 5,
"x": 19,
"y": 3
},
"id": 4,
"interval": null,
"links": [],
"mappingType": 1,
"mappingTypes": [
{
"name": "value to text",
"value": 1
},
{
"name": "range to text",
"value": 2
}
],
"maxDataPoints": 100,
"nullPointMode": "connected",
"nullText": null,
"postfix": "",
"postfixFontSize": "50%",
"prefix": "",
"prefixFontSize": "50%",
"rangeMaps": [
{
"from": "null",
"text": "N/A",
"to": "null"
}
],
"sparkline": {
"fillColor": "rgba(31, 118, 189, 0.18)",
"full": false,
"lineColor": "#F2495C",
"show": true
},
"tableColumn": "",
"targets": [
{
"expr": "sum(changes(process_start_time_seconds{instance=~\"$instance\"}[1m]))",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "{{instance}}",
"refId": "A"
}
],
"thresholds": "",
"timeFrom": null,
"timeShift": null,
"title": "Process Restart Times",
"type": "singlestat",
"valueFontSize": "80%",
"valueMaps": [
{
"op": "=",
"text": "N/A",
"value": "null"
}
],
"valueName": "current"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 7,
"w": 16,
"x": 0,
"y": 7
},
"id": 7,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"rightSide": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"paceLength": 10,
"percentage": false,
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "process_resident_memory_bytes{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Process Memory - {{instance}}",
"refId": "A"
},
{
"expr": "nodejs_heap_size_total_bytes{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Heap Total - {{instance}}",
"refId": "B"
},
{
"expr": "nodejs_heap_size_used_bytes{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Heap Used - {{instance}}",
"refId": "C"
},
{
"expr": "nodejs_external_memory_bytes{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "External Memory - {{instance}}",
"refId": "D"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Process Memory Usage",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 7,
"w": 8,
"x": 16,
"y": 7
},
"id": 9,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"paceLength": 10,
"percentage": false,
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "nodejs_active_handles_total{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Active Handler - {{instance}}",
"refId": "A"
},
{
"expr": "nodejs_active_requests_total{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Active Request - {{instance}}",
"refId": "B"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Active Handlers/Requests Total",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 8,
"w": 8,
"x": 0,
"y": 14
},
"id": 10,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"rightSide": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"paceLength": 10,
"percentage": false,
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "nodejs_heap_space_size_total_bytes{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Heap Total - {{instance}} - {{space}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Heap Total Detail",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 8,
"w": 8,
"x": 8,
"y": 14
},
"id": 11,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"rightSide": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"paceLength": 10,
"percentage": false,
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "nodejs_heap_space_size_used_bytes{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Heap Used - {{instance}} - {{space}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Heap Used Detail",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_PROMETHEUS}",
"fill": 1,
"gridPos": {
"h": 8,
"w": 8,
"x": 16,
"y": 14
},
"id": 12,
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"rightSide": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"paceLength": 10,
"percentage": false,
"pointradius": 2,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "nodejs_heap_space_size_available_bytes{instance=~\"$instance\"}",
"format": "time_series",
"intervalFactor": 1,
"legendFormat": "Heap Used - {{instance}} - {{space}}",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Heap Available Detail",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "bytes",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"schemaVersion": 18,
"style": "dark",
"tags": [
"nodejs"
],
"templating": {
"list": [
{
"allValue": null,
"current": {},
"datasource": "${DS_PROMETHEUS}",
"definition": "label_values(nodejs_version_info, instance)",
"hide": 0,
"includeAll": true,
"label": "instance",
"multi": true,
"name": "instance",
"options": [],
"query": "label_values(nodejs_version_info, instance)",
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 1,
"tagValuesQuery": "",
"tags": [],
"tagsQuery": "",
"type": "query",
"useTags": false
}
]
},
"time": {
"from": "now-1h",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "",
"title": "NodeJS Application Dashboard",
"uid": "PTSqcpJWk",
"version": 4
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://transcendence-prom:9090/prometheus
basicAuth: true
basicAuthUser: admin
secureJsonData:
basicAuthPassword:
isDefault: true
editable: true

View File

@ -0,0 +1,11 @@
FROM prom/prometheus
ARG PROM_ADMIN_PASSWD
ARG PROM_ADMIN_PASSWD_HASH
COPY ./config/prometheus.yml /etc/prometheus/prometheus.yml
COPY ./config/web-config.yml /etc/prometheus/web-config.yml
COPY ./config/rules.yml /etc/prometheus/rules.yml
RUN sed -i "s/PROM_ADMIN_PASSWD/$(printf '%s\n' "$PROM_ADMIN_PASSWD" | sed -e 's/[\/&]/\\&/g')/g" /etc/prometheus/prometheus.yml
RUN sed -i "s/PROM_ADMIN_PASSWD_HASH/$(printf '%s\n' "$PROM_ADMIN_PASSWD_HASH" | sed -e 's/[\/&]/\\&/g')/g" /etc/prometheus/web-config.yml

View File

@ -0,0 +1,30 @@
services:
prometheus:
container_name: transcendence-prom
build:
dockerfile: Dockerfile
context: .
args:
PROM_ADMIN_PASSWD: ${PROM_PASS}
PROM_ADMIN_PASSWD_HASH: ${PROM_HASH}
environment:
- TZ=Europe/Paris
ports:
- ${PROM_PORT}:9090
volumes:
- prometheus_data:/prometheus
depends_on:
front:
condition: service_started
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.config.file=/etc/prometheus/web-config.yml'
- '--web.external-url=/prometheus/'
- '--web.console.libraries=/etc/prometheus/console_libraries'
- '--web.console.templates=/etc/prometheus/consoles'
- '--web.enable-lifecycle'
networks:
- prom
- prom-exporter
restart: unless-stopped

View File

@ -0,0 +1,30 @@
global:
scrape_interval: 5s
alerting:
alertmanagers:
- static_configs:
- targets:
- transcendence-alert:9093
scrape_configs:
- job_name: 'prometheus'
metrics_path: '/prometheus/metrics'
basic_auth:
username: admin
password: PROM_ADMIN_PASSWD
static_configs:
- targets: ['localhost:9090']
- job_name: 'nginx'
static_configs:
- targets: ['nginx-exporter:9113']
- job_name: 'node-exporter'
static_configs:
- targets: ['node-exporter:9100']
- job_name: 'nodejs'
static_configs:
- targets: ['transcendence-api-auth:3000']
- targets: ['transcendence-api-user:3000']

View File

@ -0,0 +1,12 @@
groups:
- name: AllInstances
rules:
- alert: InstanceDown
# Condition for alerting
expr: up == 0
for: 20s
annotations:
title: 'Instance {{ $labels.instance }} down'
description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 20 seconds.'
labels:
severity: 'critical'

View File

@ -0,0 +1,2 @@
basic_auth_users:
admin: PROM_ADMIN_PASSWD_HASH

9
docker/networks.yml Normal file
View File

@ -0,0 +1,9 @@
networks:
front:
name: transcendence-front
back:
name: transcendence-back
prom:
name: transcendence-prom
prom-exporter:
name: transcendence-prom-exporter

7
docker/volumes.yml Normal file
View File

@ -0,0 +1,7 @@
volumes:
prometheus_data:
name: transcendence-prom-data
db-auth:
name: transcendence-api-auth-db
db-user:
name: transcendence-api-user-db

View File

@ -9,7 +9,8 @@
"better-sqlite3": "^12.2.0",
"fastify": "^5.4.0",
"fastify-cli": "^7.4.0",
"google-auth-library": "^10.1.0"
"google-auth-library": "^10.1.0",
"prom-client": "^15.1.3"
},
"type": "module",
"devDependencies": {

30
pnpm-lock.yaml generated
View File

@ -38,6 +38,9 @@ importers:
google-auth-library:
specifier: ^10.1.0
version: 10.1.0
prom-client:
specifier: ^15.1.3
version: 15.1.3
devDependencies:
'@tailwindcss/vite':
specifier: ^4.1.11
@ -268,6 +271,10 @@ packages:
resolution: {integrity: sha512-9I2Zn6+NJLfaGoz9jN3lpwDgAYvfGeNYdbAIjJOqzs4Tpc+VU3Jqq4IofSUBKajiDS8k9fZIg18/z13mpk1bsA==}
engines: {node: '>=8'}
'@opentelemetry/api@1.9.0':
resolution: {integrity: sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==}
engines: {node: '>=8.0.0'}
'@rollup/rollup-android-arm-eabi@4.44.2':
resolution: {integrity: sha512-g0dF8P1e2QYPOj1gu7s/3LVP6kze9A7m6x0BZ9iTdXK8N5c2V7cpBKHV3/9A4Zd8xxavdhK0t4PnqjkqVmUc9Q==}
cpu: [arm]
@ -520,6 +527,9 @@ packages:
bindings@1.5.0:
resolution: {integrity: sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==}
bintrees@1.0.2:
resolution: {integrity: sha512-VOMgTMwjAaUG580SXn3LacVgjurrbMme7ZZNYGSSV7mmtY6QQRh0Eg3pwIcntQ77DErK1L0NxkbetjcoXzVwKw==}
bl@4.1.0:
resolution: {integrity: sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==}
@ -1093,6 +1103,10 @@ packages:
process-warning@5.0.0:
resolution: {integrity: sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA==}
prom-client@15.1.3:
resolution: {integrity: sha512-6ZiOBfCywsD4k1BN9IX0uZhF+tJkV8q8llP64G5Hajs4JOeVLPCwpPVcpXy3BwYiUGgyJzsJJQeOIv7+hDSq8g==}
engines: {node: ^16 || ^18 || >=20}
proxy-from-env@1.1.0:
resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==}
@ -1225,6 +1239,9 @@ packages:
resolution: {integrity: sha512-5S7Va8hKfV7W5U6g3aYxXmlPoZVAwUMy9AOKyF2fVuZa2UD3qZjg578OrLRt8PcNN1PleVaL/5/yYATNL0ICUw==}
engines: {node: '>=18'}
tdigest@0.1.2:
resolution: {integrity: sha512-+G0LLgjjo9BZX2MfdvPfH+MKLCrxlXSYec5DaPYP1fe6Iyhf0/fSmJ0bFiZ1F8BT6cGXl2LpltQptzjXKWEkKA==}
thread-stream@3.1.0:
resolution: {integrity: sha512-OqyPZ9u96VohAyMfJykzmivOrY2wfMSf3C5TtFJVgN+Hm6aj+voFhlK+kZEIv2FBh1X6Xp3DlnCOfEQ3B2J86A==}
@ -1460,6 +1477,8 @@ snapshots:
'@lukeed/ms@2.0.2': {}
'@opentelemetry/api@1.9.0': {}
'@rollup/rollup-android-arm-eabi@4.44.2':
optional: true
@ -1656,6 +1675,8 @@ snapshots:
dependencies:
file-uri-to-path: 1.0.0
bintrees@1.0.2: {}
bl@4.1.0:
dependencies:
buffer: 5.7.1
@ -2264,6 +2285,11 @@ snapshots:
process-warning@5.0.0: {}
prom-client@15.1.3:
dependencies:
'@opentelemetry/api': 1.9.0
tdigest: 0.1.2
proxy-from-env@1.1.0: {}
pump@3.0.3:
@ -2412,6 +2438,10 @@ snapshots:
mkdirp: 3.0.1
yallist: 5.0.0
tdigest@0.1.2:
dependencies:
bintrees: 1.0.2
thread-stream@3.1.0:
dependencies:
real-require: 0.2.0

View File

View File

@ -1,5 +1,6 @@
import fastifyJWT from '@fastify/jwt';
import fastifyCookie from '@fastify/cookie';
import client from 'prom-client';
import { register } from './register.js';
import { login } from './login.js';
@ -13,6 +14,7 @@ import { totpVerify } from './totpVerify.js';
const saltRounds = 10;
export const appName = process.env.APP_NAME || 'knl_meowscendence';
const collectDefaultMetrics = client.collectDefaultMetrics
authDB.prepareDB();
@ -21,6 +23,30 @@ authDB.prepareDB();
* @param {import('fastify').FastifyPluginOptions} options
*/
export default async function(fastify, options) {
collectDefaultMetrics({ labels: { service: "auth-api" } })
client.register.setDefaultLabels({ service: "auth-api" })
const httpRequestCounter = new client.Counter({
name: 'http_requests_total',
help: 'Total number of HTTP requests',
labelNames: ['method', 'route', 'status_code'],
})
fastify.addHook('onResponse', (req, res, done) => {
httpRequestCounter.inc({
method: req.method,
route: req.routerPath || req.url,
status_code: res.statusCode,
})
done()
})
fastify.get('/metrics', async (req, reply) => {
reply
.header('Content-Type', client.register.contentType)
.send(await client.register.metrics())
})
fastify.register(fastifyJWT, {
secret: process.env.JWT_SECRET || '123456789101112131415161718192021',
cookie: {

View File

@ -1,8 +1,10 @@
import fastifyJWT from '@fastify/jwt';
import fastifyCookie from '@fastify/cookie';
import Database from 'better-sqlite3';
import client from 'prom-client';
var env = process.env.NODE_ENV || 'development';
const collectDefaultMetrics = client.collectDefaultMetrics
let database;
@ -15,13 +17,13 @@ if (!env || env === 'development') {
function prepareDB() {
database.exec(`
CREATE TABLE userData (
CREATE TABLE IF NOT EXISTS userData (
username TEXT PRIMARY KEY,
displayName TEXT
) STRICT
`);
database.exec(`
CREATE TABLE friends (
CREATE TABLE IF NOT EXISTS friends (
username TEXT,
friendName TEXT,
UNIQUE(username, friendName),
@ -57,6 +59,30 @@ const deleteFriends = database.prepare('DELETE FROM friends WHERE username = ?;'
*/
export default async function(fastify, options) {
collectDefaultMetrics({ labels: { service: "auth-api" } })
client.register.setDefaultLabels({ service: "auth-api" })
const httpRequestCounter = new client.Counter({
name: 'http_requests_total',
help: 'Total number of HTTP requests',
labelNames: ['method', 'route', 'status_code'],
})
fastify.addHook('onResponse', (req, res, done) => {
httpRequestCounter.inc({
method: req.method,
route: req.routerPath || req.url,
status_code: res.statusCode,
})
done()
})
fastify.get('/metrics', async (req, reply) => {
reply
.header('Content-Type', client.register.contentType)
.send(await client.register.metrics())
})
fastify.register(fastifyJWT, {
secret: process.env.JWT_SECRET || '123456789101112131415161718192021',
cookie: {

View File

View File

View File

@ -13,6 +13,12 @@ const loggerOption = {
}
};
function sigHandle(signal) {
process.exit(0);
}
process.on('SIGINT', sigHandle);
async function start() {
const target = process.env.API_TARGET || 'all';

View File