-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: queryPoints * fix: construct Point with relevant types * style: linted * feat: Point field types, getField * feat: Point.fields, PointRecord removed * docs: readme for queryPoints * test: structured query tests * fix: getField, queryPoints * docs: fix README lint, env variables * test: InfluxDBClient argument options * docs: changelog * fix: md linter disable MD024 * fix: query Points without metadata * feat: PointValues object (first iteration) * refactor: PointValues query, private Point cons * refactor: reworked Point api * fix: renaming error * docs: Point values comments * refactor: rename int to integer * feat: fromValues throws when measurement missing * docs: Point comments * feat: downsampling example * fix: minor fixes * docs: use set instead of add * docs: fix * fix: apidoc * docs: correct name for type * docs: add documentation * fix: correct field name * chore: test converting point values to point * fix: code style * chore: test point values * chore: test point values * chore: test point values * chore: test point values * chore: simplify queryPoints * fix: tests * chore: test point * chore: test point * chore: test aggregation * chore: test aggregation * feat: use separate directory for downsampling data * feat: use separate directory for downsampling data * feat: use separate directory for downsampling data * feat: use separate directory for downsampling data --------- Co-authored-by: Jakub Bednar <[email protected]>
- Loading branch information
Showing
24 changed files
with
2,181 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"MD013": false, | ||
"MD024": false, | ||
"MD033": { | ||
"allowed_elements": [ "a", "img", "p", "details", "summary" ] | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## Downsampling Example | ||
|
||
- [index.ts](./src/index.ts) - How to use queries to structure data for downsampling | ||
|
||
## prerequisites | ||
|
||
- `node` and `yarn` installed | ||
|
||
- build influxdb-client: *(in project root directory)* | ||
- run `yarn install` | ||
- run `yarn build` | ||
|
||
## Usage | ||
|
||
set environment variables. | ||
|
||
- `INFLUXDB_URL` region of your influxdb cloud e.g. *`https://us-east-1-1.aws.cloud2.influxdata.com/`* | ||
- `INFLUXDB_TOKEN` read/write token generated in cloud | ||
- `INFLUXDB_DATABASE` name of database e.g .*`my-database`* | ||
|
||
For simplicity, you can use dotenv library to load environment variables in this example. Create `.env` file and paste your variables as follows: | ||
|
||
```conf | ||
INFLUXDB_URL="<url>" | ||
INFLUXDB_DATABASE="<database>" | ||
INFLUXDB_TOKEN="<token>" | ||
``` | ||
|
||
### Run example | ||
|
||
- run `yarn install` | ||
- run `yarn dev` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "influxdb3-client-example-downsampling", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"dev": "ts-node -r dotenv/config ./src/index.ts" | ||
}, | ||
"dependencies": { | ||
"@influxdata/influxdb3-client": "link:../../packages/client" | ||
}, | ||
"devDependencies": { | ||
"dotenv": "^16.3.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.1.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import {InfluxDBClient} from '@influxdata/influxdb3-client' | ||
|
||
/* get environment value or throw error if missing */ | ||
const getEnv = (variableName: string): string => { | ||
if (process.env[variableName] == null) | ||
throw new Error(`missing ${variableName} environment variable`) | ||
return process.env[variableName] as string | ||
} | ||
|
||
/* eslint-disable no-console */ | ||
async function main() { | ||
// | ||
// Use environment variables to initialize client | ||
// | ||
const host = getEnv('INFLUXDB_URL') | ||
const token = getEnv('INFLUXDB_TOKEN') | ||
const database = getEnv('INFLUXDB_DATABASE') | ||
|
||
// | ||
// Create a new client using an InfluxDB server base URL and an authentication token | ||
// | ||
const client = new InfluxDBClient({host, token, database}) | ||
|
||
try { | ||
// | ||
// Write data | ||
// | ||
await client.write(`stat,unit=temperature avg=24.5,max=45.0`) | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)) | ||
await client.write(`stat,unit=temperature avg=28,max=40.3`) | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)) | ||
await client.write(`stat,unit=temperature avg=20.5,max=49.0`) | ||
|
||
// | ||
// Query downsampled data | ||
// | ||
const downSamplingQuery = `\ | ||
SELECT | ||
date_bin('5 minutes', "time") as window_start, | ||
AVG("avg") as avg, | ||
MAX("max") as max | ||
FROM "stat" | ||
WHERE | ||
"time" >= now() - interval '1 hour' | ||
GROUP BY window_start | ||
ORDER BY window_start ASC;` | ||
|
||
// | ||
// Execute downsampling query into pointValues | ||
// | ||
const queryPointsResult = client.queryPoints( | ||
downSamplingQuery, | ||
database, | ||
'sql' | ||
) | ||
|
||
for await (const row of queryPointsResult) { | ||
const timestamp = new Date(row.getFloatField('window_start') as number) | ||
console.log( | ||
`${timestamp.toISOString()}: avg is ${row.getField( | ||
'avg', | ||
'float' | ||
)}, max is ${row.getField('max', 'float')}` | ||
) | ||
|
||
// | ||
// write back downsampled date to 'stat_downsampled' measurement | ||
// | ||
const downSampledPoint = row | ||
.asPoint('stat_downsampled') | ||
.setTimestamp(timestamp) | ||
|
||
await client.write(downSampledPoint, database) | ||
} | ||
} catch (err) { | ||
console.error(err) | ||
} finally { | ||
await client.close() | ||
} | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2018", | ||
"lib": ["es2018"], | ||
"strict": true, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true | ||
}, | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["*.js"] | ||
} |
Oops, something went wrong.