使用curl向InfluxDB插入数据时遭遇字段格式错误求助
Hey there, let's break down why you're hitting that 400 Bad Request error and fix it right away. The root cause here is a common gotcha with InfluxDB's line protocol: tag values can't have unescaped spaces!
Looking at your curl command, the service tag has a value Linux CPU check that includes spaces. InfluxDB treats unquoted spaces as separators between different components of the line protocol, so it gets confused trying to parse that space-containing value—hence the "invalid field format" message.
You've got two straightforward fixes to choose from:
- Wrap the space-containing tag value in double quotes to escape the spaces
- Replace the spaces with an underscore or hyphen (a common convention for tag values)
Fix 1: Quoted tag value
Use double quotes around the service value to tell InfluxDB to treat it as a single tag entry:
curl -i -XPOST 'http://localhost:8086/write?db=nagflux' --data-binary 'metrics,host=server1,service="Linux CPU check",command=check_Linux value=2.87 1505131200'
Fix 2: Replace spaces with underscores
If you prefer to avoid quotes, replace the spaces in the tag value:
curl -i -XPOST 'http://localhost:8086/write?db=nagflux' --data-binary 'metrics,host=server1,service=Linux_CPU_check,command=check_Linux value=2.87 1505131200'
Either approach will make your line protocol valid—InfluxDB will now correctly recognize the entire Linux CPU check (or Linux_CPU_check) as the value for the service tag instead of splitting it into invalid parts.
内容的提问来源于stack exchange,提问作者Madhanika

