|
DeepakG_[MS]: Today we are going to discuss Windows Management
Instrumentation..
DeepakG_[MS]: we have with us today Tarun Anand, who works as a
Technical Evangelist at Microsoft, India. Prior to joining Microsoft
in India, Tarun was working with Microsoft at Redmond as a developer
on the same CLR, that you and I see in action today...
DeepakG_[MS]: So I am sure he has lots of unique insights to offer.
Over to you Tarun, lets start with a brief intro to WMI..
Tarun_[MS]: Hi Folks
Tarun_[MS]: Long Long time ago there were different ways
of doing management based on what you were "managing" like networks,
os, apps etc etc. Each vendor had their own proprietary way of doing
the management of each piece.
Tarun_[MS]: So, as is usual in computer industry people saw
this as getting out of hand and wanted to have a unified way of
doing management
Tarun_[MS]: .... enter WBEM
Tarun_[MS]: or Web basaed Enterprise management - a standard
developed by DMTF org
Tarun_[MS]: The WBEM standard was implemented by many vendors
and WMI is Microsoft's implementation of that standard. The way
WMI works is that you have an app/os/device/network to be managed
a provider that provides you with the management information for
these managed objects a manager that keeps track of all providers
and stores their information in a repository and finally a consumer
that can ask the manager for information/events that it is interested
in
Tarun_[MS]: for e.g. a consumer app can send a mail to the
administrator when the cpu on a machine has reached 99% utilization,
for this it subscribes to the cpu utilization event via WMI and
it gets alerted when the "interesting" event occurs. That is a brief
intro to WMI.
DeepakG_[MS]: Is it possible to define my own events?
Tarun_[MS]: You can define your own events for this you have
to do 2 things -
Tarun_[MS]: define your event class in a .mof (Managed Object
Format) file and then define the appropriate WMI interfaces on the
event class in your class implementation. You also need to run mofcomp.exe
on the .mof file to register your events with WMI
DeepakG_[MS]: (Satya): The consumer can only request for the information
or can act on the provider basing on the information?
Tarun_[MS]: it can do both...
DeepakG_[MS]: (Saurabh_MVP): Tarun .. can u elaborate on the .mof
.. file and how to use it in .NET?
Tarun_[MS]: well .mof was used in the old days
Tarun_[MS]: instance of MSFT_AppProfEventSetting
{
ClassName = "MyCustomEvent";
Description = "My new custom event";
ProviderGUID = "{8F366B62-E078-4388-B601-C0AB493BDDDC}"; Type =
"Generic";
GUID = "{79AE076F-777E-461B-AF40-A3D4594EA3BC}";
}
Tarun_[MS]: so this is how you define the event in a .mof
file
Tarun_[MS]: in .net however your task is easier.... he ...
he... just like everything else you need to just put attributes
to your class/assembly to indicate the equivalent of .mof file
Tarun_[MS]: let me see if there is an example lying around
Tarun_[MS]: [assembly:Instrumented("Root/Default")]
// Let the system know you will
run InstallUtil.exe utility against
// this assembly
[System.ComponentModel.RunInstaller(true)]
public class MyInstaller: DefaultManagementProjectInstaller {} //
Create a management
public class MyEvent: System.Management.Instrumentation.BaseEvent
{
public string Event_Name;
}
public class Sample_EventProvider
{
public static int Main(string[] args)
{
MyEvent e = new MyEvent();
e.Event_Name = "Hello"; // Raise a management event
}
}
Tarun_[MS]: in short you are defining attributes on the assembly.
You are defining an event that inherits from BaseEvent and then
you can fire it using Instrumentation. Fire call in your app
DeepakG_[MS]: (Saurabh_MVP): Tarun .. I have heard Raj C talking
about the new "WMI Server" product .. can you shead .. some more
highlights of it ? And how will it help instrumentation in an distributed
scenario?
Tarun_[MS]: well .. don't know much about WMI Server but
I suspect it is an integrated server to help you manage various
objects in a distribute computing environment, like servers, OS,
storage etc etc... Instead of connecting to each server to monitor
it, you could go to this server to monitor your network.
DeepakG_[MS]: (Saurabh_MVP): hmmm that's intresting bit of code
.... but suppose I add instrumentation in my application .. how
much performance hit does a .NET application take? Since I believe
the current implementation of .NET is Interoping with unmanaged
code...
Tarun_[MS]: it will add a performance hit to your application,
so you will have to be careful which events you want to expose but
the interop layer is very thin and not that much of a bottleneck
as compared to the number of events, and information that you want
to expose
DeepakG_[MS]: (Saurabh_MVP): well Tarun, I was thinking of adding
a instrumentation in an enterprise application ... so that it can
be managed easily ... Saurabh_MVP: are there any other options ..
for adding Management and Instrumentation ?
Tarun_[MS]: well there are other options but if you want
to remain portable across the various windows platforms and want
a consistent api for any kind of management then go for WMI you
can also use the profiling apis/event log
DeepakG_[MS]: Let me give some examples of how you can use WMI in
day today life..Lets say you want to move to a new application across
your company. Now this application has some unique hardware requirements...
especially, lets say it requires more RAM. Now you need to take
stock of amount of RAM present in each machine in your enterprise
- how do you do that...
DeepakG_[MS]: WMI to the rescue..
DeepakG_[MS]: here is a code snippet that evaluates Physical Memory
of a machine..
DeepakG_[MS]: strComputer = "atl-dc-01"
Set wbemServices = GetObject("winmgmts:\\" & strComputer)
Set wbemObjectSet = wbemServices.InstancesOf("Win32_LogicalMemoryConfiguration")
For Each wbemObject In wbemObjectSet
WScript.Echo "Total Physical Memory (kb): " & wbemObject.TotalPhysicalMemory
Next
DeepakG_[MS]: so using AD, you can enumerate machines on your network
DeepakG_[MS]: and then go on using WMI to find amount of RAM present
in each machine. You can then do anything with that data - like
isolate machines that need hardware upgrades.
DeepakG_[MS]: (Justin): for example, wmi will send email to dba
when my sql database size reaches the hard disk limit. Is it what
the purpose of WMI ?
Tarun_[MS]: yes that is definitely up the alley of WMI. You
can do other interesting things as well.. audit violations for one
and load balancing based on load information given by WMI
DeepakG_[MS]: Ok then, with this we come to an end of this week's
chat session...
DeepakG_[MS]: Thanks Tarun for taking time out from your tight schedule..
|