Last active
December 9, 2023 19:01
-
-
Save thosmos/27b1fd6bfbdf0c5a95d42d1b62857df1 to your computer and use it in GitHub Desktop.
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
const START = process.env.START || "2022-01-01" | |
const END = process.env.END || "2023-01-01" | |
/* | |
On Mac OS zsh Call like: | |
ssh j11 "PASS=`grep dashboard_password /etc/rita.toml | tr -d '\"' | sed \"s/rita_dashboard_password = //\"`; curl -u rita:$PASS localhost:4877/usage/client" | node process-usage.js | |
In bash, call like: | |
export START=2023-01-01; export END=2024-01-01; ssh treelink 'PASS=`grep dashboard_password /etc/rita.toml | tr -d \" | sed "s/rita_dashboard_password = //"`; curl -u rita:$PASS localhost:4877/usage/client' | node process-usage.js | |
*/ | |
function getUnixHours(dateStr) { | |
const dt = new Date(Date.parse(dateStr)) | |
const dtUTCms = dt.getTime() + (dt.getTimezoneOffset() * 60 * 1000) | |
return Math.round(dtUTCms / (1000 * 60 * 60)) | |
} | |
const start = getUnixHours(START) | |
const end = getUnixHours(END) | |
let datas = "" | |
process.stdin.on('data', data => { | |
datas += data.toString() | |
}); | |
let upT = 0 | |
let downT = 0 | |
let costT = 0 | |
process.stdin.on('end', () => { | |
let usages = JSON.parse(datas) | |
usages.forEach(({index, up, down, price}) => { | |
if (index >= start && index < end ) { | |
let u = up / 1000000000 | |
let c = u * (price / 1000000000) | |
upT += u | |
costT += c | |
let d = down / 1000000000 | |
c = d * (price / 1000000000) | |
downT += d | |
costT += c | |
} | |
}) | |
console.log("START", START, "END", END, "UP",upT.toFixed(2),"DOWN", downT.toFixed(2), "TOTAL", (upT + downT).toFixed(2), "COST", costT.toFixed(2)) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment