Skip to content

Commit

Permalink
Merge pull request #2 from lgrdev/1-utiliser-systeminformationio
Browse files Browse the repository at this point in the history
writer et cleaner réécrits
  • Loading branch information
lgrdev authored May 16, 2024
2 parents 727a1ed + ebc3f79 commit 09b56d8
Show file tree
Hide file tree
Showing 15 changed files with 693 additions and 338 deletions.
16 changes: 6 additions & 10 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ BASE_URL=""
CLEANER_CRON='0 */5 * * *'
CLEANER_DELETE_AFTER_HOURS=5

# les données CPU sont enregistrées toutes les 5 secondes
CPU_CRON='*/5 * * * * *'
# CLEANER JOB : le job est executé toutes les 2 heures
# et supprime les données plus anciennes que 1 heures
CLEANER_CRON='0 */2 * * *'
CLEANER_DELETE_AFTER_HOURS=1

# les données RAM sont enregistrées toutes les 5 secondes
RAM_CRON='*/5 * * * * *'

# les données DISK sont enregistrées toutes les 5 secondes
DISK_CRON='*/5 * * * * *'

# les données dockers sont enregistrées toutes les 2 minutes
DOCKER_CRON='*/2 * * * *'
# les données sont enregistrées toutes les 5 secondes
WRITER_CRON='*/5 * * * * *'
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Utilisez IntelliSense pour en savoir plus sur les attributs possibles.
// Pointez pour afficher la description des attributs existants.
// Pour plus d'informations, visitez : https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Lancer Chrome en utilisant localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ const swaggerDocs = require('./swagger.js');


// Importation des tâches planifiées
const jobmemory = require('./tasks/job_memory.js');
const jobcpu = require('./tasks/job_cpu.js');
const jobdisk = require('./tasks/job_disk.js');
const jobwriter = require('./tasks/job_writer.js');
const jobcleaner = require('./tasks/job_cleaner.js');
const jobdocker = require('./tasks/job_docker.js');


// Création de l'application Express
Expand Down
2 changes: 1 addition & 1 deletion mochawesome-report/mochawesome.html

Large diffs are not rendered by default.

526 changes: 445 additions & 81 deletions mochawesome-report/mochawesome.json

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions modules/database.js

This file was deleted.

64 changes: 38 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"name": "servermetrics",
"version": "1.0.1",
"version": "1.1.0",
"description": "simple serveur interne de monitoring (cpu, ram, disk, docker) avec des api rest",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "mocha --env-file=.env **/*.spec.js --reporter mochawesome -r dotenv/config",
"report": "mocha --reporter mochawesome"
},
"keywords": ["nodejs", "express", "prisma", "node-schedule","postgresql", "swagger", "rest", "api"],
"keywords": [
"nodejs",
"express",
"prisma",
"node-schedule",
"postgresql",
"swagger",
"rest",
"api"
],
"author": "Lgrdev",
"license": "ISC",
"dependencies": {
Expand All @@ -17,9 +26,10 @@
"expect.js": "^0.3.1",
"express": "^4.19.2",
"jsonwebtoken": "^9.0.2",
"node-disk-info": "^1.3.0",
"moment": "^2.30.1",
"node-schedule": "^2.1.1",
"prisma": "^5.13.0"
"prisma": "^5.13.0",
"systeminformation": "^5.22.9"
},
"devDependencies": {
"axios": "^1.6.8",
Expand Down
7 changes: 3 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ServerMetrics

[![Node.js CI](https://github.com/lgrdev/servermetrics/actions/workflows/node.js.yml/badge.svg)](https://github.com/lgrdev/servermetrics/actions/workflows/node.js.yml)
[![Mocha tests - Ok](https://img.shields.io/static/v1?label=Mocha+tests&message=Ok&color=2ea44f)](https://)
[![Made with PostgreSQL](https://img.shields.io/badge/PostgreSQL-13-blue?logo=postgresql&logoColor=white)](https://www.postgresql.org/ "Go to PostgresSQL homepage")
Expand All @@ -14,14 +15,12 @@ ce projet mets en oeuvre NodeJs, Prisma comme ORM et Postgresql pour stocker les

Les métrics sont enregistrés toutes les 5 secondes via node-schedule


## Projet Metrics

![Projet Metrics](./images/nodejs-metrics.png "Projet Metrics")

Le projet metric est un projet experimental permettant de mettre en oeuvre différentes techniques

- Nodejs et prisma pour le serveur d'api
- Nodejs, express et prisma pour le serveur d'api
- Vuejs 3 en typescript pour le viewer
- Traefik et docker pour l'hebergement des sites et base de données

- Traefik et docker pour l'hebergement des applications et base de données
20 changes: 11 additions & 9 deletions tasks/job_cleaner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Importation du module Prisma pour la base de données
const prisma = require('../modules/database.js');
const prisma = require("@prisma/client");
const { PrismaClient } = prisma;

const prismaClient = new PrismaClient();

// Importation du module node-schedule pour la planification de tâches
const schedule = require('node-schedule');
Expand All @@ -15,10 +17,10 @@ const schedule = require('node-schedule');
async function mainFunction() {
try {
// Suppression des données de la mémoire
const result = await prisma.data_memory.deleteMany({
await prismaClient.data_memory.deleteMany({
where: {
createdAt: {
lt: new Date(new Date() - 2 * 60 * 60 * 1000)
lt: new Date(new Date() - process.env.CLEANER_DELETE_AFTER_HOURS * 60 * 60 * 1000)
}
}
});
Expand All @@ -29,10 +31,10 @@ async function mainFunction() {

try {
// Suppression des données du CPU
const result = await prisma.data_cpu.deleteMany({
await prismaClient.data_cpu.deleteMany({
where: {
createdAt: {
lt: new Date(new Date() - 2 * 60 * 60 * 1000)
lt: new Date(new Date() - process.env.CLEANER_DELETE_AFTER_HOURS * 60 * 60 * 1000)
}
}
});
Expand All @@ -43,10 +45,10 @@ async function mainFunction() {

try {
// Suppression des données du disque
const result = await prisma.data_disk.deleteMany({
await prismaClient.data_disk.deleteMany({
where: {
createdAt: {
lt: new Date(new Date() - 2 * 60 * 60 * 1000)
lt: new Date(new Date() - process.env.CLEANER_DELETE_AFTER_HOURS * 60 * 60 * 1000)
}
}
});
Expand All @@ -57,7 +59,7 @@ async function mainFunction() {

try {
// Suppression des données de la DataContainerState
const result = await prisma.DataContainerState.deleteMany({
await prismaClient.DataContainerState.deleteMany({
where: {
createdAt: {
lt: new Date(new Date() - process.env.CLEANER_DELETE_AFTER_HOURS * 60 * 60 * 1000)
Expand Down
42 changes: 0 additions & 42 deletions tasks/job_cpu.js

This file was deleted.

42 changes: 0 additions & 42 deletions tasks/job_disk.js

This file was deleted.

Loading

0 comments on commit 09b56d8

Please sign in to comment.