async function main() {
const url = "https://coderbyte.com/api/challenges/logs/web-logs-raw";
// Fetch logs
const response = await fetch(url);
const logs = await response.text();
// Prepare accumulators
const totals: Record<string, number> = {};
const counts: Record<string, number> = {};
// Process each line
for (const line of logs.split("\n")) {
if (!line.includes("coderbyte heroku/router")) continue;
// Extract dyno, connect, and service values
const dynoMatch = line.match(/dyno=([\w.-]+)/);
const connectMatch = line.match(/connect=(\d+)ms/);
const serviceMatch = line.match(/service=(\d+)ms/);
if (dynoMatch && connectMatch && serviceMatch) {
const dyno = dynoMatch[1];
const connect = parseInt(connectMatch[1], 10);
const service = parseInt(serviceMatch[1], 10);
const total = connect + service;
// Aggregate totals
totals[dyno] = (totals[dyno] || 0) + total;
counts[dyno] = (counts[dyno] || 0) + 1;
}
}
// Compute and display averages
for (const dyno of Object.keys(totals)) {
const avg = Math.round(totals[dyno] / counts[dyno]);
console.log(`${dyno}: ${avg}ms`);
}
}
main().catch(console.error);
Created
November 4, 2025 20:05
-
-
Save alyatwa/b8f1035a08119f947a332ace1d184558 to your computer and use it in GitHub Desktop.
coderbyte solution bash parser
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment