Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL='sqlserver://localhost:1433;database=gil_cms2;integratedSecurity=true;trustServerCertificate=true'
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,87 @@ Simple, self-hosted module based on Socket.io and Chart.js to report realtime se

Note: This plugin works on Node versions > 4.x

## Database Setup

This package now includes database logging using Prisma with SQL Server. Follow these steps to set up:

1. In your main project, create a `.env` file in the root directory if it doesn't exist already. Add the following line, replacing the placeholders with your actual database details:

```
DATABASE_URL="sqlserver://localhost:1433;database=your_database;user=your_username;password=your_password;trustServerCertificate=true"
```

Replace username, password, localhost, and your_database_name with your actual database credentials.

2. In your main project's root directory, create a `prisma` folder if it doesn't exist. Inside this folder, create a `schema.prisma` file with the following content:

```prisma
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
}

model StatusLog {
id Int @id @default(autoincrement())
timestamp DateTime
cpuCount Int
memory Float
pid Int
ppid Int
ctime BigInt
elapsed Float
load1 Float
load5 Float
load15 Float
heapTotal BigInt
heapUsed BigInt
response2xx Int
response3xx Int
response4xx Int
response5xx Int
responseMean Float
createdAt DateTime @default(now())
}
```

3. In your main project's root directory, run the following commands:

```bash
npx prisma generate
npx prisma db push
```

This will generate the Prisma client and create the necessary table in your database.

## Usage

In your main project, initialize the middleware in your Express app:

```javascript
const express = require('express');
const statusMonitor = require('express-status-monitor');

const app = express();

app.use(statusMonitor({
path: '/status',
databaseLoggingInterval: 60 // Log to database every 60 seconds
}));

// ... rest of your Express app setup
```

Make sure your SQL Server instance is running and accessible before starting your application.

## Viewing Status

Once your app is running, you can view the status page by navigating to the path you specified (e.g., `http://localhost:3000/status`).


## Run examples

1. Go to `cd examples/`
Expand Down
163 changes: 163 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
},
"license": "MIT",
"dependencies": {
"@prisma/client": "^5.18.0",
"axios": "0.26.0",
"debug": "4.1.1",
"handlebars": "^4.7.7",
Expand All @@ -83,6 +84,7 @@
"chai": "4.3.6",
"eslint": "8.10.0",
"mocha": "9.2.1",
"prisma": "^5.18.0",
"sinon": "13.0.1"
},
"funding": {
Expand Down
47 changes: 47 additions & 0 deletions prisma-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const fs = require('fs');
const path = require('path');

const schemaContent = `
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
}

model StatusLog {
id Int @id @default(autoincrement())
timestamp DateTime
cpuCount Int
memory Float
pid Int
ppid Int
ctime BigInt
elapsed Float
load1 Float
load5 Float
load15 Float
heapTotal BigInt
heapUsed BigInt
response2xx Int
response3xx Int
response4xx Int
response5xx Int
responseMean Float
createdAt DateTime @default(now())
}
`;

const prismaDir = path.join(process.cwd(), 'prisma');
const schemaPath = path.join(prismaDir, 'schema.prisma');

if (!fs.existsSync(prismaDir)) {
fs.mkdirSync(prismaDir);
}

fs.writeFileSync(schemaPath, schemaContent);

console.log('Prisma schema created. Please run `npx prisma generate` to generate the Prisma client.');
console.log('Make sure to set the DATABASE_URL environment variable in your .env file.');
30 changes: 30 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
}

model StatusLog {
id Int @id @default(autoincrement())
timestamp DateTime
cpuCount Int
memory Float
pid Int
ppid Int
ctime BigInt
elapsed Float
load1 Float
load5 Float
load15 Float
heapTotal BigInt
heapUsed BigInt
response2xx Int
response3xx Int
response4xx Int
response5xx Int
responseMean Float
createdAt DateTime @default(now())
}
Loading