epip-typeorm-analyses
v0.0.36
Published
**EpipTypeormAnalyses** is a NestJS module that allows you to monitor and analyze the performance of your TypeORM queries by logging the average time and the number of executions for each query. The data is stored in Redis, and you can use tools like Graf
Downloads
19
Readme
EpipTypeormAnalyses
EpipTypeormAnalyses is a NestJS module that allows you to monitor and analyze the performance of your TypeORM queries by logging the average time and the number of executions for each query. The data is stored in Redis, and you can use tools like Grafana to visualize and report on the logged data.
Installation
To install the package, use the following npm command:
npm i epip-typeorm-analyses
Usage
To integrate the EpipTypeormAnalyses module into your NestJS application, you need to register it within your AppModule. The module requires two arguments to connect to your Redis instance: url and password. Here’s an example:
import { Module } from '@nestjs/common';
import { EpipTypeormAnalyses } from 'epip-typeorm-analyses';
@Module({
imports: [
// Other imports...
EpipTypeormAnalyses.register({
url: process.env.REDIS_URL,
password: process.env.REDIS_PASS,
}),
// Other imports...
],
// Other module metadata...
})
export class AppModule {}
In the above code:
- url: The URL of your Redis instance. This is typically stored in the REDIS_URL environment variable.
- password: The password for your Redis instance. This is typically stored in the REDIS_PASS environment variable.
Functionality
Once integrated, the EpipTypeormAnalyses module will log the average execution time and the number of executions for each TypeORM query to the specified Redis database.
Query Storage
Each query is hashed to create a unique identifier. This ensures that even if the same query is executed multiple times, it is consistently tracked using the same unique key in Redis. This unique hash is then used to store and update the performance metrics in Redis, ensuring that duplicate queries are correctly aggregated under the same entry.
Visualization and Reporting
You have two options to visualize and report the logged data:
Grafana Integration: You can use Grafana to create custom dashboards and reports based on the data logged by EpipTypeormAnalyses. Grafana’s powerful visualization tools allow you to monitor and analyze your application’s database performance effectively.
Pre-Built Reporting Tool: Alternatively, you can use a pre-built reporting tool developed by Mr. Mousavi, which is publicly available on GitLab. This tool provides various log visualization and reporting features out-of-the-box.
- Repository for the reporting tool: Analyse Backend(https://gitlab.com/bakhshabadi.javad/analyse-backend/)
- Repository by Mr. Mousavi: Mousavi’s GitLab Repo(https://gitlab.com/moein1378)
Conclusion
The EpipTypeormAnalyses module is a powerful tool for monitoring the performance of TypeORM queries in your NestJS application. By logging query metrics to Redis, it provides the foundation for detailed performance analysis and reporting using tools like Grafana or the pre-built reporting tool by Mr. Mousavi.
For more detailed instructions on how to use the reporting tool or to contribute to its development, please visit the linked repositories.