rrdtool.ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

rrdtool.ts

This is a wrapper for rrdtool written in TypeScript. Inspired by the rrdtool NPM package https://github.com/LinusU/node-rrdtool.

Usage

import rrdtool from "rrdtool.ts";

interface MyData {
  test: number;
};

const start = rrdtool.now() - 10;
const db = await rrdtool.create<MyData>("test.rrd", { start, step: 1 }, [
  "DS:test:GAUGE:1:0:100",
  "RRA:AVERAGE:0.5:1:10"
]);

db.update({ test: 15 }, { timestamp: start + 0 });
db.update({ test: 90 }, { timestamp: start + 1 });
db.update({ test: 35 }, { timestamp: start + 2 });
db.update({ test: 45 }, { timestamp: start + 3 });
db.update({ test: 85 }, { timestamp: start + 4 });
db.update({ test: 10 }, { timestamp: start + 5 });
db.update({ test: 60 }, { timestamp: start + 6 });
db.update({ test: 55 }, { timestamp: start + 7 });
db.update({ test: 75 }, { timestamp: start + 8 });
db.update({ test: 25 }, { timestamp: start + 9 });

const data = await db.fetch("AVERAGE", { start, end: start + 9});
const info = await db.info();
const graphInfo = await rrdtool.graph([
  "DEF:mydef=test.rrd:test:AVERAGE",
  "LINE2:mydef",
  "VDEF:myvdef=mydef,MAXIMUM",
  "PRINT:myvdef:Maximum\\: %6.2lf",
], {
  filename: "test.png",
  verbose: true,
  image: {
    width: 500,
    height: 300,
    backgroundColor: [10, 10, 10],
  },
  border: 3,
  x: {
    start,
    end: start + 20,
  },
  y: {
    label: "My vertical label",
  },
  text: {
    color: [255, 0, 255],
    defaultFont: 10,
  },
  grid: {
    axisColor: [0, 0, 255],
    arrowColor: [0, 255, 0],
    baseColor: [150, 150, 150],
    majorColor: [50, 50, 50],
  },
  graph: {
    canvasColor: [255, 255, 255],
  },
  title: {
    text: "My title",
    font: 20,
  },
  watermark: "My watermark",
});

API

rrdtool

create<D>(filename: string, definitions: RrdtoolDefinition[], options?: RrdToolCreateOptions): Promise<RrdtoolDatabase<D>>

Creates a new database.

open<D>(filename: string): RrdtoolDatabase<D>

Loads an existing database.

  • filename: Path to the db

graph(definitions: string[], options?: RrdToolGraphOptions): Promise<RrdToolGraphInfo>

Creates a new database.

now()

Returns the current unix timestamp

RrdtoolDatabase

.update(values: Partial<D>, options?: RrdToolUpdateOptions

Insert data into the database.

.fetch(cf: ConsolidationFunction, options?: RrdToolFetchOptions): Promise<RrdtoolDatapoint<D>[]>

Fetch data from the database.

.info(): Promise<RrdtoolInfo[]> and .dump(): Promise<string>

Get various data from database. See https://oss.oetiker.ch/rrdtool/doc/rrdinfo.en.html and https://oss.oetiker.ch/rrdtool/doc/rrddump.en.html

Package Sidebar

Install

npm i rrdtool.ts

Weekly Downloads

1

Version

1.0.1

License

none

Unpacked Size

21.8 kB

Total Files

12

Last publish

Collaborators

  • filiptypjeu