Created
January 10, 2016 20:24
-
-
Save miklund/664ce9c665e69469b42c to your computer and use it in GitHub Desktop.
2011-12-08 Custom Performance Counters in Alive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: Custom Performance Counters in Alive | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2011/12/08/custom-performance-counters-in-alive.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alive> | |
<settings columns="3" /> | |
<counters> | |
<groups> | |
<group name="Test" updateLatency="1000"> | |
<counter name="Test" categoryName="Test Category" counterName="Test Increment" /> | |
</group> | |
</groups> | |
</counters> | |
</Alive> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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