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

对着背影说爱祢 提交于 2019-12-12 01:33:04

问题


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'
SELECT  (@@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.


回答1:


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>



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3425581/i-want-to-use-wmi-or-java-in-coldfusion-on-windows-to-get-performance-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!