New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Nginx status monitor sensor

Votes:

0

Your Vote:

Up

Down

Is there a way we can create a custom monitor from nginx_status? The output can be like:

Active connections: 1 server accepts handled requests 19 19 28 Reading: 0 Writing: 1 Waiting: 0

nginx prtg webserver

Created on Apr 10, 2014 9:36:03 PM by  rajeshkodali (0) 1



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 14 or later

Using PRTG to Monitor Nginx Status

You can monitor the status page of nginx and see the corresponding values by creating an EXE/Script Advanced sensor which uses the PowerShell script given below.

Note: The script might not properly work with newer versions of Nginx and probably requires some modifications. As an alternative, you can try the REST Custom sensor with an appropriate template.

Set up Monitoring of Nginx Status

  • Open a text editor.
  • Copy the following code and paste it into the editor:
Param([string]$url)
$warningpreference = "silentlyContinue"


    $global:resultText = "OK"

# create a table to store the information 
    $table = New-Object system.Data.DataTable "result"
    $col1 = New-Object system.Data.DataColumn channel,string
    $col2 = New-Object system.Data.DataColumn value,string
    $col3 = New-Object system.Data.DataColumn unit,string
    $col4 = New-Object system.Data.DataColumn customUnit,string
    $col5 = New-Object system.Data.DataColumn warning,string
    $col6 = New-Object system.Data.DataColumn float,string
    $col7 = New-Object system.Data.DataColumn mode, string
    
    $table.columns.add($($col1))
    $table.columns.add($($col2))
    $table.columns.add($($col3))
    $table.columns.add($($col4))
    $table.columns.add($($col5))
    $table.columns.add($($col6))
    $table.columns.add($($col7))
    
# To get this script running with PRTGNetworkMonitor you need to enable RemoteSigned-scripting for 32bit-processes. 
# This can be done with running 'c:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe "Set-ExecutionPolicy RemoteSigned"' on a system with default paths

# this function produces a well-formated xml-output out of a given table
function New-Xml
{
    param($RootTag="ROOT",$ItemTag="ITEM", $ChildItems="*", $TextTag="OK", $Attributes=$Null)

    Begin {
        $xml = "<$RootTag>`n"
    }

    Process {
        $xml += "  <$ItemTag>`n"
        
    foreach ($child in $_ | Get-Member -Type *Property $childItems)
    {
        $Name = $child.Name
        if (-not "$($_.$name)" -eq "")  {
            $xml += "    <$Name>$($_.$Name)</$Name>`n"
        }
    }
        $xml += "  </$ItemTag>`n"
    }

    End {
        $xml += "  <text>$TextTag</text>`n" 
        $xml += "</$RootTag>`n"
        $xml
    }
} 


    $web = New-Object Net.WebClient
    Try {
        $response = $web.DownloadString($url)
    } 
    Catch {
        Write-Warning "$($error[0])"
    }
    # Stubbing input for development:
    #$response="Active connections: 291`r`n
#server accepts handled requests`r`n
#  16630948 16630949 31070465`r`n
#Reading: 6 Writing: 179 Waiting: 106"

    $responseArray = $response.split(“`r`n”)

    ForEach ($responseLine in $responseArray){
      if ($responseLine.startswith('Active')) {
        $keyval = $responseLine.split(":") 
        $row = $table.NewRow();
        $row.channel = "$($keyval[0])";
        $row.value = $keyval[1]
        $row.unit  = "Count"
        $row.mode  = "absolute"
        $table.Rows.Add($row)
      }
      if ($responseLine.startswith('Reading:')) {
        ($responseLine -match "Reading: [0-9]+") | out-null 
          $keyval = $matches[0].split(": ")
          $row = $table.NewRow();
          $row.channel = "$($keyval[0])";
          $row.value = $keyval[2]
          $row.unit  = "Count"
          $row.mode  = "absolute"
          $table.Rows.Add($row)
        ($responseLine -match "Writing: [0-9]+") | out-null 
          $keyval = $matches[0].split(": ")
          $row = $table.NewRow();
          $row.channel = "$($keyval[0])";
          $row.value = $keyval[2]
          $row.unit  = "Count"
          $row.mode  = "absolute"
          $table.Rows.Add($row)
        ($responseLine -match "Waiting: [0-9]+") | out-null 
          $keyval = $matches[0].split(": ")
          $row = $table.NewRow();
          $row.channel = "$($keyval[0])";
          $row.value = $keyval[2]
          $row.unit  = "Count"
          $row.mode  = "absolute"
          $table.Rows.Add($row)
      }
      if (!$responseLine.length -eq 0 -and ! $responseLine.startswith('Active connections:') -and ! $responseLine.startswith('server') -and ! $responseLine.startswith('Reading:')) {
        $values = $responseLine.trim().split(" ")
        $row = $table.NewRow();
          $row.channel = "Accepts";
          $row.value = "$($values[0])"
          $row.unit  = "Count"
          $row.mode  = "difference"
          $table.Rows.Add($row)
        $row = $table.NewRow();
          $row.channel = "Handled";
          $row.value = $values[1]
          $row.unit  = "Count"
          $row.mode  = "difference"
          $table.Rows.Add($row)
          $row = $table.NewRow();
        $row.channel = "Requests";
          $row.value = $values[2]
          $row.unit  = "Count"
          $row.mode  = "difference"
          $table.Rows.Add($row)
      }
    }

