473,699 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

performancecoun ter

I'm trying to write some that is database driven. What it does it loop
through a dataset and populate the

categoryName
CounterName
InstanceName
MachineName

properties of the performancecoun ter object (I think I have the speak right
there)

Anyway, when I run the console app, the values are always 0. For example,
the properties above have these values from the db.

with PerforanceCount er
..CategoryName = "Processor"
..CounterName = "% Processor Time"
..InstanceName = "0"
..MachineName = "."
beginInit()
end with

later in the code I do a performancecoun ter.nextvalue

it always comes back 0. If I step through it, the value is still 0, but if
I type in the command window, I get a value back.. like 3.34324. Can
anyone tell me what I'm doing wrong. I would like to keep this database
driven so I can add stuff easiser and not have to change the vb code.

Thanks
Shannon

ra*****@sauder. com
Nov 21 '05 #1
7 2951
Could you post the code that's causing the problem? somewhere around and
including where you're getting 0 as the NextValue.

Imran.

"JvCoach23" <ra*****@sauder .com> wrote in message
news:1d******** *************** ********@40tude .net...
I'm trying to write some that is database driven. What it does it loop
through a dataset and populate the

categoryName
CounterName
InstanceName
MachineName

properties of the performancecoun ter object (I think I have the speak right there)

Anyway, when I run the console app, the values are always 0. For example,
the properties above have these values from the db.

with PerforanceCount er
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "0"
.MachineName = "."
beginInit()
end with

later in the code I do a performancecoun ter.nextvalue

it always comes back 0. If I step through it, the value is still 0, but if I type in the command window, I get a value back.. like 3.34324. Can
anyone tell me what I'm doing wrong. I would like to keep this database
driven so I can add stuff easiser and not have to change the vb code.

Thanks
Shannon

ra*****@sauder. com

Nov 21 '05 #2
For Each dr In ds.Tables(0).Ro ws
vcCategoryName = CType(dr.Item(" vcCategoryName" ), String)
vcCounterName = CType(dr.Item(" vcCounterName") , String)
vcServer = CType(dr.Item(" vcServer"), String)
vcInstance = CType(dr.Item(" vcInstance"), String)
intTblPMInstanc eId = CType(dr.Item(" intTblPMInstanc eId"),
Integer)

