Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Buffering and High Availability

Use PowerShell scripts to monitor AF Health Check counter

Use PowerShell scripts to monitor AF Health Check counter

  • Last UpdatedJun 27, 2023
  • 1 minute read

If you are unable to run Internet Information Services (IIS) on your system, you might use Windows PowerShell scripts to create a listener to monitor the AF Server Health tag, as demonstrated by the following example code fragments.

  1. Create a listener.

    For example:

    $endpoint = new-object System.Net.IPEndPoint
    ([system.net.ipaddress]::any, $port)

    $listener = new-object System.Net.Sockets.TcpListener
    $endpoint

    $listener.start()

  2. Read the AF Server Health tag.

    For example:

    $counter_path = "\PI AF Server\Health"

    $counters_value = get-counter -counter $counter_path |
    Select-Object –ExpandProperty CounterSamples |
    Select-Object CookedValue

  3. Parse the response.

    For example:

    $Pass = Select-String -inputObject $counters_value
    -pattern "CookedValue=1" -quiet

    If ($Pass){$responseString=$up}else{$responseString=$down}

  4. Send the response to the listener.

    For example:

    $sendBytes = [System.Text.Encoding]::ASCII.GetBytes($responseString) + $CR + $LF

    $stream.Write($sendBytes,0,$sendBytes.Length)

TitleResults for “How to create a CRG?”Also Available in