【问题标题】:Lambda function only putting one data point into InfluxDBLambda 函数只将一个数据点放入 InfluxDB
【发布时间】:2020-07-11 16:01:57
【问题描述】:

我有一个 Lambda 函数,旨在从 SQS 队列中获取消息,然后输入一个名为 perf_value 的值,它只是一个整数。 CloudWatch 日志显示它每次触发并记录Done,如我的写入点的.then() 块中所示。每次触发时,我仍然只能在 InfluxDB Cloud 中看到一个数据点。我不知道为什么它只输入一个值,然后什么都没有。我在 SQS 中没有看到积压,在 CloudWatch 中也没有错误消息。我猜这是代码问题或 InfluxDB Cloud 设置,尽管我使用了您希望实际适用于多个数据点的默认值

'use strict';

const {InfluxDB, Point, HttpError} = require('@influxdata/influxdb-client')

const InfluxURL = 'https://us-west-2-1.aws.cloud2.influxdata.com'
const token = '<my token>=='
const org = '<my org>'
const bucket= '<bucket name>'

const writeApi = new InfluxDB({url: InfluxURL, token}).getWriteApi(org, bucket, 'ms')

module.exports.perf = function (event, context, callback) {
  context.callbackWaitsForEmptyEventLoop = false;

  let input = JSON.parse(event.Records[0].body);
  console.log(input)

  const point = new Point('elapsedTime')
    .tag(input.monitorID, 'monitorID')
    .floatField('elapsedTime', input.perf_value)
    // .timestamp(input.time)
  writeApi.writePoint(point)
  writeApi
  .close()
  .then(() => {
    console.log('Done')
  })
  .catch(e => {
    console.error(e)
    if (e instanceof HttpError && e.statusCode === 401) {
      console.log('Unauthorized request')
    }
    console.log('\nFinished ERROR')
  })

  return true
};

编辑** 仍然无法解决问题。我可以让一个数据点进入 influxdb,然后什么都不会显示。

【问题讨论】:

    标签: node.js aws-lambda influxdb influxdb-2


    【解决方案1】:

    @Joshk132 -

    我相信问题出在这里:

    writeApi
      .close() // <-- here
      .then(() => {
        console.log('Done')
      })
    

    您将在第一次写入后关闭 API 客户端对象,因此您只能写入一次。如果您想立即强制发送 Point,可以改用flush()

    【讨论】:

      猜你喜欢
      • 2021-01-26
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      • 1970-01-01
      • 2022-06-17
      • 2018-09-19
      相关资源
      最近更新 更多