Skip to content

Instantly share code, notes, and snippets.

@juliangruber
Last active May 14, 2024 21:51
Show Gist options
  • Save juliangruber/cd50f1227d08e8b94d6b4b36620b4711 to your computer and use it in GitHub Desktop.
Save juliangruber/cd50f1227d08e8b94d6b4b36620b4711 to your computer and use it in GitHub Desktop.
import { InfluxDB } from '@influxdata/influxdb-client'
const client = new InfluxDB({
url: 'https://eu-central-1-1.aws.cloud2.influxdata.com',
token: process.env.INFLUX_TOKEN, // julian-station-read
timeout: 5 * 60 * 1000
})
const queryApi = client.getQueryApi('Filecoin Station')
const query = `
from(bucket:"station")
|> range(start: 0, stop: 2024-05-01T00:00:00Z)
`
const counts = {
rows: 0,
jobs: 0
}
const status = () => console.error(new Date(), counts)
setInterval(status, 1000).unref()
queryApi.queryRows(query, {
next (row, tableMeta) {
const obj = tableMeta.toObject(row)
delete obj.url
delete obj.host
delete obj._start
delete obj._stop
delete obj.table
counts.rows++
if (obj._measurement === 'jobs-completed' && obj._field === 'value') {
counts.jobs += obj._value
}
console.log(JSON.stringify(obj))
},
error: console.error,
complete: status
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment