Skip to content

Instantly share code, notes, and snippets.

@tareqy
Created August 30, 2018 17:22
Show Gist options
  • Select an option

  • Save tareqy/7ff62746fadb0ded7a1058453209c77f to your computer and use it in GitHub Desktop.

Select an option

Save tareqy/7ff62746fadb0ded7a1058453209c77f to your computer and use it in GitHub Desktop.

Revisions

  1. tareqy created this gist Aug 30, 2018.
    73 changes: 73 additions & 0 deletions PhpFpmStats.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@

    param(
    [string]$url
    );

    $status_page = Invoke-WebRequest -uri $url -UseBasicParsing

    $statistics = ,@("value","name")

    # listen queue
    $status_page.RawContent -match '(listen queue:\s+)(\d+)' | Out-Null
    $statistics += ,@($matches[2],"listen queue")

    # max listen queue
    $status_page.RawContent -match '(max listen queue:\s+)(\d+)' | Out-Null
    $statistics += ,@($matches[2],"max listen queue")

    # listen queue len
    $status_page.RawContent -match '(listen queue len:\s+)(\d+)' | Out-Null
    $statistics += ,@($matches[2],"listen queue")

    # idle processes
    $status_page.RawContent -match '(idle processes:\s+)(\d+)' | Out-Null
    $statistics += ,@($matches[2],"idle processes")

    # active processes
    $status_page.RawContent -match '(active processes:\s+)(\d+)' | Out-Null
    $statistics += ,@($matches[2],"active processes")

    # total processes
    $status_page.RawContent -match '(total processes: \s+)(\d+)' | Out-Null
    $statistics += ,@($matches[2],"total processes")

    # max active processes
    $status_page.RawContent -match '(max active processes:\s+)(\d+)' | Out-Null
    $statistics += ,@($matches[2],"max active processes")

    # max children reached
    $status_page.RawContent -match '(max children reached:\s+)(\d+)' | Out-Null
    $statistics += ,@($matches[2],"max children reached")

    # slow requests
    $status_page.RawContent -match '(slow requests:\s+)(\d+)' | Out-Null
    $statistics += ,@($matches[2],"slow requests")

    Write-Host @"
    <PRTG>
    "@

    for ($i=1; $i -lt $statistics.Count; $i++){
    Write-Host @"
    <result>
    <channel>$($statistics[$i][1])</channel>
    <value>$($statistics[$i][0])</value>
    <Float>0</Float>
    <unit>Count</unit>
    "@

    if($statistics[$i][1] -eq "listen queue" -or $statistics[$i][1] -eq "listen queue len"){
    Write-Host @"
    <LimitMode>200</LimitMode>
    <LimitMaxError>200</LimitMaxError>
    "@
    }

    Write-Host @"
    </result>
    "@
    }

    Write-Host @"
    </PRTG>
    "@