一个Azure的网站/应用程序可以决定它的实例的CPU /内存使用情况? [英] Can an Azure web site/app determine its instance's CPU/memory usage?

查看:221
本文介绍了一个Azure的网站/应用程序可以决定它的实例的CPU /内存使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的情况下,记录它们的CPU /内存使用(总preferably的百分比),但一切我已经在Azure中的网站试图不起作用。它打破启动,并在502错误的结果。我试过ManagementObjectSearcher和的PerformanceCounter至今。当部署到Azure的这些工作,但在当地没有找到。难道这功能,只需禁用?将一个WebJob有更好的运气,也许?

I have a need for my instances to log their cpu/mem usage (% of total preferably), but everything I've tried in an Azure web site doesn't work. It breaks startup and results in 502 errors. I've tried ManagementObjectSearcher and PerformanceCounter so far. These work find locally but not when deployed to Azure. Is this functionality just disabled? Would a WebJob have better luck maybe?

我想,如果没有办法做到这一点的网站实例本身的唯一的选择就是做一个PowerShell脚本或其他应用程序,可以看看它通过在Azure API和它存储在该情况下,一个共享的地方查找在飞行...

The only alternative I can think of if there's no way to do this on the web site instance itself is make a PowerShell script or other app that can look it up via the Azure APIs and store it in a shared place for the instances to look up on the fly...

推荐答案

您将无法访问在Azure中的webapps性能计数器数据以及类似的东西。您应该能够使用的System.Diagnostics.Process 类和检索进程列表,找出w3wp进程,并得到其CPU和内存使用情况,如果你真的想这样做本网站code本身。

You cannot access Performance counters data and similar stuff in Azure Webapps. You should be able to use the System.Diagnostics.Process class and retrieve a process list and find out the w3wp process and get its CPU and memory usage if you really want to do this within the website code itself.

<%@ Page language="cs" %>
<%@ Import Namespace="System.Diagnostics" %>
<%
foreach (Process p in  System.Diagnostics.Process.GetProcesses())
{
Response.Write ("<br/>" + p.ProcessName + "\t" + p.Id + "\t" +    p.PrivateMemorySize+ "\t" + "\t" );
}

%>

做最简单的事情就是写一个PowerShell脚本和欠幅它作为一个webjob。一个PowerShell code像这样在你的webjob可能给你,你正在寻找的信息。

The easiest thing to do is to write a powershell script and runt it as a webjob. A powershell code like this in your webjob might give you the information that you are looking for

gps|where {$_.name -eq 'w3wp' }|select PrivateMemorySize, CPU, Id

希望这有助于...

hope this helps...

这篇关于一个Azure的网站/应用程序可以决定它的实例的CPU /内存使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