Solved

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

Posted on 2014-11-26
8
70 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 32

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 32

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 32

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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.

757 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

21 Experts available now in Live!

Get 1:1 Help Now