Solved

Show Server Load on ASP Page...

Posted on 2006-07-12
5
322 Views
Last Modified: 2012-05-05
I need to be able to show the server load on an ASP page so I can get a snapshot of what the server load is like at that given page load.  Graphically would be AWESOME, but I'll take text percentages any day.  I could put them in the header showing each CPU and it's load average.  

Is this something fairly easily obtained?  I'm monitoring the load on a large inventory application that's in beta right now and this data would be very useful to me.

Joe
0
Comment
Question by:Joe Jenkins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 17094731
Quick and dirty:


    Dim CPU_Count
    Set objWMIService = GetObject("winmgmts:\\localhost\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
    For Each objItem In colItems
        CPU_Count = CPU_Count + 1
        Response.Write "CPU " & CPU_Count & ": <br><ul>"
        Response.Write "Load Percentage: " & objItem.LoadPercentage & "</ul>"
    Next


There's a bunch of other information you can retrieve from the objItem object. Take a look at this page:
http://www-sharp.com/articles/HardwareInfo.php

0
 
LVL 5

Author Comment

by:Joe Jenkins
ID: 17096167
Interesting idea but I'm getting a permissions error when I run it.  

Output:
error '80041003'
/fsa/test2.asp, line 3

Line3:
    Set objWMIService = GetObject("winmgmts:\\localhost\root\cimv2")

My understanding of WMI is that I'll need to have an administrator account logged in to have this work.  How would that work on a website admin panel where it's using an anonymous account?  Can you impersonate a user account on the server?  If so, this will work beautifully.

Joe
0
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 17096959
You'll have to set that up in IIS

To do that load the IIS management module

Click the website that contains the file where you stored this script
Right click on the file and click properties
Click the file security tab
Click edit in the Authentication and access control frame
Make sure the "Enable Anonymous access" check box is checked
Put in the username and password for an administrative account on the computer

Keep in mind that this is potentially dangerous. If you add anything else to this script take extra precautions to ensure there are no security holes in it.
0
 
LVL 14

Accepted Solution

by:
CyrexCore2k earned 125 total points
ID: 17097265
Eh I was bored so I made it graphical for ya ;)

<html>
<body>
<style>
table {
      font-family: arial;
      color: 999999;
      font-size: 10px;
}</style>
<table cellpadding="0" cellspacing="0"><tr>
<%
      Dim CPU_Count
    Set objWMIService = GetObject("winmgmts:\\localhost\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
    For Each objItem In colItems
            Response.Write "<td><table cellpadding=""0"" cellspacing=""0""><tr><td>"
        CPU_Count = CPU_Count + 1
        Response.Write "CPU #" & CPU_Count & ": " & objItem.LoadPercentage & "%<br><br></td></tr><tr><td align=""center"">"
        Response.Write "<div style=""height: 200px; width: 40px; border: 1px solid black; background-color: 007700; padding: 0px;"">"
            Response.Write "<span style=""height: " & ((100 - objItem.LoadPercentage) * 2) & "px; width: 40px; background-color: 000000;""></div></div></td></tr></table></td>"
    Next
%>
</tr></table>
</body></html>

This should display multiple CPUs if you have a dual core or if you have a P4 with hyper threading.
0
 
LVL 5

Author Comment

by:Joe Jenkins
ID: 17098480
Oooooo, that'll fit nicely on the page with all the other system statistics, thank you!

One more quick thing, for integration into my bar along the top if you're logged in as our sysadmins.  

Now, if I wanted to just show it in a format like:

Load: 0.40, 0, 0.45, 0

I could do:
    Dim CPU_Count
    Set objWMIService = GetObject("winmgmts:\\localhost\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
    For Each objItem In colItems
        CPU_Count = CPU_Count + 1
        Response.Write "Load: " & objItem.LoadPercentage / 100 & ", "
    Next
      
Excellent. :)  Thanks again!

Joe Jenkins
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question