Skip to content

Commit

Permalink
[CON-395] Add duration to network monitoring metrics (#3891)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaylor89 committed Sep 20, 2022
1 parent 5d613e4 commit 89545fb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions discovery-provider/plugins/network-monitoring/src/metrics/index.ts
Expand Up @@ -68,11 +68,13 @@ export const generateMetrics = async (run_id: number) => {
);

// Record duration for generating metrics and export to prometheus
const endTime = Date.now()
endTimer({ run_id: run_id });

if (userCount > 0) {
await publishSlackReport({
runStartTime: runStartTime.toString(),
runDuration: msToTime(endTime - runStartTime.getTime()),
fullySyncedUsersCount:
((fullySyncedUsersCount / userCount) * 100).toFixed(2) + "%",
partiallySyncedUsersCount:
Expand Down Expand Up @@ -123,3 +125,16 @@ const publishSlackReport = async (metrics: Object) => {
);
}
};

const msToTime = (duration: number) => {
const milliseconds = Math.floor((duration % 1000) / 100)
const seconds = Math.floor((duration / 1000) % 60)
const minutes = Math.floor((duration / (1000 * 60)) % 60)
const hours = Math.floor((duration / (1000 * 60 * 60)) % 24)

const hoursStr = (hours < 10) ? "0" + hours : hours;
const minutesStr = (minutes < 10) ? "0" + minutes : minutes;
const secondsStr = (seconds < 10) ? "0" + seconds : seconds;

return `${hoursStr}:${minutesStr}:${secondsStr}:${milliseconds.toString()}`
}

0 comments on commit 89545fb

Please sign in to comment.