I have a windows service that spawns off around 60 threads when it starts. I am using Nagios for general monitoring and I have all necessary routines to send data to nagios. However, I cannot figure out how to get a sum of all threads and make sure that none of them are dead.
Basically what I want to do is:
foreach(thread t in threadPool)
{
if(t.isAlive())
{
PingHost(t.ThreadID);
}
}
It doesn’t seem like this should be very difficult, but I am not sure where to start.
I recommend adding each thread to a
Dictionary<int, Thread>keyed by itsManagedThreadId. Then pass a callback method to each thread that returns itsManagedThreadIdwhen it terminates. The callback then removes the thread from the dictionary and informs Nagios.You can use the thread’s Name property for basic descriptive data, or create a custom object to hold other information about the process and store that inthe dictionary instead of the thread.