Pandora FMS Community

Service/Process Monitoring Windows Agent

BSOD · 25 jun 2012, 20:42 · 4 mensajes · 72 visitas

  1. Inicio del debate

    Hi, First off, forgive me if this is in the wrong section. If an Admin wants to change the this location of this for me then feel free. Hope someone can help with a something I want to implement. I want to monitor a service/process by how much CPU usage it takes up i.e. once the CPU usage for this particular service goes above 50% it is flagged by Pandora FMS and then either is highlighted in the Agent/Modules view or it sends an email to an Admin. Either will suffice. I have successfully monitored a service and it shows up but was wondering if anyone had implemented this in a Windows environment. I have seen some tutorials for Unix boxes but nothing for a Windows shop. This is the Service check I have setup currently as a test, so it probably has something to do with entering a PID or process name somewhere with a script check to perfmon (maybe not as complicated as that) I would presume? # Check Service Module module_begin module_name Service_Dhcp module_type generic_proc module_service Dhcp module_description Service DHCP Client module_end Using Verision 4.0.1 Build 111220 Any help appreciated

  2. That is a boolean module which only returns 1 if the service status is OK and 0 if it's something wrong. It's a little bit more complex to find out the CPU usage of a service since the service listing via command lines only returns the status, and not the CPU usage of the process associated to this service. Besides, the performance monitor can return the CPU usage of a process, but since in this case, several services are executed by the same process with different parameters, (svchost) there's no way you can find out which of the running svchosts is the one you want to monitor using the performance monitor only. With the process listing, you are able to get the CPU usage of a process, and it is also possible with another parameter set, to know which services are linked to which process... however, you cannot get the value you need in a single execution, since by listing from the command line, you get it in CPU Time (hh:mm:ss) format, which is not really useful when it comes to monitoring. So... you'd need a small script to store the info you need from both tasks and use the CPU usage of that process as the script output... ...unless you use Powershell. Once again, if you have Powershell installed in your Windows system, you're lucky, since everything can be done with a Powershell one-liner script, and you will be able to execute it in a single instruction, with module_exec. If you execute the following code in the command line:

    Powershell.exe -command "tasklist /SVC | grep Dhcp | foreach-object { $test = echo $_ | gawk '{print $2}'; get-process | select-object -Property * | where-object {$_.Id -match $test} | foreach-object { echo $_.CPU }}"
    

    It should return the CPU usage of the svchost process associated to the Dhcp service. A small explanation of what it does:

    First, you execute from cmd the Powershell CLI, then you execute the command. In this command, first you get the process list "cmd style" with the services linked to each process, then you filter that list to get only the line of the process linked to the Dhcp service, and then you get the PID of the process. Once you have it, you can use the Powershell cmdlet "get-process", which does the same thing tasklist does, but with a better organisation, storing each data from each process in objects, and providing the CPU values in the format we need. Finally, the only thing you have to do is to match the PIDs from the new list with the one you gathered before, and extract the CPU value for the resulting object.

    Now you can insert this command as the module_exec parameter of your software agent module, and either define warning and critical ranges from the Pandora Console, or from the agent configuration file (however, the last option is only possible from v4.0) Using the first option, the module in pandora_agent.conf would be like this:

    module_begin
    module_name Dhcp_CPU_Usage
    module_type generic_data
    module_exec Powershell.exe -command "tasklist /SVC | grep Dhcp | foreach-object { $test = echo $_ | gawk '{print $2}'; get-process | select-object -Property * | where-object {$_.Id -match $test} | foreach-object { echo $_.CPU }}"
    module_end
    

    And with the other one, like this:

    module_begin
    module_name Dhcp_CPU_Usage
    module_type generic_data
    module_min_warning 25
    module_max_warning 50
    module_min_critical 50
    module_max_critical 100
    module_exec Powershell.exe -command "tasklist /SVC | grep Dhcp | foreach-object { $test = echo $_ | gawk '{print $2}'; get-process | select-object -Property * | where-object {$_.Id -match $test} | foreach-object { echo $_.CPU }}"
    module_end
    

    Feel free to use whatever you want. ;) Regarding the highlighting, that's the idea of the critical status of the module. Regarding the email to an Admin, you can always set up an alert with template "email to XXX", modify the recipient to the Admin email, and link your module to this alert. If you need more information about setting up alerts and configuring the server MTA to send the emails, you can try reading these links. Pandora FMS Alert System (Link not available anymore) Pandora FAQ: Configuring the email server for alert emails (Link not available anymore) Pandora FAQ: Problems receiving mails after alert triggering (Link not available anymore) Pandora FAQ: Emails not being sent properly from Pandora FMS Server (Link not available anymore) If I'm ever bored enough/have enough time/feel like doing it, I'll write a small ps1 script which would use the Service name or other conditions as parameters, to extract these values automatically. Regards.

  3. I am having the issue where I can run the command in powershell but when I translate it to a pandora module it doesn't show up: when run in powershell: PS C:Usersxxxxxx> ([System.Net.DNS]::GetHostAddresses('xxxxxxxx') | Where-Object {$_.AddressFamily -eq "InterNetwork"} | select-object IPAddressToString)[0].IPAddressToString 10.XXX.XXX.XXX Pandora module: #Shows current IP Address module_begin module_name IP Address module_type generic_data_string module_exec powershell.exe -command "([System.Net.DNS]::GetHostAddresses('xxxxxxxxx') | Where-Object {$_.AddressFamily -eq "InterNetwork"} | select-object IPAddressToString)[0].IPAddressToString" module_description Current IP Address module_end the log shows: 2016-09-13 22:29:54 Pandora_Module_Exec: IP Address did not executed well (retcode: 1) 2016-09-13 22:34:56 Pandora_Module_Exec: IP Address did not executed well (retcode: 1) 2016-09-13 22:39:55 Pandora_Module_Exec: IP Address did not executed well (retcode: 1)

  4. Hello mhall246, The problem with your configuration are quotes. See that you have this: module_begin module_name IP Address module_type generic_data_string module_exec powershell.exe -command "([System.Net.DNS]::GetHostAddresses('xxxxxxxxx') | Where-Object {$_.AddressFamily -eq "InterNetwork"} | select-object IPAddressToString)[0].IPAddressToString**"** module_description Current IP Address module_end As you can see, quotes are wrong paired, so the command execution isn't correct. Using this configuration it should work: module_begin module_name IP Address module_type generic_data_string module_exec powershell.exe -command "([System.Net.DNS]::GetHostAddresses('xxxxxxxxx') | Where-Object {$_.AddressFamily -eq 'InterNetwork'} | select-object IPAddressToString)[0].IPAddressToString**"** module_description Current IP Address module_end Kind regards, Enrique.

Entra en tu cuenta para publicar.