Skip to content

Commit

Permalink
output metrics as array
Browse files Browse the repository at this point in the history
  • Loading branch information
malteish committed Sep 10, 2024
1 parent 0d5cd69 commit d1c7edf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
15 changes: 7 additions & 8 deletions packages/delivery-service/src/persistence/metrics/getMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DeliveryServiceProperties } from '@dm3-org/dm3-lib-delivery';
import { Redis, RedisPrefix } from '../getDatabase';
import { getCurrentIntervalTimestamp } from './getCurrentIntervalTimestamp';
import { MetricsObject } from './metricTypes';

/**
* Get the metrics from the database, excluding the current interval.
Expand All @@ -15,9 +14,9 @@ export function getMetrics(
redis: Redis,
): (
deliveryServiceProperties: DeliveryServiceProperties,
) => Promise<MetricsObject> {
) => Promise<IntervalMetric[]> {
return async (deliveryServiceProperties: DeliveryServiceProperties) => {
const metrics: MetricsObject = {};
const metrics: IntervalMetric[] = [];
const messageCountKeys = await redis.keys(
`${RedisPrefix.MetricsMessageCount}*`,
);
Expand All @@ -34,9 +33,6 @@ export function getMetrics(
continue;
}

const date = new Date(timestamp * 1000);
const dateString = date.toISOString();

const messageCount = await redis.get(key);
const messageSizeBytes = await redis.get(
`${RedisPrefix.MetricsMessageSize}${timestamp}`,
Expand All @@ -45,11 +41,14 @@ export function getMetrics(
`${RedisPrefix.MetricsNotificationCount}${timestamp}`,
);

metrics[dateString] = {
metrics.push({
timestamp_start: timestamp,
duration_seconds:
deliveryServiceProperties.metricsCollectionIntervalInSeconds,
messageCount: parseInt(messageCount || '0', 10),
messageSizeBytes: parseInt(messageSizeBytes || '0', 10),
notificationCount: parseInt(notificationCount || '0', 10),
};
});
}

return metrics;
Expand Down
10 changes: 2 additions & 8 deletions packages/delivery-service/src/persistence/metrics/metricTypes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
type IntervalMetric = {
timestamp_start: number;
duration_seconds: number;
messageCount: number;
messageSizeBytes: number;
notificationCount: number;
};

type MetricsMap = Map<Date, IntervalMetric>;

export type { MetricsMap, IntervalMetric };

export interface MetricsObject {
[date: string]: IntervalMetric;
}

0 comments on commit d1c7edf

Please sign in to comment.