# forward the generated table to xml-generator and store the result
    $retval = $table | New-Xml -RootTag prtg -ItemTag result -ChildItems Channel,Value,Unit,CustomUnit,Warning,Float,Mode -TextTag $resultText

# return the result
    write-host $retval
  • Save the file and name it, e.g., nginx_status.ps1
  • Place the script in the \Custom Sensors\EXEXML sub-directory of your PRTG installation to ensure that the EXE/Script Advanced sensor can pick up the same.
  • Create a new EXE/Script Advanced Sensor .
    • Choose nginx_status.ps1 as executable.
    • As Parameter, pass the URL to the nginx status page to the sensor.

The sensor will now read the status page and you should see the values reflected in the sensor's channels.

Best regards

Created on Apr 14, 2014 11:21:27 AM by  Konstantin Wolff [Paessler Support]

Last change on Dec 21, 2017 11:11:40 AM by  Gerald Schoch [Paessler Support]



6 Replies

Votes:

0

Your Vote:

Up

Down

Is there a way we can create a custom monitor for nginx from nginx_status? The output of http://ip/nginx_status is:

Active connections: 1 server accepts handled requests 19 19 28 Reading: 0 Writing: 1 Waiting: 0

Is there a way to monitor above values from the page?

Created on Apr 11, 2014 7:27:37 AM by  rajeshkodali (0) 1



Accepted Answer

Votes:

0

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 14 or later

Using PRTG to Monitor Nginx Status

You can monitor the status page of nginx and see the corresponding values by creating an EXE/Script Advanced sensor which uses the PowerShell script given below.

Note: The script might not properly work with newer versions of Nginx and probably requires some modifications. As an alternative, you can try the REST Custom sensor with an appropriate template.

Set up Monitoring of Nginx Status

  • Open a text editor.
  • Copy the following code and paste it into the editor:
Param([string]$url)
$warningpreference = "silentlyContinue"


    $global:resultText = "OK"

# create a table to store the information 
    $table = New-Object system.Data.DataTable "result"
    $col1 = New-Object system.Data.DataColumn channel,string
    $col2 = New-Object system.Data.DataColumn value,string
    $col3 = New-Object system.Data.DataColumn unit,string
    $col4 = New-Object system.Data.DataColumn customUnit,string
    $col5 = New-Object system.Data.DataColumn warning,string
    $col6 = New-Object system.Data.DataColumn float,string
    $col7 = New-Object system.Data.DataColumn mode, string
    
    $table.columns.add($($col1))
    $table.columns.add($($col2))
    $table.columns.add($($col3))
    $table.columns.add($($col4))
    $table.columns.add($($col5))
    $table.columns.add($($col6))
    $table.columns.add($($col7))
    
# To get this script running with PRTGNetworkMonitor you need to enable RemoteSigned-scripting for 32bit-processes. 
# This can be done with running 'c:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe "Set-ExecutionPolicy RemoteSigned"' on a system with default paths

# this function produces a well-formated xml-output out of a given table
function New-Xml
{
    param($RootTag="ROOT",$ItemTag="ITEM", $ChildItems="*", $TextTag="OK", $Attributes=$Null)

    Begin {
        $xml = "<$RootTag>`n"
    }

    Process {
        $xml += "  <$ItemTag>`n"
        
    foreach ($child in $_ | Get-Member -Type *Property $childItems)
    {
        $Name = $child.Name
        if (-not "$($_.$name)" -eq "")  {
            $xml += "    <$Name>$($_.$Name)</$Name>`n"
        }
    }
        $xml += "  </$ItemTag>`n"
    }

    End {
        $xml += "  <text>$TextTag</text>`n" 
        $xml += "</$RootTag>`n"
        $xml
    }
} 


    $web = New-Object Net.WebClient
    Try {
        $response = $web.DownloadString($url)
    } 
    Catch {
        Write-Warning "$($error[0])"
    }
    # Stubbing input for development:
    #$response="Active connections: 291`r`n
