Skip to content

Commit

Permalink
fix metrics name
Browse files Browse the repository at this point in the history
  • Loading branch information
wphan committed Dec 8, 2023
1 parent 07f430d commit 8e6af84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
17 changes: 5 additions & 12 deletions src/core/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum METRIC_TYPES {
endpoint_response_status = 'endpoint_response_status',
gpa_fetch_duration = 'gpa_fetch_duration',
last_ws_message_received_ts = 'last_ws_message_received_ts',
account_updates_per_sec = 'account_updates_per_sec',
account_updates_count = 'account_updates_count',
current_system_ts = 'current_system_ts',
health_status = 'health_status',
}
Expand Down Expand Up @@ -126,19 +126,12 @@ lastWsReceivedTsGauge.addCallback((obs: ObservableResult) => {
obs.observe(lastWsMsgReceivedTs, {});
});

let lastAccountUpdatesPerSecond = 0;
const setAccountUpdatesPerSecond = (updatesPerSecond: number) => {
lastAccountUpdatesPerSecond = updatesPerSecond;
};
const accountUpdatesPerSecondGauge = meter.createObservableGauge(
METRIC_TYPES.account_updates_per_sec,
const accountUpdatesCounter = meter.createCounter(
METRIC_TYPES.account_updates_count,
{
description: 'Updates per second, the last second',
description: 'Total accounts update',
}
);
accountUpdatesPerSecondGauge.addCallback((obs: ObservableResult) => {
obs.observe(lastAccountUpdatesPerSecond, {});
});

const currentSystemTsGauge = meter.createObservableGauge(
METRIC_TYPES.current_system_ts,
Expand Down Expand Up @@ -244,5 +237,5 @@ export {
responseStatusCounter,
handleHealthCheck,
setLastReceivedWsMsgTs,
setAccountUpdatesPerSecond as setLastAccountUpdatesPerSecond,
accountUpdatesCounter,
};
20 changes: 11 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import * as http from 'http';
import {
gpaFetchDurationHistogram,
handleHealthCheck,
setLastAccountUpdatesPerSecond,
accountUpdatesCounter,
setLastReceivedWsMsgTs,
} from './core/metrics';
import { handleResponseTime } from './core/middleware';
Expand Down Expand Up @@ -255,7 +255,7 @@ const main = async () => {
};
}

let updatesPerTenSecond = 0;
let updatesReceivedTotal = 0;
const orderSubscriber = new OrderSubscriber({
driftClient,
subscriptionConfig,
Expand All @@ -264,13 +264,10 @@ const main = async () => {
'updateReceived',
(_pubkey: PublicKey, _slot: number, _dataType: 'raw' | 'decoded') => {
setLastReceivedWsMsgTs(Date.now());
updatesPerTenSecond++;
updatesReceivedTotal++;
accountUpdatesCounter.add(1);
}
);
setInterval(() => {
setLastAccountUpdatesPerSecond(updatesPerTenSecond / 10);
updatesPerTenSecond = 0;
}, 10_000);

dlobProvider = getDLOBProviderFromOrderSubscriber(orderSubscriber);

Expand Down Expand Up @@ -308,6 +305,9 @@ const main = async () => {
);
logger.info(`dlob provider size ${dlobProvider.size()}`);

logger.info(
`GPA refresh?: ${useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH}`
);
if (useWebsocket && !FEATURE_FLAGS.DISABLE_GPA_REFRESH) {
const recursiveFetch = (delay = WS_FALLBACK_FETCH_INTERVAL) => {
setTimeout(() => {
Expand Down Expand Up @@ -479,9 +479,11 @@ const main = async () => {
auctionEndPrice: order.auctionEndPrice.toString(),
maxTs: order.maxTs.toString(),
};
if (order.quoteAssetAmount) {
if (order.quoteAssetAmountFilled) {
orderHuman['quoteAssetAmount'] =
order.quoteAssetAmount.toString();
order.quoteAssetAmountFilled.toString();
orderHuman['quoteAssetAmountFilled'] =
order.quoteAssetAmountFilled.toString();
}

orders.push({
Expand Down

0 comments on commit 8e6af84

Please sign in to comment.