metrics counter
This commit is contained in:
@@ -40,6 +40,8 @@ enum METRIC_TYPES {
|
|||||||
gpa_fetch_duration = 'gpa_fetch_duration',
|
gpa_fetch_duration = 'gpa_fetch_duration',
|
||||||
last_ws_message_received_ts = 'last_ws_message_received_ts',
|
last_ws_message_received_ts = 'last_ws_message_received_ts',
|
||||||
account_updates_count = 'account_updates_count',
|
account_updates_count = 'account_updates_count',
|
||||||
|
cache_hit_count = 'cache_hit_count',
|
||||||
|
cache_miss_count = 'cache_miss_count',
|
||||||
current_system_ts = 'current_system_ts',
|
current_system_ts = 'current_system_ts',
|
||||||
health_status = 'health_status',
|
health_status = 'health_status',
|
||||||
}
|
}
|
||||||
@@ -126,6 +128,14 @@ lastWsReceivedTsGauge.addCallback((obs: ObservableResult) => {
|
|||||||
obs.observe(lastWsMsgReceivedTs, {});
|
obs.observe(lastWsMsgReceivedTs, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const cacheHitCounter = meter.createCounter(METRIC_TYPES.cache_hit_count, {
|
||||||
|
description: 'Total redis cache hits',
|
||||||
|
});
|
||||||
|
|
||||||
|
const cacheMissCounter = meter.createCounter(METRIC_TYPES.cache_miss_count, {
|
||||||
|
description: 'Total redis cache misses',
|
||||||
|
});
|
||||||
|
|
||||||
const accountUpdatesCounter = meter.createCounter(
|
const accountUpdatesCounter = meter.createCounter(
|
||||||
METRIC_TYPES.account_updates_count,
|
METRIC_TYPES.account_updates_count,
|
||||||
{
|
{
|
||||||
@@ -238,4 +248,6 @@ export {
|
|||||||
handleHealthCheck,
|
handleHealthCheck,
|
||||||
setLastReceivedWsMsgTs,
|
setLastReceivedWsMsgTs,
|
||||||
accountUpdatesCounter,
|
accountUpdatesCounter,
|
||||||
|
cacheHitCounter,
|
||||||
|
cacheMissCounter,
|
||||||
};
|
};
|
||||||
|
|||||||
72
src/index.ts
72
src/index.ts
@@ -37,7 +37,9 @@ import {
|
|||||||
gpaFetchDurationHistogram,
|
gpaFetchDurationHistogram,
|
||||||
handleHealthCheck,
|
handleHealthCheck,
|
||||||
accountUpdatesCounter,
|
accountUpdatesCounter,
|
||||||
|
cacheHitCounter,
|
||||||
setLastReceivedWsMsgTs,
|
setLastReceivedWsMsgTs,
|
||||||
|
cacheMissCounter,
|
||||||
} from './core/metrics';
|
} from './core/metrics';
|
||||||
import { handleResponseTime } from './core/middleware';
|
import { handleResponseTime } from './core/middleware';
|
||||||
import {
|
import {
|
||||||
@@ -768,22 +770,10 @@ const main = async () => {
|
|||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_perp_${normedMarketIndex}_depth_5`
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_5`
|
||||||
);
|
);
|
||||||
if (
|
|
||||||
Math.abs(
|
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
|
||||||
l2Formatted = redisL2;
|
|
||||||
} else if (parseInt(adjustedDepth as string) === 20) {
|
} else if (parseInt(adjustedDepth as string) === 20) {
|
||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_perp_${normedMarketIndex}_depth_20`
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_20`
|
||||||
);
|
);
|
||||||
if (
|
|
||||||
Math.abs(
|
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
|
||||||
l2Formatted = redisL2;
|
|
||||||
} else if (parseInt(adjustedDepth as string) === 100) {
|
} else if (parseInt(adjustedDepth as string) === 100) {
|
||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_perp_${normedMarketIndex}_depth_100`
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_100`
|
||||||
@@ -791,9 +781,7 @@ const main = async () => {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
redisL2 &&
|
redisL2 &&
|
||||||
Math.abs(
|
slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
)
|
||||||
l2Formatted = redisL2;
|
l2Formatted = redisL2;
|
||||||
} else if (
|
} else if (
|
||||||
@@ -808,22 +796,10 @@ const main = async () => {
|
|||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_spot_${normedMarketIndex}_depth_5`
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_5`
|
||||||
);
|
);
|
||||||
if (
|
|
||||||
Math.abs(
|
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
|
||||||
l2Formatted = redisL2;
|
|
||||||
} else if (parseInt(adjustedDepth as string) === 20) {
|
} else if (parseInt(adjustedDepth as string) === 20) {
|
||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_spot_${normedMarketIndex}_depth_20`
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_20`
|
||||||
);
|
);
|
||||||
if (
|
|
||||||
Math.abs(
|
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
|
||||||
l2Formatted = redisL2;
|
|
||||||
} else if (parseInt(adjustedDepth as string) === 100) {
|
} else if (parseInt(adjustedDepth as string) === 100) {
|
||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_spot_${normedMarketIndex}_depth_100`
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_100`
|
||||||
@@ -831,14 +807,13 @@ const main = async () => {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
redisL2 &&
|
redisL2 &&
|
||||||
Math.abs(
|
slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
)
|
||||||
l2Formatted = redisL2;
|
l2Formatted = redisL2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l2Formatted) {
|
if (l2Formatted) {
|
||||||
|
cacheHitCounter.add(1);
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end(JSON.stringify(l2Formatted));
|
res.end(JSON.stringify(l2Formatted));
|
||||||
return;
|
return;
|
||||||
@@ -896,7 +871,7 @@ const main = async () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cacheMissCounter.add(1);
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end(JSON.stringify(l2Formatted));
|
res.end(JSON.stringify(l2Formatted));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -976,27 +951,20 @@ const main = async () => {
|
|||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_perp_${normedMarketIndex}_depth_5`
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_5`
|
||||||
);
|
);
|
||||||
if (
|
|
||||||
Math.abs(
|
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
|
||||||
l2Formatted = redisL2;
|
|
||||||
} else if (parseInt(adjustedDepth as string) === 20) {
|
} else if (parseInt(adjustedDepth as string) === 20) {
|
||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_perp_${normedMarketIndex}_depth_20`
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_20`
|
||||||
);
|
);
|
||||||
if (
|
|
||||||
Math.abs(
|
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
|
||||||
l2Formatted = redisL2;
|
|
||||||
} else if (parseInt(adjustedDepth as string) === 100) {
|
} else if (parseInt(adjustedDepth as string) === 100) {
|
||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_perp_${normedMarketIndex}_depth_100`
|
`last_update_orderbook_perp_${normedMarketIndex}_depth_100`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
redisL2 &&
|
||||||
|
slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10
|
||||||
|
)
|
||||||
|
l2Formatted = redisL2;
|
||||||
} else if (
|
} else if (
|
||||||
marketType === 'spot' &&
|
marketType === 'spot' &&
|
||||||
normedParam['includePhoenix'].toLowerCase() === 'true' &&
|
normedParam['includePhoenix'].toLowerCase() === 'true' &&
|
||||||
@@ -1008,22 +976,10 @@ const main = async () => {
|
|||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_spot_${normedMarketIndex}_depth_5`
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_5`
|
||||||
);
|
);
|
||||||
if (
|
|
||||||
Math.abs(
|
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
|
||||||
l2Formatted = redisL2;
|
|
||||||
} else if (parseInt(adjustedDepth as string) === 20) {
|
} else if (parseInt(adjustedDepth as string) === 20) {
|
||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_spot_${normedMarketIndex}_depth_20`
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_20`
|
||||||
);
|
);
|
||||||
if (
|
|
||||||
Math.abs(
|
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
|
||||||
l2Formatted = redisL2;
|
|
||||||
} else if (parseInt(adjustedDepth as string) === 100) {
|
} else if (parseInt(adjustedDepth as string) === 100) {
|
||||||
redisL2 = await redisClient.client.get(
|
redisL2 = await redisClient.client.get(
|
||||||
`last_update_orderbook_spot_${normedMarketIndex}_depth_100`
|
`last_update_orderbook_spot_${normedMarketIndex}_depth_100`
|
||||||
@@ -1031,14 +987,13 @@ const main = async () => {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
redisL2 &&
|
redisL2 &&
|
||||||
Math.abs(
|
slotSource.getSlot() - parseInt(JSON.parse(redisL2).slot) < 10
|
||||||
parseInt(JSON.parse(redisL2).slot) - slotSource.getSlot()
|
|
||||||
) < 10
|
|
||||||
)
|
)
|
||||||
l2Formatted = redisL2;
|
l2Formatted = redisL2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l2Formatted) {
|
if (l2Formatted) {
|
||||||
|
cacheHitCounter.add(1);
|
||||||
return l2Formatted;
|
return l2Formatted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1097,6 +1052,7 @@ const main = async () => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cacheMissCounter.add(1);
|
||||||
return l2Formatted;
|
return l2Formatted;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user