Solved

Identify CPU Utilization and restart the service if the CPU utilization is more

Posted on 2014-11-26
8
72 Views
Last Modified: 2014-12-21
Dear Experts,
 
  I've a windows service. If the service consumes more CPU utilization (say for instance 85% - which I could configure in config file and read in application) then I would like to restart the service. Could you please let me know how to achieve this?


Thanks.
0
Comment
Question by:Easwaran Paramasivam
  • 5
  • 3
8 Comments
 
LVL 33

Expert Comment

by:it_saige
ID: 40467067
You could throw an event that would tell the service to restart itself.  But then the question becomes, why is it consuming so much processor utilization?  Do you have an idea as to why your service does this?

-saige-
0
 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 40467420
Thanks. Some threads  are running for 2 days continuously. They are unmanaged threads. Hence could not identify the root cause of the issue. Please explain your solution how to achieve in code. Thanks.
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40467570
Sure thing.  Let me throw a project together for illustrative purposes.

-saige-
0
 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 40470279
@it_saige: Waiting for your response. Thanks.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 40475232
@it_saige: Could you please share the project?
0
 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 40499738
@it_saige: Awaiting your reply. Kindly assist.
0
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40503530
Here is a sample solution.  The solution itself, contains three projects:

1.  A service executable that is the ServiceFactory/ServiceBroker located in the EE_Q28570005 directory.
2.  A Common shared library in the Common directory.
3.  A SampleService library in the SampleService directory.

After you unzip this file, browse to the EE_Q2857005\Common\Resources directory and rename the file CommandLine.dll.zip to CommandLine.dll.

After you do this you can open the solution in VS2010 or higher.  Once you build the solution, the EE_Q28570005.exe file and the EE_Q28570005.Common.dll file can be placed into a directory on your system for testing.  The service contains an installer which can be initialized by starting a command prompt and running the command EE_Q28570005.exe -i.  To make the servicebroker listen for and start the sample service, you would use the command EE_Q28570005.exe -a SampleService.dll.  Note - These commands can be combined i.e. - EE_Q2857005.exe -i -a SampleService.dll.  A full list of command line options can be printed to the log file by simply typing EE_Q2857005.exe --help

The service broker also has a file watcher so once you drop the SampleService.dll into the directory that the service broker lives in, the SampleService will start.

SampleService would represent your current service.  SampleService contains an example ProcessorUtlization Event that is raised and that prints out a message to the log file.  Instead of printing out a message to the log file, you would utilize the service broker to stop and start (or restart) the SampleService.

Since the service broker uses a filewatcher, this also means that you can update your service (in this case SampleService) without needing to worry about stopping the service broker, you just inline replace the SampleService.dll with the updated version and the service broker stops the service and starts the code in the new version.

-saige-
EE-Q28570005.zip
0
 
LVL 16

Author Closing Comment

by:Easwaran Paramasivam
ID: 40512458
Thanks a lot.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now