【问题标题】:How to solve this error in prometheus ktext format parsing error in line 1: expected float as value, got "41584\r"如何解决prometheus ktext format parsing error in line 1: expected float as value, got "41584\r"
【发布时间】:2019-05-09 16:30:57
【问题描述】:

当我将参数从 sh 传递到我的服务器 prometheus 显示错误时,我从 json 获得的数据

我的狗

#!/bin/bash
REPORT=C:/gauge2/gauge/reports/json-report
FILE=$REPORT/result.json     

# Validate & push the metrics
if [ -f $FILE ]; then
   echo "File $FILE exists."
   cat $REPORT/result.json | \
    # Extract a nice json from last report
    jq -r '.projectName as $project |.environment as $env | .specResults[] |"ngt_lambda_qa {env=\"\($env)\", spec=\"\(.specHeading|gsub("\"";"\\\""))\", result=\"\(.executionStatus)\"} \(.executionTime)"' | \

    # Send to the metric server
    curl -v --data-binary @- localhost:9091/metrics/job/prometheus
    name=`uname -n`
    timestamp=`date +%s`
    result=`jq -r '.executionStatus' $REPORT/result.json`
    echo "prometrics_exec{name=\"$name\", result=\"$result\"} $timestamp" | curl --data-binary @- localhost:9091/metrics/prueba
else
   echo "File $FILE does not exist."
fi
sleep 90

【问题讨论】:

    标签: json sh jq grafana prometheus


    【解决方案1】:

    您的数据看起来在行尾有一个回车符('/r')。 jq 期望一个浮点值,解析后的值不是,因为它添加了这个字符。

    Difference between \n and \r?

    【讨论】:

    • 会不会是因为我是在windows 7上运行的?
    • 很可能,您可以尝试使用 dos2unix 之类的方法来修复行尾?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-27
    • 2023-02-03
    • 1970-01-01
    • 2018-10-09
    • 2018-11-07
    • 2019-09-29
    • 1970-01-01
    相关资源
    最近更新 更多