Searching.ton
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.8 KiB

2 years ago
import { fluxDuration, InfluxDB } from "@influxdata/influxdb-client"
import { Point } from "@influxdata/influxdb-client"
import { influxBucket, influxHost, influxOrg, influxPointName, influxToken } from "./constants"
import { influxQuery, processInfluxResult } from "./helpers"
2 years ago
import { InfluxField, InfluxPeriod } from "./types"
interface WriteSitesCounteParams {
all: number
available: number
2 years ago
}
interface QueryParams {
field: InfluxField
period: InfluxPeriod
2 years ago
}
class InfluxDb {
private client: InfluxDB
constructor() {
this.client = new InfluxDB({ url: process.env.INFLUX_URL as string, token: influxToken })
}
getWriteApi() {
const writeApi = this.client.getWriteApi(influxOrg, influxBucket)
writeApi.useDefaultTags({ host: influxHost })
return writeApi
}
writeSitesCount({ all, available }: WriteSitesCounteParams) {
return
/*const writeApi = this.getWriteApi()
const pointAll = new Point(influxPointName).intField(InfluxField.ALL_SITES, all)
const pointAvailable = new Point(influxPointName).intField(
InfluxField.AVAILABLE_SITES,
available
)
2 years ago
writeApi.writePoint(pointAll)
writeApi.writePoint(pointAvailable)
writeApi.close() */
2 years ago
}
async query({ field, period }: QueryParams) {
return []
/* const queryApi = this.client.getQueryApi(influxOrg)
2 years ago
const query = influxQuery(field, period)
2 years ago
const result = await queryApi.collectRows(query)
return processInfluxResult(result); */
2 years ago
}
async getHistoryOfState(period: InfluxPeriod) {
return { all: [], available: [] }
/* const all = await this.query({
field: InfluxField.ALL_SITES,
period,
})
const available = await this.query({
field: InfluxField.AVAILABLE_SITES,
period,
2 years ago
})
return {
all,
available,
} */
2 years ago
}
}
export default new InfluxDb()