rrdtool
Version:
A simple wrapper around RRDTool
68 lines (54 loc) • 1.55 kB
JavaScript
import Queue from 'p-queue'
import { now } from './util.js'
import * as proc from './proc.js'
export default class DB {
constructor (file, info) {
this.
this.
}
static async open (file) {
const info = await proc.info(file)
return new DB(file, info)
}
static async create (file, opts, args) {
await proc.create(file, opts, args)
const info = await proc.info(file)
return new DB(file, info)
}
/** `ts` is optional and defaults to 'N' */
update (ts, values) {
if (arguments.length === 1) {
values = ts
ts = now()
}
return this.
const ds = this.
const unknown = Object.keys(values).map((name) => {
const matching = ds.filter((ds) => ds.name === name)
return (matching.length === 1 ? null : name)
}).filter(Boolean)
if (unknown.length > 0) {
if (unknown.length === 1) {
throw new Error('Unknown data source: ' + unknown[0])
} else {
throw new Error('Unknown data sources: ' + unknown.join(', '))
}
}
await proc.update(this.
})
}
/** `res` is optional and defaults to highest possible */
fetch (cf, start, stop, res) {
return this.
return await proc.fetch(this.
})
}
_dump () {
return this.
return await proc.dump(this.
})
}
}