问题描述
我正在一个项目中,我有一个InfluxDB存储桶,该存储桶的度量值为elapsedtime
,标签为service
。我想查询Influx,以便能够在最近1小时内获得foobar
作为服务的所有数据点。理想情况下,稍后我将添加一个时间度量,我可以以此为基础来休假1个小时,因为获取经过时间的系统和将其写入Influx的系统是不同的,并且它们之间的等待时间约为1-2分钟。 / p>
我从here中获取了一些示例代码,由于我不确定需要更改什么并且无法理解文档(头昏了头脑),我得到了几乎相同的代码。
此操作的最终目标是能够有一个图表,在我查询应用程序时显示服务的elapsedtime
-查询Influx。我希望能够根据服务和时间的预设列表进行查询,但这是应用程序的方面,在这里我将作为最终结果的参考。
...
variables that define bucket,url,org and token
...
const queryApi = new InfluxDB({url,token}).getQueryApi(org)
const fluxQuery =
`from(bucket:"${bucket}") |> range(start: 0) |> filter(fn: (r) => r._measurement == "elapsedtime")`
console.log('*** QUERY ROWS ***')
// Execute query and receive table Metadata and rows.
// https://v2.docs.influxdata.com/v2.0/reference/Syntax/annotated-csv/
queryApi.queryRows(fluxQuery,{
next(row: string[],tableMeta: FluxTableMetaData) {
const o = tableMeta.toObject(row)
console.log(
`${o._time} ${o._measurement} in '${o.location}' (${o.example}): ${o._field}=${o._value}`
)
},error(error: Error) {
console.error(error)
},complete() {
console.log('\nFinished SUCCESS')
},})
运行此命令时,我会收到一个有关附加值的错误消息,但是我希望示例中的代码正确,因此也许我缺少了需要更新的内容?
next(row: string[],tableMeta: FluxTableMetaData) {
^
SyntaxError: Unexpected token ':'
at wrapSafe (internal/modules/cjs/loader.js:992:16)
at Module._compile (internal/modules/cjs/loader.js:1040:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:941:32)
at Function.Module._load (internal/modules/cjs/loader.js:782:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
解决方法
问题最终是我复制的代码是TypeScript,您可以想象它在JavaScript文件中不起作用。我的愚蠢错误