Solved

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

Posted on 2014-11-26
8
74 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 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