Skip to content

Commit 1b62051

Browse files
committed
Added consensus and execution peer counts to rpc check in
1 parent 944da6c commit 1b62051

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

https_connection/httpsConnection.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import {
99
} from "../getSystemStats.js";
1010
import { localClient } from "../monitor_components/viemClients.js";
1111
import { installDir } from "../commandLineOptions.js";
12+
import {
13+
getConsensusPeers,
14+
getExecutionPeers,
15+
} from "../monitor_components/peerCountGauge.js";
1216

1317
export let checkIn;
1418

@@ -91,6 +95,12 @@ export function initializeHttpConnection(httpConfig) {
9195
const memoryUsage = await getMemoryUsage();
9296
const diskUsage = await getDiskUsage(installDir);
9397
const macAddress = await getMacAddress();
98+
const executionPeers = await getExecutionPeers(
99+
httpConfig.executionClient
100+
);
101+
const consensusPeers = await getConsensusPeers(
102+
httpConfig.consensusClient
103+
);
94104

95105
const params = new URLSearchParams({
96106
id: `${os.hostname()}-${macAddress}-${os.platform()}-${os.arch()}`,
@@ -102,6 +112,8 @@ export function initializeHttpConnection(httpConfig) {
102112
storage_usage: `${diskUsage}`,
103113
block_number: possibleBlockNumber ? possibleBlockNumber.toString() : "",
104114
block_hash: possibleBlockHash ? possibleBlockHash : "",
115+
execution_peers: executionPeers,
116+
consensus_peers: consensusPeers,
105117
});
106118

107119
const options = {
@@ -118,6 +130,7 @@ export function initializeHttpConnection(httpConfig) {
118130
});
119131
res.on("end", () => {
120132
debugToFile(`Checkin response: ${data}`, () => {});
133+
debugToFile(`Response status: ${res.statusCode}`, () => {});
121134
});
122135
});
123136

monitor_components/peerCountGauge.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function createPeerCountGauge(grid, screen) {
3131

3232
//
3333

34-
async function getExecutionPeers() {
34+
export async function getExecutionPeers() {
3535
try {
3636
const peerCountHex = await localClient.request({
3737
method: "net_peerCount",
@@ -45,28 +45,20 @@ async function getExecutionPeers() {
4545
}
4646
}
4747

48-
async function getConsensusPeers(consensusClient) {
49-
// debugToFile(
50-
// `getConsensusPeers() consensusClient: ${consensusClient}`,
51-
// () => {}
52-
// );
53-
48+
export async function getConsensusPeers(consensusClient) {
5449
let searchString;
5550
if (consensusClient == "prysm") {
5651
searchString = 'p2p_peer_count{state="Connected"}';
5752
} else if (consensusClient == "lighthouse") {
5853
searchString = "libp2p_peers";
5954
}
60-
return new Promise((resolve, reject) => {
55+
return new Promise((resolve) => {
6156
exec(
6257
`curl -s http://localhost:5054/metrics | grep -E '^${searchString} '`,
6358
(error, stdout, stderr) => {
64-
if (error) {
65-
return reject(error);
66-
}
67-
if (stderr) {
68-
debugToFile(`getConsensusPeers(): ${stderr}`, () => {});
69-
return reject(new Error(stderr));
59+
if (error || stderr) {
60+
// debugToFile(`getConsensusPeers(): ${error || stderr}`, () => {});
61+
return resolve(null);
7062
}
7163

7264
const parts = stdout.trim().split(" ");

0 commit comments

Comments
 (0)