|
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(); |