I get a big difference when I invoke HTTP API :
1/ via a bash/curl call
2/ via a nodejs/https GET call
Any help appreciated
1/ Here is bash/curl call
#!/bin/bash
APIKEY="xxx-xxx"
curl https://<server>/prometheus-api/query \
-H "x-api-key: $APIKEY" \
-H "content-type: application/x-www-form-urlencoded" \
--data-urlencode \
query='ifHCInOctets{instance="MYROUTER.xxx"} and ifHCInOctets{ifName=~"et-1/1/1"}'
Here is the result : resultType is “vector” and result “value” is a number as string, 16 digits (??help)
$ jq '.' result
{
"status": "success",
"data": {
"resultType": "vector",
"result": [
{
"metric": {
"__name__": "ifHCInOctets",
"ifAlias": "--- Lien vers ...",
"ifDescr": "et-1/1/1",
"ifIndex": "682",
"ifName": "et-1/1/1",
"instance": "MYROUTER.xxx",
"job": "ifmibsnmp"
},
"value": [
1725001024.046,
"1975177966081341"
]
}
]
}
}
2/ Here is the node.js/https call
var request = '/prometheus-api/query?query=\"ifHCInOctets{instance=\'MYROUTER.xxx\'} and ifHCInOctets{ifName=~\'et-1/1/1\'}\"'
var erequest = encodeURI(request)
var options = {
host:host,
port: 443,
method: "GET",
path: erequest,
headers: {
'x-api-key': 'xxxxx',
'content-type': 'application/x-www-form-urlencoded',
},
rejectUnauthorized: false,
}
https.get(options,function(resp) {
resp.setEncoding('utf8');
console.log('statusCode',resp.statusCode)
if(resp.statusCode!=200) {
console.log('-----------------')
}
//console.log('headers:', resp.headers);
let data = '';
resp.on('data',function(chunk) {
data += chunk;
});
resp.on('end', () => {
exec.emit('data',data)
});
}).on('error', (err) => {
console.log('Error: ' + err.message);
});
Here is the result when invoked via nodejs+https : resultType is “string” and result[1] is NaN
{ statusCode 200
data {
status: 'success',
data: {
resultType: 'string',
result: [
1725001330.179,
"ifHCInOctets{instance='MYROUTER.xxx'} and ifHCInOctets{ifName=~'et-1/1/1'}"
]
}
}