Skip to content

Instantly share code, notes, and snippets.

@phiresky
Last active March 30, 2019 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phiresky/f69f35f057163c092e0ddb7099e9a9cf to your computer and use it in GitHub Desktop.
Save phiresky/f69f35f057163c092e0ddb7099e9a9cf to your computer and use it in GitHub Desktop.
fusl script
/node_modules
/charts.json
/stats.json

run:

npm install
./getStats.sh googleplus | parallel .....whatever
#!/usr/bin/env node
require("ts-node/register")
require("./getStats")
import { Stats, Charts } from "./types";
import fetch from "node-fetch";
const project = process.argv[2];
if (!project) throw "no project specified";
console.warn("project:", project);
const startDate = new Date();
startDate.setMinutes(startDate.getMinutes() - 30);
const startTimestamp = startDate.valueOf() / 1000;
const now = new Date();
async function get() {
console.warn("getting stats");
const sres = await fetch(`http://tracker.archiveteam.org/${project}/stats.json`);
if (!sres.ok) throw "failed stats: " + (await sres.text());
const stats: Stats = await sres.json();
const { todo, out, done } = stats.counts;
console.log(
`attrackeritemstates,project=${project}`,
`todo=${todo}i,out=${out}i,done=${done}i`,
now.valueOf() + "000000",
);
console.warn("getting charts");
const cres = await fetch(`http://tracker.archiveteam.org/${project}/charts.json`);
if (!cres.ok) throw "failed charts: " + (await cres.text());
const charts: Charts = await cres.json();
function logValues(header: string, key: string, values: [number, number][]) {
values = values.filter(([ts, _]) => ts > startTimestamp);
for (const [ts, value] of values) {
console.log(header, `${key}=${value}i ${ts}000000000`);
}
}
Object.entries(charts.downloader_chart).map(([downloader, values]) =>
logValues(`attrackercharts,project=${project},downloader=${downloader}`, "bytes", values),
);
logValues(`attrackeritemsx,project=${project}`, "value", charts.items_done_chart);
}
get();
{
"scripts": {
"getStats": "ts-node getStats.ts"
},
"dependencies": {
"@types/node": "^11.12.1",
"@types/node-fetch": "^2.1.7",
"node-fetch": "^2.3.0",
"ts-node": "^8.0.3",
"typescript": "^3.4.1"
},
"prettier": {
"semi": true,
"tabWidth": 4,
"useTabs": true,
"trailingComma": "all",
"printWidth": 100,
"endOfLine": "lf"
}
}
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true
}
}
export type Stats = {
domain_bytes: {
data: 1120905749294131;
};
downloader_bytes: { [name: string]: number };
downloader_count: { [name: string]: number };
downloaders: string[];
total_items_done: 23970782;
total_items: 24422342;
counts: {
todo: 198103;
out: 253457;
done: 23970782;
};
total_items_out: 253457;
total_bytes: 1120905749294131;
};
type ChartData = [number, number][];
export type Charts = {
downloader_chart: { [name: string]: ChartData };
items_done_chart: ChartData;
bytes_done_chart: ChartData;
previous_chart_data_urls: [];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment