Here are instructions to set up a Windows Powershell data collector to monitoring the status of any windows service.
1. In your Dotcom-Monitor account, set up a MetricsView Custom Collector:
2. Setup a Custom Metrics device. Select the Collector created at the pervious step. Fill out the Custom Counter Path. Set the Aggregate type to Minimum or Maximum.
The service status can be in 7 states. By default they are transformed into values:
- Service is stopped – default 1000
- Service is starting – default 2000
- Service is stopping – default 3000
- Service is running – default 4000
- Service is resuming work after pause – default 5000
- Service is pausing – default 6000
- Service is paused – default 7000
We recommend using Minimum, so you can set your Minimum threshold to anything less than 2000 to detect the “Service is Stopped” event.
Leave the remaining fields at their default values.
3. To receive the script, create a Trouble Ticket from within your account.
4. On the target computer, open Powershell as administrator.
5. Navigate to the directory where ServiceMonitoring.ps1 is installed, for example, we created a folder in the c: drive:
cd c:\ps\
6. Run the command:
set-executionpolicy unrestricted
7. Run the command:
.\ServiceMonitoring.ps1 -collector <Collector ID>-task < Task UID> -service <Service Name> -log
The Collector ID is found under Configure > MetricsView Collectors.
The Task UID is found in the device URL when editing the task.
The Service Name parameter should be spelled exactly as it shows up in the services window.
With the –log command you can verify if the script is working correctly in the event viewer:
8. Set up the script to run periodically through Windows Task Scheduler or any other tool you use to run scripts.
Additional Information about the Script
To get built-in help, execute:
.\ServiceMonitoring.ps1
The -log key enables logging to EventLog “Windows Logs/Application”. By default, the logging is done to the Microsoft Management Consol only.
The service status can be in 7 states. By default, they are transformed into values:
- Service is stopped – default 1000
- Service is starting – default 2000
- Service is stopping – default 3000
- Service is running – default 4000
- Service is resuming work after pause – default 5000
- Service is pausing – default 6000
- Service is paused – default 7000
These values can be set to any other values using command line keys:
-stopped <number> -starting <number> -stopping <number> -running <number> -continuing <number> -pausing <number> -paused <number>
-
Why Dotcom-Monitor Can Help You Monitor Windows Services
A service, or Windows service, is a background application that can be launched in various ways. A service can be started automatically on Windows start or started if another application needs it for its work. Windows Services run in the background and usually don’t interact with users. Most services can be stopped by a user, but there are also those that cannot be stopped since they are necessary for the normal operation of some components of the operating system.
Typically, various servers are implemented as the services (for example, database servers), monitoring utilities, and other applications that can work completely independently of user actions. Windows OS has a lot of its own services, and you can work with them as well as with other custom services from the Task Manager > Services or by running services.msc from the command line.
So why is it so important to monitor Windows Services? One of the important criteria of a server’s performance is the state of its Windows services. There are some critical Windows services that must be up continuously while the server is up.
Also, there are a lot of applications such as Active Directory that are using their services running on a Windows server. Or, for example, you have created your own software that uses multiple custom services installed on a Windows server to work. If these services are an essential part of the applications, they must be running without any errors.
Thus, monitoring of Windows services on the servers is one of the main tasks of a system administrator to keep tabs on the server performance.
Monitoring the State of Windows Services with Powershell
To monitor the status of Windows services you can use Powershell. For example, using the Get-Service cmdlet, you can get a list of all services installed on the system, their status and startup type:
PS C:\Windows\system32> Get-Service
This command will list all services and their status (started or stopped) and display names. With some scripting experience, it is possible to configure a custom Windows services monitoring solution on the Powershell’s commands (e.g., Get-Service, Get-Process, Send-MailMessage, etc. ) basis.
Using Dotcom-Monitor’s MetricsView Service for Windows Services Monitoring
Although using Powershell and custom scripts that are written for Windows services monitoring is a common approach, it becomes problematic when the number of monitored servers and services grows. In this case, it is recommended to use automated monitoring tools such as MetricsView by Dotcom-Monitor.
MetricsView allows users to set up monitoring of the services on the remote Windows servers. The tool does not require any Powershell scripting skills or deep knowledge in system administration from a user. Using a user-friendly graphical interface, one can install a MetricsView software on the target Windows server, create a monitoring task including error threshold, set up frequency and the scheduler of the monitoring, pull reports on the dynamics of the services. Moreover, MetricsView offers a built-in alert notification system to send notifications when the monitored services change their status.