Haris Razis
4 years ago
8 changed files with 57 additions and 58 deletions
Before Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,32 @@ |
|||
import { InfluxDB, QueryApi } from '@influxdata/influxdb-client'; |
|||
|
|||
export class Query { |
|||
private client!: InfluxDB; |
|||
private queryApi!: QueryApi; |
|||
|
|||
constructor() { |
|||
this.initDatabase(); |
|||
} |
|||
|
|||
private initDatabase(): void { |
|||
this.client = new InfluxDB({ |
|||
url: process.env.VUE_APP_DB_URL!, |
|||
token: process.env.VUE_APP_DB_TOKEN!, |
|||
}); |
|||
this.queryApi = this.client.getQueryApi(process.env.VUE_APP_DB_ORG!); |
|||
} |
|||
|
|||
async query(filter: string) { |
|||
const query = `from(bucket: "${process.env.VUE_APP_DB_BUCKET}") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "${filter}") |> aggregateWindow(every: 10m, fn: mean)`; |
|||
|
|||
try { |
|||
const data = await this.queryApi.collectRows(query); |
|||
console.log('\nCollect ROWS SUCCESS'); |
|||
return data; |
|||
} catch (error) { |
|||
console.error(error); |
|||
console.log('\nCollect ROWS ERROR'); |
|||
return [{ Error: 'Error occured' }]; |
|||
} |
|||
} |
|||
} |
Before Width: | Height: | Size: 6.7 KiB |
Loading…
Reference in new issue