Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save miklund/664ce9c665e69469b42c to your computer and use it in GitHub Desktop.
Save miklund/664ce9c665e69469b42c to your computer and use it in GitHub Desktop.
2011-12-08 Custom Performance Counters in Alive
# Title: Custom Performance Counters in Alive
# Author: Mikael Lundin
# Link: http://blog.mikaellundin.name/2011/12/08/custom-performance-counters-in-alive.html
<Alive>
<settings columns="3" />
<counters>
<groups>
<group name="Test" updateLatency="1000">
<counter name="Test" categoryName="Test Category" counterName="Test Increment" />
</group>
</groups>
</counters>
</Alive>
open System.Diagnostics
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
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="LiteMedia.Alive.Web.Test.Index" %>
<!DOCTYPE html5>
<html>
<head>
<title>Alive custom performance counter</title>
<style>
div { display: block; }
iframe { width: 100%; height: 500px; border: none; }
</style>
</head>
<body>
<form runat="server">
<div>
<h1>Press the button to increment the counter</h1>
<asp:ScriptManager runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button runat="server" Text="Press me" OnClick="IncreaseCounter" />
</ContentTemplate>
</asp:UpdatePanel>
<iframe src="/Alive.axd/" />
</div>
</form>
</body>
</html>
protected void IncreaseCounter(object sender, EventArgs e)
{
using (var counter = new PerformanceCounter("Test Category", "Test Increment", readOnly: false))
{
counter.Increment();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment