# node-simpletsdb

> A Nodejs library for interacting with SimpleTSDB

Latest version **0.0.9** (published 2021-07-29) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install node-simpletsdb
pnpm add node-simpletsdb
yarn add node-simpletsdb
bun add node-simpletsdb
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2021-07-29 |
| First published | 2021-07-27 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.7 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Author | a1c9lll |
| Maintainers | a1c9lll |
| Keywords | simpletsdb |

## Links

- npm: https://www.npmjs.com/package/node-simpletsdb
- Repository: https://github.com/a1c9lll/node-simpletsdb
- Issues: https://github.com/a1c9lll/node-simpletsdb/issues
- npm.io page: https://npm.io/package/node-simpletsdb

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.21.1

## Recent versions

- 0.0.9 (latest) — 2021-07-29
- 0.0.8 — 2021-07-28
- 0.0.7 — 2021-07-28
- 0.0.6 — 2021-07-28
- 0.0.5 — 2021-07-28
- 0.0.4 — 2021-07-27
- 0.0.3 — 2021-07-27
- 0.0.2 — 2021-07-27
- 0.0.1 — 2021-07-27

## README

# node-simpletsdb

## Installation

```
npm install node-simpletsdb
```

## API

#### Object: `SimpleTSDB`

###### Parameters: `options`

`options` has the following properties:

| Field            | Type   | Description                                                        |
|:---------------- |:------:|:------------------------------------------------------------------ |
|`host`            |`string`|The host used to connect to SimpleTSDB                              |
|`port`            |`number`|The port used to connect to SimpleTSDB                              |
|`insertBufferSize`|`number`|_optional:_ The buffer size used by insertPoints. Defaults to 65536.|

###### Example:

```javascript
const { SimpleTSDB } = require('node-simpletsdb');

const db = new SimpleTSDB({
  host: '127.0.0.1',
  port: 8981,
});
```

#### Object: `Point`

###### Parameters: `options`

`options` has the following properties:

| Field     | Type   | Description                                           |
|:--------- |:------:|:----------------------------------------------------- |
|`metric`   |`string`|The metric name of the  point                          |
|`value`    |`number`|The value of the point                                 |
|`timestamp`|`number`|The timestamp of the point                             |
|`tags`     |`array` |_optional_: The tags associated with the inserted point|

###### Example:

```javascript
const { Point } = require('node-simpletsdb');

const pt = new Point({
  metric: 'test0',
  value: 99,
  timestamp: Date.now() * 1000000, // SimpleTSDB uses nanoseconds
  tags: {
    'id': '2',
  }
});
```

#### Function: `insertPoint`

###### Parameters: `point`

###### Example:

```javascript
db.insertPoint(new Point({
  metric: 'test0',
  value: 99,
  tags: {
    'id': '2',
  },
  timestamp: Date.now() * 1000000, // SimpleTSDB uses nanoseconds
}))
  .then(() => console.log('successfully inserted point'))
  .catch(err => console.error(err));
```

#### Function: `insertPoints`

###### Parameters: `points`

The same as `insertPoint` but takes an array of points.

#### Function: `queryPoints`

###### Parameters: `query`

`query` has the following properties:

| Field       | Type   | Description                                                      |
|:----------- |:------:|:---------------------------------------------------------------- |
|`metric`     |`string`|The metric to query.                                              |
|`start`      |`number`|The timestamp in nanoseconds for the start of the query.          |
|`end`        |`number`|_optional:_ The timestamp in nanoseconds for the end of the query.|
|`n`          |`number`|_optional:_ The max number of points to return.                   |
|`tags`       |`object`|_optional:_ Key/value pairs to add criteria to the query.         |
|`window`     |`object`|_optional:_ Windowing options. See [Windowing / Gap filling](https://github.com/a1c9lll/SimpleTSDB/#windowing--gap-filling)                                   |
|`aggregators`|`array` |_optional:_ An array of aggregators. See [aggregators](https://github.com/a1c9lll/SimpleTSDB/#aggregators)                              |

###### Example:

```javascript
db.queryPoints({
  metric: 'test0',
  start: (Date.now() - 360000) * 1000000, // SimpleTSDB uses nanoseconds
  window: {
    every: '1m',
  }
})
  .then(points => console.log(points))
  .catch(err => console.error(err));
```

#### Function: `deletePoints`

###### Parameters: `options`

`options` has the following properties:

| Field       | Type   | Description                                                      |
|:----------- |:------:|:---------------------------------------------------------------- |
|`metric`     |`string`|The metric to query.                                              |
|`start`      |`number`|The timestamp in nanoseconds for the start of the query.          |
|`end`        |`number`|The timestamp in nanoseconds for the end of the query.            |
|`tags`       |`object`|_optional:_ Key/value pairs to add criteria to the query.         |

###### Example:

```javascript
db.deletePoints({
  metric: 'test0',
  start: (Date.now() - 36000) * 1000000, // SimpleTSDB uses nanoseconds
  end: Date.now() * 1000000
})
  .then(() => console.log('successfully deleted points'))
  .catch(err => console.error(err));
```

## TODO

Add some sort of time library to make working with timestamps easier.

---
_Source: https://npm.io/package/node-simpletsdb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
