From a33d7e07b30d782a64665078e198a9a1f393f4d5 Mon Sep 17 00:00:00 2001 From: Benjamin Wilson Date: Tue, 25 Feb 2025 23:59:29 -0500 Subject: [PATCH] logging --- src/models/StratumV1Client.ts | 2 +- src/services/stratum-v1.service.ts | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/models/StratumV1Client.ts b/src/models/StratumV1Client.ts index 48e5ce6..e40147f 100644 --- a/src/models/StratumV1Client.ts +++ b/src/models/StratumV1Client.ts @@ -234,7 +234,7 @@ export class StratumV1Client { eStratumErrorCode.OtherUnknown, 'Authorization validation error', errors).response(); - console.log(err); + //console.log(err); const success = await this.write(err); if (!success) { return; diff --git a/src/services/stratum-v1.service.ts b/src/services/stratum-v1.service.ts index 9cdb784..6b30ce6 100644 --- a/src/services/stratum-v1.service.ts +++ b/src/services/stratum-v1.service.ts @@ -15,6 +15,11 @@ import { StratumV1JobsService } from './stratum-v1-jobs.service'; @Injectable() export class StratumV1Service implements OnModuleInit { + private socketTimeout = 0; + private emptySocket = 0; + private normalClosure = 0; + private errorClosure = 0; + constructor( private readonly bitcoinRpcService: BitcoinRpcService, private readonly clientService: ClientService, @@ -61,7 +66,11 @@ export class StratumV1Service implements OnModuleInit { const cleanup = async (reason: string) => { if (client.extraNonceAndSessionId != null) { await client.destroy(); - console.log(`Client ${client.extraNonceAndSessionId} disconnected, Reason: ${reason}`); + if(reason == 'Error'){ + this.errorClosure++; + }else{ + this.normalClosure++; + } } if (!socket.destroyed) { socket.end(); @@ -76,16 +85,22 @@ export class StratumV1Service implements OnModuleInit { // Handle socket timeouts socket.on('timeout', async () => { - console.log(`Socket timeout ${socket.remoteAddress}, ${socket.bytesRead}/${socket.bytesWritten}, ${client.clientSubscription?.userAgent}`); + if(socket.bytesRead == 0 || socket.bytesWritten == 0){ + this.emptySocket++; + }else{ + this.socketTimeout++; + } await cleanup("Timeout"); }); // Handle errors properly socket.on('error', async (error: Error) => { - console.log(`Socket error: ${error.message}`); await cleanup("Error"); }); + // + + }); // Ensure server itself handles errors @@ -96,6 +111,14 @@ export class StratumV1Service implements OnModuleInit { server.listen(port, () => { console.log(`Stratum server is listening on port ${port}`); }); + + setInterval(() => { + console.log(`Socket stats: ${this.emptySocket} empty, ${this.socketTimeout} timeouts, ${this.normalClosure} normal closure, ${this.errorClosure} error closure`); + this.emptySocket = 0; + this.socketTimeout = 0; + this.normalClosure = 0; + this.errorClosure = 0; + }, 1000 * 60); }