locked
Powershell script to monitor Redis Cluster RRS feed

  • Question

  • I am trying to build a powershell script that monitors a Redis Cluster.   I use the Command Cluster Info which gives me the information on the cluster and the first line is cluster_state:ok.   If it is not OK I will want it to send out an email.

    What I am running into is how do I use the function indexof correctly to check this line to see if it ok.

    This is what I got so far.   How 

    $output = & 'd:\program files\redis\redis-cli' -h 10.162.209.126 cluster info

    $sp = $Output[14].Indexof(" ",14,16)

    Write-Host $sp

    Here is what the cluster info output looks like.

    127.0.0.1:6379> cluster info
    cluster_state:ok
    cluster_slots_assigned:16384
    cluster_slots_ok:16384
    cluster_slots_pfail:0
    cluster_slots_fail:0
    cluster_known_nodes:6
    cluster_size:3
    cluster_current_epoch:6
    cluster_my_epoch:3
    cluster_stats_messages_sent:4763894
    cluster_stats_messages_received:4763801
    127.0.0.1:6379>

    So what am I missing with the indexof function?  

    Wednesday, August 30, 2017 6:56 PM

All replies

  • This will work:

    $ci = @'
    cluster_state:ok
    cluster_slots_assigned:16384
    cluster_slots_ok:16384
    cluster_slots_pfail:0
    cluster_slots_fail:0
    cluster_known_nodes:6
    cluster_size:3
    cluster_current_epoch:6
    cluster_my_epoch:3
    cluster_stats_messages_sent:4763894
    cluster_stats_messages_received:4763801
    '@ -replace ':','='
    $data = $ci | ConvertFrom-StringData
    $data['cluster_state']
    


    \_(ツ)_/

    Wednesday, August 30, 2017 7:03 PM
  • You can do it like this:

    PS >$ci = (cluster info) -replace ':', '=' | Out-String
    PS >$data = $ci | ConvertFrom-StringData
    PS >$data['cluster_state']
    Ok


    \_(ツ)_/


    • Edited by jrv Wednesday, August 30, 2017 7:09 PM
    Wednesday, August 30, 2017 7:06 PM
  • I am getting the following output.

    PS C:\temp> C:\temp\Monitor Cluster.ps1
    ok
    = System.Collections.Hashtable

    What do I need to get to do to get rid of the extra info system.collections.hashtable?   

    Thursday, August 31, 2017 6:56 PM
  • You have to remove the unwanted output in your script.  Without the script we cannot be of much help.


    \_(ツ)_/

    Thursday, August 31, 2017 8:06 PM
  • Here is what I have so far.

     

    $redisHost = '10.162.209.126'
    $Arg = 'cluster info'

    $cmd1 =  "& 'd:\program files\redis\redis-cli' -h $redisHost $Arg"

    $otp1 = Invoke-Expression $cmd1 
    $otp2 = $otp1 -replace ':', '=' | Out-String | ConvertFrom-StringData
    $otp2['cluster_state']


    Write-host = $otp2

    Friday, September 1, 2017 11:48 AM
  • Don't  try to get fancy before you understand how it works.

    $redisHost = '10.162.209.126'
    $Arg = 'cluster info'
    
    $output = Start-Process "$env:ProgramFiles\redis\redis-cli" -args "-h $redisHost $Arg" -NoNewWindow | select -Skip 1
    $data = $output -replace ':','=' | Out-String | ConvertFrom-StringData
    $data['cluster_state']


    \_(ツ)_/

    Friday, September 1, 2017 4:20 PM