Skip to content

Instantly share code, notes, and snippets.

@cyberbutler
Last active July 27, 2022 19:29
Show Gist options
  • Save cyberbutler/4e6b71e26f88535c05419fc25b7a6897 to your computer and use it in GitHub Desktop.
Save cyberbutler/4e6b71e26f88535c05419fc25b7a6897 to your computer and use it in GitHub Desktop.
const redis = require("redis");
const fs = require('fs');
const redisMonitor = redis.createClient({
host: "portal.hackazon.org",
port: 17011
})
redisMonitor.monitor(function (err, res) {
console.log("Entering monitoring mode.");
});
writes = {}
redisMonitor.on("monitor", function (time, args, rawReply) {
// On Montior events
writeKeys = Object.keys(writes)
try {
// Attempt to:
// Parse the 4th argument as JSON
const data = JSON.parse(args[3])
// Add the time argument to the object
data['time'] = parseFloat(time)
if (writeKeys.includes(args[1])) {
// If the Key is already found in the output object
// append the data to its sub-array
writes[args[1]].push(data)
} else {
// Else create the object key and assign a sub array with the data as its sole element
writes[args[1]] = [data]
}
} catch (error) {
// If unable to parse properly, throw an error.
console.log(args, error)
}
// Write the output on a single line, showing the number of unique keys we\'ve seen writes to so far.
process.stdout.write("Total Unique Keys: " + writeKeys.length + "\r")
});
function saveWrites() {
// Write the object as JSON to output.json
fs.writeFileSync("output.json", JSON.stringify(writes))
}
process.on("SIGINT", () => {
// Capture CTRL^C event and save the output to the output.json file.
console.log(writes)
saveWrites()
process.exit();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment