从安卓工作室到PowerBI流式数据集的流式CPU和Ram或传感器数据使用(通过REST-端点)



我通过Rest API成功实现了实时powerbi仪表板(用于监控CPU和Ram的使用情况(我使用以下powershell脚本读取值,并通过powershell代码将这些值通过3个变量Time、Ram和CPU发送到powerbi提供的端点,如下所示(端点(

https://api.powerbi.com/beta/xxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxx/datasets/xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx/rows?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%xxxxxxx%xxxxx%xxxx%xxxxxxxxxxxxxxx%3D%3D

寻求帮助想要通过android应用程序发送这些变量变量将保持不变(时间、CPU和RAm使用情况(,但这一次它将来自android应用程序(应用程序已经运行良好,并通过Java、捕获RAm和CPU信息

我尝试过改装、Volley示例代码,但仍然无法弄清楚如何将这3个变量发送到以下power BI流数据集的终点?我是REST的新手,所以寻求帮助将这3个变量以Json格式发送到下面的powerBI端点API,如下面的powershell代码所示

我也尝试过以下基于HTTP的代码,但无法弄清楚我是否可以在以下代码中放入下面的power BI推送URL new HttpPost(";http://yoururl"(;是否替换为电源BI URL?

JSONObject json = new JSONObject();
json.put("CPU", "15%");   
json.put("RAM", "4 GB");  
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpPost request = new HttpPost("http://yoururl");
StringEntity params = new StringEntity(json.toString());
request.addHeader("content-type", "application/json");
request.setEntity(params);
httpClient.execute(request);
// handle response here...
} catch (Exception ex) {
// handle exception here
} finally {
httpClient.close();
}

我从power BI得到的只是关注推送URL

while($true)
{
$ComputerCPU = (Get-WmiObject -Class win32_processor -ErrorAction Stop | Measure-Object -Property LoadPercentage -Average | Select-Object Average).Average
$ComputerMemory = Get-WmiObject -Class win32_operatingsystem -ErrorAction Stop
$UsedMemory = $ComputerMemory.TotalVisibleMemorySize - $ComputerMemory.FreePhysicalMemory
$Memory = (($UsedMemory/ $ComputerMemory.TotalVisibleMemorySize)*100)
$RoundMemory = [math]::Round($Memory, 2)
$Date = Get-Date -DisplayHint Date -Format MM/dd/yyyy
$Time123 = Get-Date -DisplayHint Time -Format HH:MM:ss
#$Date
#$Time123
#$ComputerCPU
#$RoundMemory
$endpoint = "https://api.powerbi.com/beta/xxxxxxxxxxx/datasets/xxxxxxxx/rows?key=xxx%xxxxxx%xxxxxxx%xxxxxx%xxxxxxxx%3D%3D"
$payload = @{
"Date" =$Date
"Time" =$Time123
"CPU" = $ComputerCPU
"MEM" = $RoundMemory
}
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))
Write-Host "date: " $Date " time: " $Time123 " cpu: " $ComputerCPU " mem: " $RoundMemory
sleep 0.5
}

明白了通过使用OkHTTP。

最新更新