Skip to main content

SignalR Performance Counters

One of the hidden gems in the SignalR framework is a utility called signalr.exe (in the Microsoft.AspNet.SignalR.Hosting.Utils package) that you can use to do a few things.

  • Install/Uninstall SignalR performance counters
  • Generate a static js file for the magic ~/signalr/hubs url.

After installing the Microsoft.AspNet.SignalR.Hosting.Utils NuGet package, you’ll find a SignalR executable in the package folder(under \packages\Microsoft.AspNet.SignalR.Hosting.Utils.1.0.0-alpha2\tools)

  • Open a command prompt(run as Administrator).
  • Browse to the tools folder containing the SignalR.exe file.
  • Run signalr ipc to install the Performance Counters. These performance counters give you more detailed information about your SignalR applications.

clip_image002

    • Remark: To use these on full IIS you need to add the app pool user for your application to the Performance Monitor Users group.
  • Run signalr ghp /path:<path to binaries> to generate a static JavaScript file containing the hub code. This file(server.js) is generated inside the same tools folder.

image

  • If we open up the file we see the magic that SignalR creates for us when calling the ~/signalr/hubs url:
/*!
* ASP.NET SignalR JavaScript Library v1.0.0
* http://signalr.net/
*
* Copyright Microsoft Open Technologies, Inc. All rights reserved.
* Licensed under the Apache 2.0
* https://github.com/SignalR/SignalR/blob/master/LICENSE.md
*
*/

/// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.2.js" />
/// <reference path="jquery.signalR.js" />
(function ($, window) {
/// <param name="$" type="jQuery" />
"use strict";

if (typeof ($.signalR) !== "function") {
throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/hubs.");
}

var signalR = $.signalR;

function makeProxyCallback(hub, callback) {
return function () {
// Call the client hub method
callback.apply(hub, $.makeArray(arguments));
};
}

function registerHubProxies(instance, shouldSubscribe) {
var key, hub, memberKey, memberValue, subscriptionMethod;

for (key in instance) {
if (instance.hasOwnProperty(key)) {
hub = instance[key];

if (!(hub.hubName)) {
// Not a client hub
continue;
}

if (shouldSubscribe) {
// We want to subscribe to the hub events
subscriptionMethod = hub.on;
}
else {
// We want to unsubscribe from the hub events
subscriptionMethod = hub.off;
}

// Loop through all members on the hub and find client hub functions to subscribe/unsubscribe
for (memberKey in hub.client) {
if (hub.client.hasOwnProperty(memberKey)) {
memberValue = hub.client[memberKey];

if (!$.isFunction(memberValue)) {
// Not a client hub function
continue;
}

subscriptionMethod.call(hub, memberKey, makeProxyCallback(hub, memberValue));
}
}
}
}
}

signalR.hub = $.hubConnection("/signalr", { useDefaultPath: false })
.starting(function () {
// Register the hub proxies as subscribed
// (instance, shouldSubscribe)
registerHubProxies(signalR, true);

this._registerSubscribedHubs();
}).disconnected(function () {
// Unsubscribe all hub proxies when we "disconnect". This is to ensure that we do not re-add functional call backs.
// (instance, shouldSubscribe)
registerHubProxies(signalR, false);
});

signalR.testHub = signalR.hub.createHubProxy('testHub');
signalR.testHub.client = { };
signalR.testHub.server = {
test: function () {
/// <summary>Calls the Test method on the server-side TestHub hub.&#10;Returns a jQuery.Deferred() promise.</summary>
return signalR.testHub.invoke.apply(signalR.testHub, $.merge(["Test"], $.makeArray(arguments)));
}
};

}(window.jQuery, window));

Popular posts from this blog

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Color B

Help! I accidently enabled HSTS–on localhost

I ran into an issue after accidently enabling HSTS for a website on localhost. This was not an issue for the original website that was running in IIS and had a certificate configured. But when I tried to run an Angular app a little bit later on http://localhost:4200 the browser redirected me immediately to https://localhost . Whoops! That was not what I wanted in this case. To fix it, you need to go the network settings of your browser, there are available at: chrome://net-internals/#hsts edge://net-internals/#hsts brave://net-internals/#hsts Enter ‘localhost’ in the domain textbox under the Delete domain security policies section and hit Delete . That should do the trick…

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.