diff --git a/metrics.js b/metrics.js new file mode 100644 index 0000000..6398e9b --- /dev/null +++ b/metrics.js @@ -0,0 +1,37 @@ +const fs = require('fs-extra'); +const path = require('path'); +const { formatBytes } = require('./utils'); + +module.exports = () => { + let data = fs.readJsonSync(path.join(__dirname, 'data.json')); + let { users } = fs.readJsonSync(path.join(__dirname, 'auth.json')); + + let totalSize = 0; + let oldSize = 0; + Object.values(data).forEach(({ token, size }) => { + try { + totalSize += size; + if (token == null) oldSize += size; + else { + if (!users[token].size) users[token].size = 0; + users[token].size += size; + } + } catch (ex) { + // Silently handle missing tokens from dev environment -tycrek + } + }); + + console.log('---- Usage metrics ----\n'); + console.log(`Users: ${Object.keys(users).length}`); + console.log(`Files: ${Object.keys(data).length}`); + console.log(''); + console.log(`Total size: ${formatBytes(totalSize)}`); + console.log(`Untracked size: ${formatBytes(oldSize)}`); + console.log(''); + + Object.values(users).forEach(({ username, count, size }) => { + console.log(`- ${username}: ${formatBytes(size)} (${count} files)`); + }); +} + +if (require.main === module) module.exports(); diff --git a/package.json b/package.json index 7051386..567a77f 100755 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "start": "node ass.js", "setup": "node setup.js", + "metrics": "node metrics.js", "new-token": "node generators/token.js", "test": "echo \"Error: no test specified\" && exit 1" }, @@ -35,4 +36,4 @@ "prompt": "^1.1.0", "uuid": "^8.3.2" } -} +} \ No newline at end of file