Custom Performance Counters in Alive
If you've missed previous posts about Alive, you can read more about it at
The real power of Alive, is when it comes to custom performance counters. In your application you have events that would be nice to track in real time. A new order is put, someone paid with their credit card, a user logged in. For this you can create custom performance counters.
Create a new performance counter
It is easy to create a new performance counter on your development machine. Open up server explorer in Visual Studio. Right click on Performance Counters and select "Create New Category".
This gives you a slick interface where you can create your new counter.
Create a new web application and include Alive.
Install-Package LiteMediaAlive
Edit your web.config so Alive configuration looks like following.
Create a new ASPX page.
We bind the button to a method in code behind that increases the counter.
Bam! You're done! You can download the whole example from here.
LiteMedia.Alive.CustomPerformanceCounter.zip
There are a lot of performance counter types to explore. There's an excellent article on The Code Project about performance counters.
Create performance counters in your production environment
It is a common scenario that you can't reach the production environment from your development machine. In that case I use this piece of F# to create my performance counters.
let args = System.Environment.GetCommandLineArgs()
printf "LiteMedia, Mikael Lundin\n" printf "Create performance counters\n"
if args.Length <> 3 then printf "Usage: CreatePerfmon [category name] [category description] "
else let name = args.[1] let description = args.[2]
let counterCreation = new CounterCreationDataCollection()
let create name description counterType = new CounterCreationData(name, description, counterType)
create "# operations executed" "Number of total operations executed" PerformanceCounterType.NumberOfItems32 |> counterCreation.Add |> ignore
create "# operations / sec" "Number of operations executed per second" PerformanceCounterType.RateOfCountsPerSecond32 |> counterCreation.Add |> ignore
create "average time per operation" "Average duration per operation execution" PerformanceCounterType.AverageTimer32 |> counterCreation.Add |> ignore
create "average time per operation base" "Average duration per operation execution base" PerformanceCounterType.AverageBase |> counterCreation.Add |> ignore
PerformanceCounterCategory.Create(name, description, PerformanceCounterCategoryType.MultiInstance, counterCreation) |> ignore
Compile it into a runnable exe and execute on your production environment like this.
CreateCounter.exe "New orders" "Increments when new orders are added to the system"
This will give you a performance category on the server called "New orders" and it will contain the following counters.
- # operations executed
- # operations / sec
- average time per operation
This is a really simple way to keep an eye on the production environment and that you're recieving new orders in the rate that you should.