'display on screen what we are going to be going after
Console.WriteLi ne(vcCounterNam e & " - " & vcCategoryName & " -
" & vcInstance & " - " & vcServer)

'set the oPerfmon object settings
With oPerfMon
.CategoryName = vcCategoryName
.CounterName = vcCounterName
.InstanceName = vcInstance
.MachineName = vcServer
.BeginInit()
End With

Dim intVal As Single

Try
intVal = oPerfMon.NextVa lue
'pump that info the the screen
Console.WriteLi ne(intVal & " - Value in the intVal object")

'this is where it alwasy shows 0.
On Fri, 24 Sep 2004 16:36:58 -0400, Imran Koradia wrote:
Could you post the code that's causing the problem? somewhere around and
including where you're getting 0 as the NextValue.

Imran.

"JvCoach23" <ra*****@sauder .com> wrote in message
news:1d******** *************** ********@40tude .net...
I'm trying to write some that is database driven. What it does it loop
through a dataset and populate the

categoryName
CounterName
InstanceName
MachineName

properties of the performancecoun ter object (I think I have the speak

right
there)

Anyway, when I run the console app, the values are always 0. For example,
the properties above have these values from the db.

with PerforanceCount er
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "0"
.MachineName = "."
beginInit()
end with

later in the code I do a performancecoun ter.nextvalue

it always comes back 0. If I step through it, the value is still 0, but

if
I type in the command window, I get a value back.. like 3.34324. Can
anyone tell me what I'm doing wrong. I would like to keep this database
driven so I can add stuff easiser and not have to change the vb code.

Thanks
Shannon

ra*****@sauder. com

Nov 21 '05 #3
Maybe this applies in your case:
http://msdn.microsoft.com/library/de...valuetopic.asp

<quote>
If the calculated value of a counter depends on two counter reads, the first
read returns 0.0.
</quote>

If the value turns out to be zero, you can call NextValue again and check
the value.

hope that helps..
Imran.

"JvCoach23" <ra*****@sauder .com> wrote in message
news:vy******** *************** *****@40tude.ne t...
For Each dr In ds.Tables(0).Ro ws
vcCategoryName = CType(dr.Item(" vcCategoryName" ), String)
vcCounterName = CType(dr.Item(" vcCounterName") , String)
vcServer = CType(dr.Item(" vcServer"), String)
vcInstance = CType(dr.Item(" vcInstance"), String)
intTblPMInstanc eId = CType(dr.Item(" intTblPMInstanc eId"),
Integer)

'display on screen what we are going to be going after
Console.WriteLi ne(vcCounterNam e & " - " & vcCategoryName & " -
" & vcInstance & " - " & vcServer)

'set the oPerfmon object settings
With oPerfMon
.CategoryName = vcCategoryName
.CounterName = vcCounterName
.InstanceName = vcInstance
.MachineName = vcServer
.BeginInit()
End With

Dim intVal As Single

Try
intVal = oPerfMon.NextVa lue
'pump that info the the screen
Console.WriteLi ne(intVal & " - Value in the intVal object")

'this is where it alwasy shows 0.
On Fri, 24 Sep 2004 16:36:58 -0400, Imran Koradia wrote:
Could you post the code that's causing the problem? somewhere around and
including where you're getting 0 as the NextValue.

Imran.

"JvCoach23" <ra*****@sauder .com> wrote in message
news:1d******** *************** ********@40tude .net...
I'm trying to write some that is database driven. What it does it loop
through a dataset and populate the

categoryName
CounterName
InstanceName
MachineName

properties of the performancecoun ter object (I think I have the speak

right
there)

Anyway, when I run the console app, the values are always 0. For
example,
the properties above have these values from the db.

with PerforanceCount er
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "0"
.MachineName = "."
beginInit()
end with

later in the code I do a performancecoun ter.nextvalue

it always comes back 0. If I step through it, the value is still 0, but

if
I type in the command window, I get a value back.. like 3.34324. Can
anyone tell me what I'm doing wrong. I would like to keep this database
driven so I can add stuff easiser and not have to change the vb code.

Thanks
Shannon

ra*****@sauder. com

Nov 21 '05 #4
On Mon, 27 Sep 2004 22:50:06 -0400, Imran Koradia wrote:
http://msdn.microsoft.com/library/de...valuetopic.asp


great.. thanks for the help.. I had figured that out with testing, but am
new to vb.net, doubted myself and figured I was doing something wrong. do
you happen to have a list of which counters need to be run twice..

no biggie.. I appreciate the help
Nov 21 '05 #5
I'm afraid no. However, Performance counters are *generally* used to display
stats that refresh every once in a while (using a timer or something). In
that case, you know that the NextValue is going to be called multiple times
and hence you're not going to end up with a value of 0 (if its not 0). Just
a thought..Ofcour se, there are exceptions always..

Imran.

"JvCoach23" <ra*****@sauder .com> wrote in message
news:1e******** *************** *****@40tude.ne t...
On Mon, 27 Sep 2004 22:50:06 -0400, Imran Koradia wrote:
http://msdn.microsoft.com/library/de...valuetopic.asp
great.. thanks for the help.. I had figured that out with testing, but am
new to vb.net, doubted myself and figured I was doing something wrong. do
you happen to have a list of which counters need to be run twice..

no biggie.. I appreciate the help

Nov 21 '05 #6
Maybe your willing to give a bit more education. This works. it is on a
timer. after the first run it bring back the correct data..
Sub Main()
Dim intTimer As Integer = 3000
Console.WriteLi ne("Samples every " & intTimer / 1000 & " seconds.")
Console.WriteLi ne("Press ENTER to exit")
Dim vcServer As String
vcServer = "s011038hom e"
With oPerfMon
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "_Total"
.MachineName = vcServer
.BeginInit()
End With

CheckCounter()

tmr.Enabled = True
tmr.Interval = intTimer
Console.ReadLin e()
tmr = Nothing
oPerfMon = Nothing
End Sub
Private Sub tmr_Elapsed(ByV al sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles tmr.Elapsed
CheckCounter()
End Sub
Private Sub CheckCounter()
Dim intVal As Integer
intVal = Math.Round(oPer fMon.NextValue)
Console.WriteLi ne(oPerfMon.Nex tValue & " - oPerfmon")
Console.WriteLi ne(intVal & " - intVal value")

Console.WriteLi ne("CPU %:" & intVal)
End Sub
However, if I move where I set the oPerfmon values.. it always returns 0.
can you explain why.
Sub Main()
Dim intTimer As Integer = 3000
Console.WriteLi ne("Samples every " & intTimer / 1000 & " seconds.")
Console.WriteLi ne("Press ENTER to exit")
CheckCounter()

tmr.Enabled = True
tmr.Interval = intTimer
Console.ReadLin e()
tmr = Nothing
oPerfMon = Nothing
End Sub
Private Sub tmr_Elapsed(ByV al sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles tmr.Elapsed
CheckCounter()
End Sub
Private Sub CheckCounter()
Dim vcServer As String
vcServer = "s011038hom e"
With oPerfMon
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "_Total"
.MachineName = vcServer
.BeginInit()
End With

Dim intVal As Integer
intVal = Math.Round(oPer fMon.NextValue)
Console.WriteLi ne(oPerfMon.Nex tValue & " - oPerfmon")
Console.WriteLi ne(intVal & " - intVal value")

Console.WriteLi ne("CPU %:" & intVal)
End Sub

Hope your still willing to help out on this.
Thanks
Shannon
Nov 21 '05 #7
Here's what I believe is happening:
At every tick of your timer, you are setting the category name, instance
name, etc of the performance counter which means you are re-initializing the
performance counter. When that happens and if your performance counter is
one which would require two reads to get the correct value, then the first
value read with the NextValue method will be 0. So now what's happening is
that everytime your elapsed event is fired, you are simply re-initializing
the counter and wiping out whatever previous values it had which is why
you're always getting 0. What you did in the first part is correct. You
initialize the counter somewhere, then fire the timer and within the elapsed
event, keep calling NextValue to get the performance counter values. If you
need to keep track of several performance counter values, either define
different peformance counter objects for different counters or define a
collection (array, arraylist, hashtable, etc whichever is suitable) of
performance counters which holds one object for each performance counter you
want to keep track of.

hope that helps..
Imran.

"JvCoach23" <ra*****@sauder .com> wrote in message
news:1i******** *************** *******@40tude. net...
Maybe your willing to give a bit more education. This works. it is on a
timer. after the first run it bring back the correct data..
Sub Main()
Dim intTimer As Integer = 3000
Console.WriteLi ne("Samples every " & intTimer / 1000 & " seconds.")
Console.WriteLi ne("Press ENTER to exit")
Dim vcServer As String
vcServer = "s011038hom e"
With oPerfMon
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "_Total"
.MachineName = vcServer
.BeginInit()
End With

CheckCounter()

tmr.Enabled = True
tmr.Interval = intTimer
Console.ReadLin e()
tmr = Nothing
oPerfMon = Nothing
End Sub
Private Sub tmr_Elapsed(ByV al sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles tmr.Elapsed
CheckCounter()
End Sub
Private Sub CheckCounter()
Dim intVal As Integer
intVal = Math.Round(oPer fMon.NextValue)
Console.WriteLi ne(oPerfMon.Nex tValue & " - oPerfmon")
Console.WriteLi ne(intVal & " - intVal value")

Console.WriteLi ne("CPU %:" & intVal)
End Sub
However, if I move where I set the oPerfmon values.. it always returns 0.
can you explain why.
Sub Main()
Dim intTimer As Integer = 3000
Console.WriteLi ne("Samples every " & intTimer / 1000 & " seconds.")
Console.WriteLi ne("Press ENTER to exit")
CheckCounter()

tmr.Enabled = True
tmr.Interval = intTimer
Console.ReadLin e()
tmr = Nothing
oPerfMon = Nothing
End Sub
Private Sub tmr_Elapsed(ByV al sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles tmr.Elapsed
CheckCounter()
End Sub
Private Sub CheckCounter()
Dim vcServer As String
vcServer = "s011038hom e"
With oPerfMon
.CategoryName = "Processor"
.CounterName = "% Processor Time"
.InstanceName = "_Total"
.MachineName = vcServer
.BeginInit()
End With

Dim intVal As Integer
intVal = Math.Round(oPer fMon.NextValue)
Console.WriteLi ne(oPerfMon.Nex tValue & " - oPerfmon")
Console.WriteLi ne(intVal & " - intVal value")

Console.WriteLi ne("CPU %:" & intVal)
End Sub

Hope your still willing to help out on this.
Thanks
Shannon

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3295
by: W1ld0ne74 | last post by:
I am implimenting Performance counters into a web application. I use the following code to create the counters during setup: private void SetupPerfCntrs() { System.Diagnostics.CounterCreationDataCollection CounterDatas = null; System.Diagnostics.CounterCreationData cdCounter4 = null; try { if(System.Diagnostics.PerformanceCounterCategory.Exists("LogisOnline"))
1
7289
by: Chris | last post by:
I'm trying to do something really easy: just get the % CPU load. However, I just get mostly 0's sprinkled with an occasional 100. I poked around on the web for info, but all the stuff I found (I think) does what I have below. Am I blanking out on something here? Getting the available RAM works fine. Code example below: using System;
1
4226
by: jimbo | last post by:
Here is my problem. I'm creating an Instrumentation class that will use previously created Performance Categories and Counters in order to time various processes (ie. query duration etc.). This Instrumentation class will be used by a variety of "services", so the Categories and Counters to be used within the object must be set during object construction. So I created a class variable array of: private static PerformanceCounter...
0
1278
by: BuddyWork | last post by:
Hello, Can someone please explain why my Instances are not appearing in Perfmon. Here is my code to create the counters. CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
0
1107
by: Michiel | last post by:
Hello, I'm trying to retrieve my cpu load as follows : PerformanceCounter* cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); float value = cpuCounter->NextValue(); However, this always returns 0.0. The same query used in perfmon.exe works fine.
0
1138
by: Henning Krause [MVP] | last post by:
Hello, I've created a simple website which instantiates a PerformanceCounter object on any existing counter. On the Page_Load() event I set a label to the value of the performancecounter (via counter.NextValue()). My testmachine is a Windows 2000 SP4, IE6 SP1, .NET Framework 1.1 SP 1. When I open the Page, the Performance Counter value is displayes as
3
2882
by: Rob Meade | last post by:
Hi all, I'm having a bit of trouble with the following function.... Private Function GetSystemUpTime() As TimeSpan ' declare variables Dim Result As TimeSpan Dim PerformanceCounter As PerformanceCounter
0
1239
by: Scheu | last post by:
Hi all, I'm hoping someone can help me with this bizarre problem. If I create a new PerformanceCounter object in a ComVisible class and invoke it from wscript, it never seems to terminate. When debugging, Visual Studio never leaves the (running) state when the Go function exits (even clicking the 'Stop Debugging' button fails). When not debugging, the cscript / wscript.exe process never leaves memory. I've tried this same code in a...
3
4590
by: Geoff McElhanon | last post by:
I have been struggling with a security issue that occurs under .NET 2.0, but does not occur under .NET 1.1. Essentially I am trying to open up a performance counter on a remote server and monitor its value. In .NET 1.1 this worked fine, however under .NET 2.0 it fails when I am not an administrator on the remote server. To provide a lean demonstration of the issue, I created the following class: ============================
1
4199
by: bobido | last post by:
Hi there! Currently I'm trying to display the current performance of my servers on my website. I tried it with the following code: protected static PerformanceCounter cpuCounter; protected static PerformanceCounter ramCounter; protected void Page_Load(object sender, EventArgs e) {
0
8705
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8628
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8899
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5884
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.