From edf25d6f00ffbc369a5bff4aaf08575b0acd5466 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Mon, 9 Sep 2024 10:31:52 -0600 Subject: [PATCH] chore(redis): add redis connection and error metrics --- src/cache/redis-kv-store.ts | 5 +++-- src/metrics.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cache/redis-kv-store.ts b/src/cache/redis-kv-store.ts index 6dd7798..1e36ddf 100644 --- a/src/cache/redis-kv-store.ts +++ b/src/cache/redis-kv-store.ts @@ -19,6 +19,7 @@ import { RedisClientType, commandOptions, createClient } from 'redis'; import winston from 'winston'; import * as config from '../config.js'; +import * as metrics from '../metrics.js'; import { KVBufferStore } from '../types.js'; export class RedisKvStore implements KVBufferStore { @@ -45,14 +46,14 @@ export class RedisKvStore implements KVBufferStore { message: error.message, stack: error.stack, }); - // TODO: add prometheus metric for redis error + metrics.redisErrors.inc({ error: error.message }); }); this.client.connect().catch((error: any) => { this.log.error(`Redis connection error`, { message: error.message, stack: error.stack, }); - // TODO: add prometheus metric for redis connection error + metrics.redisConnectionError.inc(); }); } diff --git a/src/metrics.ts b/src/metrics.ts index 581dd45..7b143c3 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -19,6 +19,7 @@ import * as promClient from 'prom-client'; export const metrics = new promClient.Registry(); +// ARNS cache metrics export const arnsCacheHit = new promClient.Counter({ name: 'arns_cache_hit', help: 'Number of times the ARNS cache was hit', @@ -30,3 +31,15 @@ export const arnsCacheMiss = new promClient.Counter({ help: 'Number of times the ARNS cache was missed', labelNames: ['cache_type'], }); + +// Redis metrics +export const redisConnectionError = new promClient.Gauge({ + name: 'redis_connection_error', + help: 'Redis connection error', +}); + +export const redisErrors = new promClient.Counter({ + name: 'redis_errors', + help: 'Redis errors', + labelNames: ['error'], +});