Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Added additional conditions to alerts

Yevhenii Kulisidi07df7536e040
diff --git a/src/project/dto/project.dto.ts b/src/project/dto/project.dto.ts
index 642f27ff6..6f884b76f 100644
--- a/src/project/dto/project.dto.ts
+++ b/src/project/dto/project.dto.ts
@@ -8,7 +8,9 @@ export enum QueryMetric {
export enum QueryCondition {
GREATER_THAN = 'greater_than',
+ GREATER_EQUAL_THAN = 'greater_equal_than',
LESS_THAN = 'less_than',
+ LESS_EQUAL_THAN = 'less_equal_than',
}
export enum QueryTime {
diff --git a/src/task-manager/task-manager.service.ts b/src/task-manager/task-manager.service.ts
index 9ae4afd6f..088c43997 100644
--- a/src/task-manager/task-manager.service.ts
+++ b/src/task-manager/task-manager.service.ts
@@ -402,9 +402,9 @@ export class TaskManagerService {
}
// every 5 minutes
- @Cron('*/5 * * * *')
- // every 5 seconds
- // @Cron('*/5 * * * * *')
+ // @Cron('*/5 * * * *')
+ //every 5 seconds
+ @Cron('*/5 * * * * *')
async checkAdditionalAlerts(): Promise<void> {
const projects = await this.projectService.findWhere(
{
@@ -453,14 +453,18 @@ export class TaskManagerService {
const isLess =
projects[i].additionalAlertQueryCondition === QueryCondition.LESS_THAN
? '<'
- : '>'
-
- const query = `SELECT count() FROM analytics WHERE pid = '${
- projects[i].id
- }' AND unique = '${isUnique}' AND created ${isLess.replace(
- '<',
- '>',
- )} now() - ${time}`
+ : projects[i].additionalAlertQueryCondition ===
+ QueryCondition.LESS_EQUAL_THAN
+ ? '<='
+ : projects[i].additionalAlertQueryCondition ===
+ QueryCondition.GREATER_THAN
+ ? '>'
+ : projects[i].additionalAlertQueryCondition ===
+ QueryCondition.GREATER_EQUAL_THAN
+ ? '>='
+ : ''
+
+ const query = `SELECT count() FROM analytics WHERE pid = '${projects[i].id}' AND unique = '${isUnique}' AND created ${isLess} now() - ${time}`
const queryResult = await clickhouse.query(query).toPromise()
const count = Number(queryResult[0]['count()'])