Skip to content

Commit

Permalink
Merge branch 'ausias/deploy-latency-monitor' of https://github.com/ho…
Browse files Browse the repository at this point in the history
…prnet/uHTTP-latency-monitor into ausias/deploy-latency-monitor
  • Loading branch information
ausias-armesto committed Sep 13, 2024
2 parents 80591f9 + 62700fd commit 1dcb2c6
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ if (require.main === module) {
metrics: {},
metricLabels: {
hops: forceZeroHop ? '0' : '1',
instance: process.env.UHTTP_LM_METRIC_INSTANCE || 'unknown',
region: process.env.UHTTP_LM_METRIC_REGION || 'unknown',
zone: process.env.UHTTP_LM_METRIC_ZONE || 'unknown',
location: process.env.UHTTP_LM_METRIC_LOCATION || 'unknown',
latitude: process.env.UHTTP_LM_METRIC_LATITUDE || 'unknown',
longitude: process.env.UHTTP_LM_METRIC_LONGITUDE || 'unknown',
instance: process.env.UHTTP_LM_METRIC_INSTANCE,
region: process.env.UHTTP_LM_METRIC_REGION,
zone: process.env.UHTTP_LM_METRIC_ZONE,
location: process.env.UHTTP_LM_METRIC_LOCATION,
latitude: process.env.UHTTP_LM_METRIC_LATITUDE,
longitude: process.env.UHTTP_LM_METRIC_LONGITUDE,
},
};
const logOpts = {
Expand Down Expand Up @@ -168,7 +168,7 @@ function tick(uClient: Routing.Client, uHTTPsettings: UHTTPsettings, settings: S
.once(uClient, uHTTPsettings.rpcProvider)
.then(collectMetrics(settings.metrics as Record<string, prom.Summary>))
.catch(reportError(settings.metrics['errorSum'] as prom.Counter))
.finally(pushMetrics(settings.pushGateway, settings.metricLabels));
.finally(pushMetrics(settings));
}

function collectMetrics(metrics: Record<string, prom.Summary>) {
Expand All @@ -188,19 +188,16 @@ function reportError(errorCounter: prom.Counter) {
};
}

function pushMetrics(pushGateway: string, metricLabels: Record<string, string>) {
function pushMetrics(settings: Settings) {
return function () {
const gateway = new prom.Pushgateway(pushGateway);
const gateway = new prom.Pushgateway(settings.pushGateway);
gateway
.push({
jobName: process.env.UHTTP_LM_METRIC_INSTANCE || 'unknown',
groupings: metricLabels,
})
.push({ jobName: settings.metricLabels.instance })
.then(() => {
log.info('Latency Monitor[%s] Metrics pushed correctly', Version);
})
.catch((err) => {
log.error('Error pushing metrics to %s: %s', pushGateway, err);
log.error('Error pushing metrics to %s: %s', settings.pushGateway, err);
});
};
}
Expand Down

0 comments on commit 1dcb2c6

Please sign in to comment.