如何发布数据,包括使用libcurl(用于InfuxDB)的线路中断
How to post data including a line break with libcurl (for Influxdb)?
我在C 中使用libcurl
向influxdb发布数据。单个数据点正在起作用,但是对于多个点,我在influxdb http api中定义的必要线路破解( n(苦苦挣扎:
通过通过新行分开每个点,用一个请求写几个点。
用 @ flag从文件中写入点。该文件应以行协议格式包含一批点。各个点必须在自己的线上,并由新线字符( n(隔开。包含运输退货的文件将导致解析器错误。
我想这可能是炭格式的问题,但是我不知道为什么?以下代码仅在距离上写入5个,但应该写两个距离。
#include "stdafx.h"
#include "tchar.h"
#include <string>
#include <curlcurl.h>
#include <sstream>
int main()
{
int dataPoints[] = { 3, 5 };
std::string fieldIdentifier = "distance";
std::stringstream ss;
for (int i = 0; i < 1; i++) {
ss << "aufbau1,ort=halle ";
ss << fieldIdentifier;
ss << "=" << dataPoints[i];
ss << std::endl; //I guess this is the problem, it adds n
}
ss << "aufbau1,ort=halle ";
ss << fieldIdentifier;
ss << "=" << dataPoints[1];
std::string data = ss.str();
const char *dataChar = data.c_str();
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://myIP:8086/write?db=testdb&u=myUser&p=myPwd");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, dataChar);
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %sn",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
return 0;
}
在python中具有 <br>
html标记,在标签/字段值中似乎像是一个线破裂,同时在格拉法纳(Grafana(查看此数据。
关于 n
infuxdb说
注意:行协议不支持标签值或字段值中的newline字符 n。
https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_reference/
相关文章:
- 1d 智能指针不适用于语法 (*)++
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 用于访问容器<T>数据成员的正确 API
- 重载操作程序时出错>>用于类中的字符串 memebr
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- C++中的cin.ignore()函数不适用于整个流
- 没有用于初始化C++中的变量模板的匹配构造函数
- 用于C++中带有数组和指针的循环
- 为什么它不适用于Visual 2019的原因
- 使用在用于SFINAE的void_t中具有参数的方法
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 重载==不适用于二进制树
- Insert函数不适用于2 if语句C++
- 用于矢量处理的多个线程
- 使外部项目可用于find_package CMake
- 在子目录中使用target_sources()命令时用于单元测试(qtest)的项目结构
- 为什么模数运算符不适用于该代码
- 并行用于C++17中数组索引范围内的循环
- 将fold表达式与std::一起用于两个元组
- 如何发布数据,包括使用libcurl(用于InfuxDB)的线路中断