Browse Source

electrum connect/disconnect stats

master
Dan Janosik 5 years ago
parent
commit
4dae273cd6
No known key found for this signature in database GPG Key ID: C6F8CE9FFDB2CED2
  1. 42
      app/api/electrumAddressApi.js
  2. 31
      views/admin.pug

42
app/api/electrumAddressApi.js

@ -16,7 +16,14 @@ const ElectrumClient = require('electrum-client');
var electrumClients = [];
global.electrumStats = {};
global.electrumStats = {
base: {
connect: { count: 0, firstSeenAt: null, lastSeenAt: null },
disconnect: { count: 0, firstSeenAt: null, lastSeenAt: null },
error: { count: 0, firstSeenAt: null, lastSeenAt: null }
},
rpc: {}
};
var noConnectionsErrorText = "No ElectrumX connection available. This could mean that the connection was lost or that ElectrumX is processing transactions and therefore not accepting requests. This tool will try to reconnect. If you manage your own ElectrumX server you may want to check your ElectrumX logs.";
@ -53,6 +60,13 @@ function connectToServer(host, port, protocol) {
var onConnect = function(client, versionInfo) {
debugLog(`Connected to ElectrumX @ ${host}:${port} (${JSON.stringify(versionInfo)})`);
global.electrumStats.base.connect.count++;
global.electrumStats.base.connect.lastSeenAt = new Date();
if (global.electrumStats.base.connect.firstSeenAt == null) {
global.electrumStats.base.connect.firstSeenAt = new Date();
}
electrumClients.push(client);
resolve();
@ -61,6 +75,13 @@ function connectToServer(host, port, protocol) {
var onClose = function(client) {
debugLog(`Disconnected from ElectrumX @ ${host}:${port}`);
global.electrumStats.base.disconnect.count++;
global.electrumStats.base.disconnect.lastSeenAt = new Date();
if (global.electrumStats.base.disconnect.firstSeenAt == null) {
global.electrumStats.base.disconnect.firstSeenAt = new Date();
}
var index = electrumClients.indexOf(client);
if (index > -1) {
@ -71,6 +92,13 @@ function connectToServer(host, port, protocol) {
var onError = function(err) {
debugLog(`Electrum error: ${JSON.stringify(err)}`);
global.electrumStats.base.error.count++;
global.electrumStats.base.error.lastSeenAt = new Date();
if (global.electrumStats.base.error.firstSeenAt == null) {
global.electrumStats.base.error.firstSeenAt = new Date();
}
utils.logError("937gf47dsyde", err, {host:host, port:port, protocol:protocol});
};
@ -296,18 +324,18 @@ function getAddressBalance(addrScripthash) {
}
function logStats(cmd, dt, success) {
if (!global.electrumStats[cmd]) {
global.electrumStats[cmd] = {count:0, time:0, successes:0, failures:0};
if (!global.electrumStats.rpc[cmd]) {
global.electrumStats.rpc[cmd] = {count:0, time:0, successes:0, failures:0};
}
global.electrumStats[cmd].count++;
global.electrumStats[cmd].time += dt;
global.electrumStats.rpc[cmd].count++;
global.electrumStats.rpc[cmd].time += dt;
if (success) {
global.electrumStats[cmd].successes++;
global.electrumStats.rpc[cmd].successes++;
} else {
global.electrumStats[cmd].failures++;
global.electrumStats.rpc[cmd].failures++;
}
}

31
views/admin.pug

@ -140,7 +140,34 @@ block content
table.table.table-hover.table-striped
thead
tr
th Method
th Action
th.text-right Count
th.text-right First Seen
th.text-right Last Seen
tbody
each item, itemName in electrumStats.base
tr.text-monospace
td #{itemName}
td.text-right #{item.count.toLocaleString()}
if (item.firstSeenAt)
td.text-right #{moment.duration(new Date().getTime() - item.firstSeenAt.getTime()).format()} ago
else
td.text-right -
if (item.lastSeenAt)
td.text-right #{moment.duration(new Date().getTime() - item.lastSeenAt.getTime()).format()} ago
else
td.text-right -
hr
div.table-responsive
table.table.table-hover.table-striped
thead
tr
th RPC
th.text-right Count
th.text-right Time
small (s)
@ -150,7 +177,7 @@ block content
th.text-right Success Rate
tbody
each item, itemName in electrumStats
each item, itemName in electrumStats.rpc
tr.text-monospace
td #{itemName}
td.text-right #{item.count.toLocaleString()}

Loading…
Cancel
Save