#server accepts handled requests`r`n
#  16630948 16630949 31070465`r`n
#Reading: 6 Writing: 179 Waiting: 106"

    $responseArray = $response.split(“`r`n”)

    ForEach ($responseLine in $responseArray){
      if ($responseLine.startswith('Active')) {
        $keyval = $responseLine.split(":") 
        $row = $table.NewRow();
        $row.channel = "$($keyval[0])";
        $row.value = $keyval[1]
        $row.unit  = "Count"
        $row.mode  = "absolute"
        $table.Rows.Add($row)
      }
      if ($responseLine.startswith('Reading:')) {
        ($responseLine -match "Reading: [0-9]+") | out-null 
          $keyval = $matches[0].split(": ")
          $row = $table.NewRow();
          $row.channel = "$($keyval[0])";
          $row.value = $keyval[2]
          $row.unit  = "Count"
          $row.mode  = "absolute"
          $table.Rows.Add($row)
        ($responseLine -match "Writing: [0-9]+") | out-null 
          $keyval = $matches[0].split(": ")
          $row = $table.NewRow();
          $row.channel = "$($keyval[0])";
          $row.value = $keyval[2]
          $row.unit  = "Count"
          $row.mode  = "absolute"
          $table.Rows.Add($row)
        ($responseLine -match "Waiting: [0-9]+") | out-null 
          $keyval = $matches[0].split(": ")
          $row = $table.NewRow();
          $row.channel = "$($keyval[0])";
          $row.value = $keyval[2]
          $row.unit  = "Count"
          $row.mode  = "absolute"
          $table.Rows.Add($row)
      }
      if (!$responseLine.length -eq 0 -and ! $responseLine.startswith('Active connections:') -and ! $responseLine.startswith('server') -and ! $responseLine.startswith('Reading:')) {
        $values = $responseLine.trim().split(" ")
        $row = $table.NewRow();
          $row.channel = "Accepts";
          $row.value = "$($values[0])"
          $row.unit  = "Count"
          $row.mode  = "difference"
          $table.Rows.Add($row)
        $row = $table.NewRow();
          $row.channel = "Handled";
          $row.value = $values[1]
          $row.unit  = "Count"
          $row.mode  = "difference"
          $table.Rows.Add($row)
          $row = $table.NewRow();
        $row.channel = "Requests";
          $row.value = $values[2]
          $row.unit  = "Count"
          $row.mode  = "difference"
          $table.Rows.Add($row)
      }
    }

# forward the generated table to xml-generator and store the result
    $retval = $table | New-Xml -RootTag prtg -ItemTag result -ChildItems Channel,Value,Unit,CustomUnit,Warning,Float,Mode -TextTag $resultText

# return the result
    write-host $retval
  • Save the file and name it, e.g., nginx_status.ps1
  • Place the script in the \Custom Sensors\EXEXML sub-directory of your PRTG installation to ensure that the EXE/Script Advanced sensor can pick up the same.
  • Create a new EXE/Script Advanced Sensor .
    • Choose nginx_status.ps1 as executable.
    • As Parameter, pass the URL to the nginx status page to the sensor.

The sensor will now read the status page and you should see the values reflected in the sensor's channels.

Best regards

Created on Apr 14, 2014 11:21:27 AM by  Konstantin Wolff [Paessler Support]

Last change on Dec 21, 2017 11:11:40 AM by  Gerald Schoch [Paessler Support]



Votes:

3

Your Vote:

Up

Down

If you're merely interested in recording the connection information from the status page, you can use the embedded variables that the status module exposes, and format them for consumption by the HTTP Content sensor directly in the NGINX configuration:

location /prtg {
    return 200 [$connections_active][$connections_reading][$connections_writing][$connections_waiting];
    access_log off;
    allow x.x.x.x/y;
    deny all;
}

Reference:

Created on Jun 15, 2018 3:00:15 AM by  ek (50)

Last change on Nov 27, 2018 6:43:17 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Thanks for your suggestion to return the module variables, Luciano.

I am reading the values with a http content sensor, but I can not rename the names of the created channels - making the connected values rather useless.

Did I overlook something in the setup, or is it not possible to change the channel names during setup or after creation?

Created on Nov 26, 2018 12:58:44 PM by  jkrem (0)

Last change on Nov 27, 2018 6:43:30 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello jkrem,
thank you for your reply.

It was actually ek's suggestion, I just adjusted the formatting of the reply a bit. :)

Can you place the variables in a XML-Like (or JSON-like) document that looks like this?

<?xml version="1.0" encoding="utf-8" ?>
<prtg>
	<result>
		<channel>Connections Active</channel>
		<value>[$connections_active]</value>
	</result>
	<result>
		<channel>Connections Reading</channel>
		<value>[$connections_reading]</value>
	</result>
	<text>The sensor's message</text>
</prtg>

This example shows only two channels, but in theory it could be up to 50. For a more complex example, please refer to:

The full API documentation for Custom Sensors is available in PRTG itself under Setup > PRTG API

If the above is an option, you can define the name of the channels in advance and use the HTTP Data Advanced Sensor. Otherwise, the issue with not being able to rename the channels is a known bug in PRTG, that we hope to fix very soon.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Nov 27, 2018 6:50:03 AM by  Luciano Lingnau [Paessler Support]

Last change on Nov 27, 2018 6:52:24 AM by  Luciano Lingnau [Paessler Support]



Votes:

2

Your Vote:

Up

Down

Just an FYI, the channel rename bug is fixed with 18.4.47.1962 :)


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team

Created on Jan 9, 2019 12:06:42 PM by  Stephan Linke [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.