Solved

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

Posted on 2014-11-26
8
78 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Author Comment

by:Easwaran Paramasivam
ID: 40470279
@it_saige: Waiting for your response. Thanks.
0
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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