To use the REST API, I have to pass a JSON object that looks like this:
{ "series" : [{ "metric": "custom.powershell.gauge", "points":[[1434684739, 1000]] } ] }
Pay attention to the nested array here. I can not reproduce this. Here is my code:
[int][double]$unixtime=get-date ( (get-date).ToUniversalTime() ) -UFormat %s $obj=@ {} $series=@ {} $array=@ () $points=@ () $value=get-random -Minimum 0 -Maximum 100 $series.add("metric","custom.powershell.gauge") $points=@ (@($unixtime, $value)) $series.add("points",$points) $obj.Add("series",@($series)) $json=$obj | ConvertTo-Json -Depth 30 -Compress $json
And here is the conclusion:
{"series":[{"points":[1434685292,95],"metric":"custom.powershell.gauge"}]}
I tried a lot of things, I can not get 2 arrays to be nested, it always looks like a separate array.
In the same note, someone explained this, please:
> $a=(1,2) > $a 1 2 > $a | ConvertTo-Json [ 1, 2 ] > $b=($a,$a) > $b 1 2 1 2 > $b | ConvertTo-Json [ { "value": [ 1, 2 ], "Count": 2 }, { "value": [ 1, 2 ], "Count": 2 } ]
Where are these value and Count ?
Thank you for your help.