Exposing runtime data from IIS worker processes
Dynamic properties feature in IIS7 configurtion system lets you expose dynamic data as configuration system properties. RscaExt.xml which is part of IIS7 has all the RSCA (runtime status and control APIs) functionality exposed as dynamic properties through configuration system (read more here). One of the things RSCA let you do is expose custom runtime data from a worker process using GetCustomData method. You can call GetCustomData method for a worker process instance which sends a GL_RSCA_QUERY notification to the worker process. Once this notification is generated, IIS core engine then calls all the modules which subscribed to GL_RSCA_QUERY global notification. These modules can then return any runtime data they want to which is seen as the return value of GetCustomData method. RequestMonitorModule is one example of such module which subscribes to RQ_BEGIN_REQUEST, RQ_END_REQUEST to keep track of requests getting processed and also subscribes to GL_RSCA_QUERY to expose this requests in flight data through RSCA. CGlobalModule::OnGlobalRscaQuery method which gets invoked on GL_RSCA_QUERY event accepts IGlobalRSCAQueryProvider as an argument which can be used to get the function name (referred to as GuidOfFunctionCall in rscaext.xml), function parameters and also to set the return value of GetCustomData. For more information on IGlobalRSCAQueryProvider, go here.
Lets see a sample module which returns appPoolName when GL_RSCA_QUERY is issued with function name “AppPoolNameMethod”.
#include <windows.h>
IHttpServer * g_pGlobalInfo = NULL;
class SampleGlobalModule : public CGlobalModule
GLOBAL_NOTIFICATION_STATUS
HRESULT hr = S_OK;
//
//
// If function name/guid is not as
//
//
//
// Use to resize the buffer. Not used.
//
//
finished:
if(SUCCEEDED(hr))
VOID Terminate()
delete this;
__declspec(dllexport)
//
//
//
Installing the module
For adding this module to the pipeline, add an entry like following to <system.webServer/globalModules> section.
As the module is not subscribing to any request notifications, you don’t need to add this to <system.webServer/modules> section.
Javascript sample calling GetCustomData using AhAdmin APIs
Sample below shows how to make the call to GetCustomData method passing in the function name/parameters and how to retrieve output. IGlobalRSCAQueryProvider makes you return the output as a byte array but configuration system does base64 encoding of the byte array to return it as string. You have to do base64 decoding of the output you get from configuration system to get the actual byte array returned by OnGlobalRscaQuery method. You are free to interpret this byte array as you wish.
//
//
//
var defAppPool = section.Collection.Item(0);
//
var wp = wps.Collection.Item(0);
//
//
//
//
function base64decode(input)
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
ch1 = (e1 << 2) | (e2 >> 4);
output = output + String.fromCharCode(ch1);
return output;
This sample is not doing something very useful but few interesting things you can do using this functionality is expose list of items in file/token/memory cache (might not be straight forward to keep track of current list), calculate and expose some custom performance counters, trigger custom actions in the worker process like clearing cache entries for a user etc.
Let me know if you have any questions or need help exposing some data.
Kanwal