Add total.bytes{Recv, Sent} to provider stats (#4671)
This commit is contained in:
@@ -56,7 +56,7 @@ export class HttpProvider implements ProviderInterface {
|
||||
this.#headers = headers;
|
||||
this.#stats = {
|
||||
active: { requests: 0, subscriptions: 0 },
|
||||
total: { cached: 0, requests: 0, subscriptions: 0, timeout: 0 }
|
||||
total: { bytesRecv: 0, bytesSent: 0, cached: 0, requests: 0, subscriptions: 0, timeout: 0 }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -142,6 +142,7 @@ export class HttpProvider implements ProviderInterface {
|
||||
|
||||
async #send <T> (body: string): Promise<T> {
|
||||
this.#stats.active.requests++;
|
||||
this.#stats.total.bytesSent += body.length;
|
||||
|
||||
try {
|
||||
const response = await fetch(this.#endpoint, {
|
||||
@@ -157,8 +158,11 @@ export class HttpProvider implements ProviderInterface {
|
||||
|
||||
assert(response.ok, () => `[${response.status}]: ${response.statusText}`);
|
||||
|
||||
const result = (await response.json()) as JsonRpcResponse;
|
||||
const decoded = this.#coder.decodeResponse(result) as T;
|
||||
const result = await response.text();
|
||||
|
||||
this.#stats.total.bytesRecv += result.length;
|
||||
|
||||
const decoded = this.#coder.decodeResponse(JSON.parse(result) as JsonRpcResponse) as T;
|
||||
|
||||
this.#stats.active.requests--;
|
||||
|
||||
|
||||
@@ -68,6 +68,8 @@ export interface ProviderStats {
|
||||
subscriptions: number;
|
||||
};
|
||||
total: {
|
||||
bytesRecv: number;
|
||||
bytesSent: number;
|
||||
cached: number;
|
||||
requests: number;
|
||||
subscriptions: number;
|
||||
|
||||
@@ -133,7 +133,7 @@ export class WsProvider implements ProviderInterface {
|
||||
this.#websocket = null;
|
||||
this.#stats = {
|
||||
active: { requests: 0, subscriptions: 0 },
|
||||
total: { cached: 0, requests: 0, subscriptions: 0, timeout: 0 }
|
||||
total: { bytesRecv: 0, bytesSent: 0, cached: 0, requests: 0, subscriptions: 0, timeout: 0 }
|
||||
};
|
||||
|
||||
if (autoConnectMs > 0) {
|
||||
@@ -333,7 +333,7 @@ export class WsProvider implements ProviderInterface {
|
||||
start: Date.now(),
|
||||
subscription
|
||||
};
|
||||
|
||||
this.#stats.total.bytesSent += json.length;
|
||||
this.#websocket.send(json);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
@@ -444,6 +444,8 @@ export class WsProvider implements ProviderInterface {
|
||||
#onSocketMessage = (message: MessageEvent<string>): void => {
|
||||
l.debug(() => ['received', message.data]);
|
||||
|
||||
this.#stats.total.bytesRecv += message.data.length;
|
||||
|
||||
const response = JSON.parse(message.data) as JsonRpcResponse;
|
||||
|
||||
return isUndefined(response.method)
|
||||
|
||||
Reference in New Issue
Block a user