Hello,
I am having trouble accessing custom windows performance counters via check_nt (NC_Net on XP and 2003); keeps returning not found (-1). I am able to access the counter using NC_Net’s “Performance Counter Viewer”, so I hope that I am simply using incorrect syntax.
These work (return 1):
./check_nt -H 192.168.1.91 -p 1248 -v COUNTER -l “\Server\Server Sessions”,“Server Sessions: %.f” -w 20 -c 30
./check_nt -H 192.168.1.91 -p 1248 -v COUNTER -l “\Server\Server Sessions”, -w 20 -c 30
These fail (return -1):
./check_nt -H 192.168.1.91 -p 1248 -v COUNTER -l “\TestCounterCategory\TestCounter”, -w 20 -c 30
./check_nt -H 192.168.1.91 -p 1248 -v COUNTER -l “TestCounterCategory\TestCounter”, -w 20 -c 30
./check_nt -H 192.168.1.91 -p 1248 -v COUNTER -l “\TestCounterCategory\TestCounter”, -w 20 -c 30
./check_nt -H 192.168.1.91 -p 1248 -v COUNTER -l “TestCounterCategory\TestCounter”, -w 20 -c 30
./check_nt -H 192.168.1.91 -p 1248 -v COUNTER -l “^TestCounterCategory^TestCounter”, -w 20 -c 30
./check_nt -H 192.168.1.91 -p 1248 -v COUNTER -l “TestCounterCategory^TestCounter”, -w 20 -c 30
Using “COUNTER” flag:
shatterit.com/nc_net/files/r … om_Counter
Name of the counter using the NC_Net performance counter viewer:
TestCounterCategory:TestCounter:0
Code snippet:
using System.Diagnostics;
…
PerformanceCounter _counter;
…
// see: msdn2.microsoft.com/en-us/2b0byczf(VS.80.aspx
_counter = new PerformanceCounter( “TestCounterCategory”, “TestCounter”, false );
_counter.RawValue = 0
…
Full source code:
using System;
using System.Diagnostics;
using System.Threading;
namespace PCTest
{
class App
{
private delegate void RunDelegate();
private Thread _counterThread;
private PerformanceCounter _counter;
private bool _counterRunning;
public App()
{
try
{
_counter = new PerformanceCounter( "TestCounterCategory", "TestCounter", false );
_counter.RawValue = 0;
}
catch(Exception e:evil:{ throw new ApplicationException( "Missing counters", ex );}
}
~App()
{
_counter.RawValue = 0;
}
private void Run()
{
while(_counterRunning)
{
_counter.RawValue += 2;
Thread.Sleep(1000);
}
}
public void BeginRun()
{
_counterRunning = true;
_counterThread = new Thread( new ThreadStart( this.Run ) );
_counterThread.Start();
Console.WriteLine("PCTest running...Press any key to exit");
Console.ReadLine();
_counterRunning = false;
_counterThread.Join();
}
[STAThread]
static void Main(string] args)
{
try
{
if( args.Length == 0 )
{
App app = new App();
app.BeginRun();
}
else if( args[0] == "-i" )
App.Install();
else if( args[0] == "-u" )
App.Uninstall();
else
App.Usage();
}
catch( ApplicationException ex )
{
Console.WriteLine( ex.Message );
App.Usage();
}
catch( Exception ex )
{
Console.WriteLine("-----------------------------------------");
Console.WriteLine( ex.Message );
Console.WriteLine( ex.StackTrace );
Console.WriteLine("-----------------------------------------");
App.Usage();
}
}
public static void Usage()
{
Console.WriteLine( "PCTest.exe -i] -u]" );
Console.WriteLine( " -i install performnance counter" );
Console.WriteLine( " -u uninstall performnance counter" );
}
public static void Install()
{
// Remove an existing performance category and its counters
if( PerformanceCounterCategory.Exists( "TestCounterCategory" ) )
throw new ApplicationException( "Performance counters have already been installed." );
// Create a set of performance counter for each task
CounterCreationDataCollection ccdc = new CounterCreationDataCollection();
// Trans execs per hour
CounterCreationData ccd = new CounterCreationData( "TestCounter",
"TestCounterDesc",
PerformanceCounterType.NumberOfItems64 );
ccdc.Add( ccd );
// Create category
PerformanceCounterCategory.Create( "TestCounterCategory",
"TestCounterCategoryDesc",
ccdc );
}
public static void Uninstall()
{
// Remove an existing performance category and its counters
if( PerformanceCounterCategory.Exists( "TestCounterCategory" ) )
PerformanceCounterCategory.Delete( "TestCounterCategory" );
}
}
}
Thanks for your time,
Erik