question

RaulChiarella-2175 avatar image
0 Votes"
RaulChiarella-2175 asked ObaidFarooqi-8403 edited

Typeperf: How to check if a Service/Proccess is currently running?

Hello there!

I would like to know the counter for typeperf used for monitoring a proccess/service status...

Example: typeperf "\Process(AnyDesk)\Is it running?"

I expect this command to return a True or False statement (1 or 0)
Is this possible to achieve using typeperf?

Thanks in advance!

windows-serverwindows-10-generalwindows-10-hardware-performancewindows-server-management
· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Raul

It appeared your question is not related to Open Specifications Protocol outline here https://aka.ms/openspecs. Openspecs-windows tag is removed from the post.

0 Votes 0 ·

Thanks! I did not know.
I saw a similar question regarding Typeperf that contained that same tag so i thought i was correct adding it to my question as well!

Sorry for the incovenience.

0 Votes 0 ·

Hi,


Just checking in to see if the information provided by MotoX80 was helpful. Please let us know if you would like further assistance.


Best Regards,
Sunny

0 Votes 0 ·

I will use Typeperf to generate a status of a service - It has to contain 0 or 1...
The result will be used in Zabbix Monitoring Tool

So i dont think that the powershell script will help me...

0 Votes 0 ·
MotoX80 avatar image MotoX80 RaulChiarella-2175 ·

Why do you want to use typeperf? That's not what it was designed for.

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/typeperf

The typeperf command writes performance data to the command window or to a log file. To stop typeperf, press CTRL+C.

It'd not going to return a 0 or 1, it's going to produce console output and your monitoring tool is going to have to "press CTRL+C" to stop it.


0 Votes 0 ·
Show more comments
MotoX80 avatar image
0 Votes"
MotoX80 answered MotoX80 commented

I'm sure that it's possible somehow with typeperf, but I think that Powershell would be a better tool to use.


  param ($ComputerName = "")
     
  $np = get-process -Name notepad -ComputerName $ComputerName -ErrorAction SilentlyContinue
  If ($np.count -eq 0) {
      "Notepad is not running."
  } else {
      "There are {0} instances of Notepad that are running." -f $np.Count
  } 
  try {
      $svc = Get-Service -Name LanmanServer -ComputerName $ComputerName -ErrorAction Stop
      if ($svc.Status -eq 'Running') {
          "LanmanServer is running." 
      } else {
          "LanmanServer is NOT running." 
      }
  } catch {
      "Error, the LanmanServer service is not defined."
  }
· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello,
Thanks for your reply!

That script is very usefull, i will save it.

Regarding my question: Unfortunately this will not solve my problem since i need Typeperf because i will use it with Zabbix Monitoring Tool...
And i will use Typeperf to check if the service is running...

I do not know how to integrate scripts with Zabbix - For example i could use your script to generate a 1 or 0 value and just check using Zabbix but i have no clue how to do that!!
Thats why im trying to find a way to do this using Typeperf...

I saw that there are a LOT of counters for Typeperf but i did not see a single one that returned if the service is running or not...

0 Votes 0 ·
MotoX80 avatar image MotoX80 RaulChiarella-2175 ·

From my experience, typeperf is the wrong tool to use to do this.

I have no experience with this Zabbix tool. Let's assume for a minute that typeperf could do what you want it to do. When you define the monitor, you will need to tell Zabbix the program name to execute (typeperf.exe) and an argument to pass to it (the counter name).

If you can do that, then it should be just as easy to tell Zabbix to run Powershell.exe and for the argument give it the name of a script to execute.

I do not understand why you are focused on using typeperf.

0 Votes 0 ·

Because Typeperf can be executed remotelly...
If i use a powershell script i will need to do on all machines that i need to monitor!

Lets say that i need to check if Anti Virus program is running on 200 machines on a domain...
With typeperf i can just use my Active Directory Administrator Login and execute typeperf remotelly just fine.

It works on all machines... And i can do it remotelly from one place only!
But how will i execute this script remotelly on all machines?


I will need to enter each one of them and create this script manually...
Or is it possible to execute this script remotelly? If it is possible, how to achieve that?

0 Votes 0 ·
Show more comments
Castorix31 avatar image
0 Votes"
Castorix31 answered

You can use Tasklist command and parse the result

For example, test if Windows Defender service is running :

 tasklist /svc /fi "SERVICES eq Windefend"
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.