Solved

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

Posted on 2014-11-26
8
80 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 34

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 34

Expert Comment

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

-saige-
0
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
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 34

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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