开发者

I want to use WMI or Java in ColdFusion on Windows to get performance data

开发者 https://www.devze.com 2023-01-11 00:26 出处:网络
I am rolling my own simple web-based perfmon, I am not happy with some of the data I can get like cpu usage, which i use via a sql query. I am able to get memory usage just fine...I will attach a scre

I am rolling my own simple web-based perfmon, I am not happy with some of the data I can get like cpu usage, which i use via a sql query. I am able to get memory usage just fine...I will attach a screenshot, so you can see what I currently have for my main/home/dashboard page.

I am currently using webcharts3d, which i am loving being able to use ajax, update the chart, and i have a dynamically updating dashboard. Yes of course I have to get only a few performance counter's so in my desire to have a web-based performance dashboard i do not kill the server.

DECLARE @CPU_BUSY int, @IDLE int
SELECT @CPU_BUSY = @@CPU_BUSY, @IDLE = @@IDLE WAITFOR DELAY '000:00:01'
S开发者_StackOverflowELECT  (@@CPU_BUSY - @CPU_BUSY)/((@@IDLE - @IDLE + @@CPU_BUSY - @CPU_BUSY) *1.00) *100 AS 'CPU'

And all i get in results is 0.0000, so either the query is wrong, or i have very little cpu activity going on. Where as when I use my windows task manager.

Here is the code for gathering memory I am using, I do not claim credit for any of this code, I found it somewhere.

<cfscript>
      jRuntime = CreateObject("java","java.lang.Runtime").getRuntime();
      memory = StructNew();
      memory.freeAllocated = jRuntime.freeMemory() / 1024^2;
      memory.allocated = jRuntime.totalMemory() / 1024^2;
      memory.used = memory.allocated - memory.freeAllocated;
      memory.percentUsedAllo = (memory.used / memory.allocated) * 100;
</cfscript>

SysAdmin http://a.imageshack.us/img826/2575/sysadminscreenshot.png

So I am looking for more wmi or java or scripts to get cpu usage, and perhaps any other important server stat.


How about using Coldfusion built-in function called, GetMetricData. It can help you to monitor your server performance like Coldfusion Admin. I've done it with bar of cfchart. If you wanna integrate with Web3Dcharts, you can.

http://ppshein.wordpress.com/2010/08/04/getmetricdata-for-server-monitor/

<cfset pmData = GetMetricData(“PERF_MONITOR”) >
<cfchart chartheight=”500″ chartwidth=”700″ format=”PNG” showlegend=”yes”>
    <cfchartseries type=”bar” seriescolor=”##639526″ paintstyle=”light” colorlist=”##ff8080,##ffff80,##80ff80,##0080ff,##ff80c0,##ff80ff,##ff8040,##008000,##0080c0,##808000″>
        <cfchartdata item=”Page Hits” value=”#pmData.PageHits#”>
        <cfchartdata item=”Request Queued” value=”#pmData.ReqQueued#”>
        <cfchartdata item=”Database Hits” value=”#pmData.DBHits#”>
        <cfchartdata item=”Request Running” value=”#pmData.ReqRunning#”>
        <cfchartdata item=”Request TimedOut” value=”#pmData.ReqTimedOut#”>
        <cfchartdata item=”Bytes In” value=”#pmData.BytesIn#”>
        <cfchartdata item=”Bytes Out” value=”#pmData.BytesOut#”>
        <cfchartdata item=”Avg Queue Time” value=”#pmData.AvgQueueTime#”>
        <cfchartdata item=”Avg Request Time” value=”#pmData.AvgReqTime#”>
        <cfchartdata item=”Avg Database Time” value=”#pmData.AvgDBTime#”>
    </cfchartseries>
</cfchart>


Another solution:

Then using the Reliability and Performance Monitor (i.e. perfmon), create a counter for CPU (Total) - it should be in the long list of Windows counters.

You can save this data to file or to a database. If you save it to a database you can then use CF to query that data and get pretty accurate performance info. You can of course display this on a graph over time which is a massive benefit in my opinion.

When you have that done you can then enable performance monitoring in CF admin, and you will then have CF performance metrics available to pick up in perfmon.

We have successfully implemented this solution across a CF cluster of 10+ machines and it gives a an excellent idea of server performance at a given point in time and historically.


CfTracker probably has the code you need, and since it uses the Apache License you can simply grab any relevant stuff from it, once you attribute appropriately.

It would be even better if you could go a step further and talk to Dave Boyet about combining your two tools - or at least collaborating on the common bits.


To more directly answer your question, here's a blog article explaining how to use WMI from ColdFusion.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号