Haris Razis
4 years ago
1 changed files with 0 additions and 32 deletions
@ -1,32 +0,0 @@ |
|||
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' }]; |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue