Announcement

Collapse
No announcement yet.

Remote process monitoring

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Remote process monitoring

    I would like to be able to report back status of process on remote PC's and populate a status virt device in HS. Is that possible or has anyone done this?

    Cheers,

    Darren

    #2
    This should be fairly easy using System.Diagnostics.Process but the main problem as I see it is to get the information back to HS. My bet is that you would need a virtual device used for status (EDIT: which I see now you already have mentioned).

    And the script needs to be placed in an reoccuring event.
    Last edited by Moskus; December 8, 2009, 11:02 AM.
    HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
    Running on Windows 10 (64) virtualized
    on ESXi (Fujitsu Primergy TX150 S8).
    WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

    Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

    Comment


      #3
      Being somewhat interessted in this, I went ahead and wrote a suggestion to a script:

      Place the followng script in the \Script folder on your rempte computer. Rename it whatever you want, I've named it" remote_procstat.vb"

      Code:
      Dim proc As String
      Dim dev As String
      
      Sub Main(ByVal param As Object)
      
          'Organizing devices
          Dim input() As String = param.ToString.Split(CChar(";"))
          If input.GetLength(0) < 1 Then
              hs.WriteLog("Script", "Not enough parameters")
              Exit Sub
          Else
              proc = input(0).ToString
              dev = input(1).ToString
          End If
      
          Dim p() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName(proc)
          hs.Writelog("Test", p.Length & " - " & proc & " - " & dev)
          If p.Length = 0 Then
              UpdateDevice(0)
      
          ElseIf p.Length > 1 Then
              UpdateDevice(1)
      
          ElseIf p.Length = 1 Then
              If p(0).Responding Then
                  UpdateDevice(2)
      
              Else 'not responding
                  UpdateDevice(3)
      
              End If
          End If
      
      End Sub
      
      Sub UpdateDevice(ByVal status As Integer)
          Select Case status
              Case Is = 0
                  hs.SetDeviceString(dev, proc & " is not running")
              Case Is = 1
                  hs.SetDeviceString(dev, proc & " has multiple instances")
              Case Is = 2
                  hs.SetDeviceString(dev, proc & " is alive and kicking")
              Case Is = 3
                  hs.SetDeviceString(dev, proc & " does not respond")
          End Select
          hs.SetDeviceStatus(dev, status)
      End Sub
      You also need to create a "Status Only" device, but I'm sure you know how to do that. And last, you need to create an event to run the remote script whenever you want to run the test. In the "Parameter" textbox be sure to enter the process name (as in "Excel", "winword", "explorer", basically the name before ".exe" I think) and then a semi colon (";") and then the code for the status device.

      See the attachment for script settings.


      This works for me. Even better than I imagined.



      This script can of course be updated and made better (i.e. more tests for the process). If anyone updates the script, I'd love to see the it.
      Attached Files
      Last edited by Moskus; December 8, 2009, 10:00 AM.
      HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
      Running on Windows 10 (64) virtualized
      on ESXi (Fujitsu Primergy TX150 S8).
      WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

      Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

      Comment


        #4
        Hey that's a nice and usefull remote script !

        I like the idea you had with If p(0).Responding Then...
        I didn't know about this interesting Process object property !

        Best regards,

        stipus
        --
        stipus

        Comment


          #5
          Originally posted by stipus View Post
          Hey that's a nice and usefull remote script !

          I like the idea you had with If p(0).Responding Then...
          I didn't know about this interesting Process object property !
          Thanks!

          I've used the process class earlier when I needed to start a program and make sure that it was running without hanging. The quick sollution was to just make a program with that aim.

          And it just occured to me today that it would be even better to use it together with HomeSeer and the script client.


          (Of course you can loop through the p array if you actually have multiple instances of a program, and it should be easy enough to let the script terminate the process if it hangs and start a new one. )
          HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
          Running on Windows 10 (64) virtualized
          on ESXi (Fujitsu Primergy TX150 S8).
          WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

          Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

          Comment


            #6
            Could you make a copy of your post #3 to the Remote Script Gallery thread ?

            http://board.homeseer.com/showthread.php?t=123250

            Thanks,

            stipus
            --
            stipus

            Comment


              #7
              Thanks for all this chaps...looks brilliant...but what happens when you have more than 1 process of the same name running?

              Thanks

              Darren

              Comment


                #8
                Originally posted by stipus View Post
                Could you make a copy of your post #3 to the Remote Script Gallery thread ?
                http://board.homeseer.com/showthread.php?t=123250
                Thanks,
                stipus
                Sure thing, no problem.


                Originally posted by darren-mc View Post
                Thanks for all this chaps...looks brilliant...but what happens when you have more than 1 process of the same name running
                The script will notify you that there is more than one instance running. However, in it's current state it won't check if all are responsive or not.

                Normally having multiple instances of the same program running is not a problem. Notepad, calculator (calc), Excel and Word are programs that can have many instances withouth problems. For other programs, such as Outlook, WebcamXP or even HomeSeer itself, having multiple instances running is a sign that something's wrong.


                But it should be easy enough to change that.

                Just replace "If p.Length = 0 Then [...] End if" with this:

                Code:
                        Dim bolAllAreRunning As Boolean = True
                        For Each pr As Process In p
                            If Not pr.Responding Then bolAllAreRunning = False
                        Next
                        If p.Length = 0 Then
                            UpdateDevice(0)
                        ElseIf bolAllAreRunning Then
                            UpdateDevice(2)
                        Else
                            UpdateDevice(3)
                        End If
                HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                Running on Windows 10 (64) virtualized
                on ESXi (Fujitsu Primergy TX150 S8).
                WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                Comment


                  #9
                  I've updated the script a little.

                  The last function ListProcesses can be run if you don't know the name of the process you want to check.

                  Code:
                      Dim proc As String
                      Dim dev As String
                  
                      Public Sub Main(ByVal param As String)
                          'Organizing devices
                          Dim input() As String = param.ToString.Split(CChar(";"))
                          If input.GetLength(0) < 1 Then
                              hs.WriteLog("Script", "Not enough parameters")
                              Exit Sub
                          Else
                              proc = input(0).ToString
                              dev = input(1).ToString
                          End If
                  
                          Dim p() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName(proc)
                  
                          If p.Length = 0 Then
                              UpdateDevice(0)
                  
                          ElseIf p.Length > 1 Then
                              UpdateDevice(1)
                  
                          ElseIf p.Length = 1 Then
                              If p(0).Responding Then
                                  Dim s As String = ProcDescription(p(0))
                                  UpdateDevice(2, s)
                  
                              Else 'not responding
                                  UpdateDevice(3)
                  
                              End If
                          End If
                  
                      End Sub
                  
                      Private Sub UpdateDevice(ByVal status As Integer, Optional ByVal str As String = Nothing)
                          Select Case status
                              Case Is = 0
                                  hs.SetDeviceString(dev, proc & " is <b><font color=""red"">not running</font></b>")
                                  'hs.WriteLog("ProcStat", proc & " is not running")
                              Case Is = 1
                                  hs.SetDeviceString(dev, proc & " has many instances")
                                  'hs.WriteLog("procStat", proc & " has many instances")
                              Case Is = 2
                                  hs.SetDeviceString(dev, "<b>" & proc & "</b> is <b><font color=""green"">running</font></b>" & str)
                                  'hs.WriteLog("ProcStat", "<b>" & proc & "</b> is running" & str)
                              Case Is = 3
                                  hs.SetDeviceString(dev, proc & " is <b><font color=""red"">not responding</font></b>")
                                  'hs.WriteLog("ProcStat", proc & " does not respond!")
                          End Select
                          hs.SetDeviceStatus(dev, status)
                          hs.SetDeviceLastChange(dev, Date.Now)
                      End Sub
                  
                      Private Function ProcDescription(ByVal p As System.Diagnostics.Process) As String
                          Dim s As String = "<br>" _
                                          & "Processor time: " & p.TotalProcessorTime.Days.ToString("00") & ":" & p.TotalProcessorTime.Hours.ToString("00") & ":" & p.TotalProcessorTime.Minutes.ToString("00") & ":" & p.TotalProcessorTime.Seconds.ToString("00") & "<br>" _
                                          & "Used memory: " & Math.Round(p.WorkingSet64 / (1024 ^ 2), 1) & " MB"
                          Return s
                      End Function
                  
                      Public Sub ListProcesses()
                          Dim p2() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
                          Dim s As String = Nothing
                          For Each pr As System.Diagnostics.Process In p2
                              s &= pr.ProcessName & "<br>"
                          Next
                          hs.WriteLog("Available processes", s)
                      End Sub
                  HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                  Running on Windows 10 (64) virtualized
                  on ESXi (Fujitsu Primergy TX150 S8).
                  WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                  Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                  Comment


                    #10
                    Network World posted an article about a free monitoring tool that would be useful

                    Comment

                    Working...
                    X