forked from AleoNet/snarkOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
# Get the directory of the bash script | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
# Navigate to the directory containing the JavaScript program | ||
cd "$SCRIPT_DIR/analytics" | ||
|
||
# Check if the 'node_modules' directory exists | ||
if [ ! -d "node_modules" ]; then | ||
echo "Node.js dependencies not found. Running 'npm install'..." | ||
npm install | ||
else | ||
echo "Node.js dependencies already installed." | ||
fi | ||
|
||
# Call the JavaScript program using Node.js | ||
npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const fs = require('fs'); | ||
const axios = require('axios'); | ||
|
||
// Read the ~/.ssh/config file | ||
const sshConfigFile = fs.readFileSync(`${process.env.HOME}/.ssh/config`, 'utf8'); | ||
|
||
// Define the AWS node name to search for (e.g., aws-n0) | ||
const awsNodeName = 'aws-n0'; | ||
|
||
// Use regular expressions to extract the IP address associated with aws-n0 | ||
const regex = new RegExp(`Host\\s+${awsNodeName}[\\s\\S]*?HostName\\s+(\\S+)`); | ||
const match = sshConfigFile.match(regex); | ||
|
||
if (match && match[1]) { | ||
const ipAddress = match[1]; | ||
const baseUrl = `http://${ipAddress}:3033/testnet3/block`; | ||
|
||
console.log(`IP Address: ${ipAddress}`); | ||
console.log(`Base URL: ${baseUrl}`); | ||
|
||
// Function to get the latest block height | ||
async function getLatestBlockHeight() { | ||
try { | ||
const response = await axios.get(`${baseUrl}/height/latest`); | ||
const latestHeight = response.data; | ||
console.log(`Latest Block Height: ${latestHeight}`); | ||
return latestHeight; | ||
} catch (error) { | ||
console.error('Error fetching latest block height:', error.message); | ||
return null; | ||
} | ||
} | ||
|
||
// Function to calculate the average block time | ||
async function calculateAverageBlockTime() { | ||
const latestHeight = await getLatestBlockHeight(); | ||
if (latestHeight === null) { | ||
return; | ||
} | ||
|
||
let totalBlockTime = 0; | ||
let previousTimestamp = 0; | ||
|
||
for (let height = 1; height <= latestHeight; height++) { | ||
// Print the current height every 10 blocks | ||
if (height % 10 === 0) { | ||
console.log(`Processed ${height} blocks...`); | ||
} | ||
|
||
try { | ||
const response = await axios.get(`${baseUrl}/${height}`); | ||
const timestamp = response.data.header.metadata.timestamp; | ||
|
||
if (timestamp && timestamp > 0) { | ||
if (previousTimestamp > 0) { | ||
const deltaTimestamp = timestamp - previousTimestamp; | ||
console.log(`Block ${height} Delta Timestamp: ${deltaTimestamp}`); | ||
totalBlockTime += deltaTimestamp; | ||
} | ||
previousTimestamp = timestamp; | ||
} | ||
} catch (error) { | ||
console.error(`Error fetching block at height ${height}:`, error.message); | ||
} | ||
} | ||
|
||
const averageBlockTime = totalBlockTime / (latestHeight - 1); // Subtract 1 for the first block | ||
console.log(`Average Block Time: ${averageBlockTime} seconds`); | ||
} | ||
|
||
// Calculate and output the average block time | ||
calculateAverageBlockTime(); | ||
} else { | ||
console.error(`No IP address found for ${awsNodeName} in ~/.ssh/config`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "analytics", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "analytics.js", | ||
"scripts": { | ||
"start": "node analytics.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "The Aleo Team", | ||
"license": "Apache 2.0", | ||
"dependencies": { | ||
"axios": "^1.5.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ wasm/Cargo.lock | |
validator-* | ||
**.bft-storage-*/ | ||
**proptest-regressions/ | ||
**package-lock.json | ||
**node_modules/ |