Using Glances to Monitor Process on Another Machine

If i look for the process on the remote machine using:
http://machine:61208/api/2/processlist/name/kodi.exe

I get the response:
{"kodi.exe": [{"memory_info": [232800256, 245035008, 301828711, 316395520, 232800256, 554592, 516768, 289376, 79064, 245035008, 328175616, 245035008], "io_counters": [31115290491, 140272840, 31113552129, 140272840, 1], "status": "R", "username": "Machine\username", "cmdline": ["C:\\Program Files (x86)\\Kodi\\kodi.exe"], "time_since_update": 2.9291675090789795, "pid": 6916, "standard_stats": true, "nice": 32, "memory_percent": 1.3625207544926314, "name": "kodi.exe", "ppid": 1320, "cpu_times": [59798.8337234, 28987.4974161, 0, 0], "mandatory_stats": true, "cpu_percent": 17.2}]}

I just cant figure out how to use this data to create a sensor in HASS to monitor if it is running.

Does this help?
https://home-assistant.io/components/sensor.glances/

Hi! Not really. I’ve done that part but it doesn’t give info on monitoring specific processes. Since it’s a different machine, I cannot use system monitor. The glances documentation isn’t very good for their API. I only discovered the above when playing around with it.

If there was a way to make a template sensor that would Curl -X GET that info then maybe scan for “status: R” in the output. If it found it, home assistant would list as “online.” If it didn’t, home assistant would say it was off line.

If you are running glances 2.1.1, there is pretty good documentation located in /usr/share/doc/glances/glances-doc.html. It does tell you how to monitor specific processes.

If you are running glances 2.7.1 you also need to install glances-doc

I installed the doc. It didn’t help too much since i cant figure out how to take the data and make it an HA sensor.

Take a look at the rest sensor.

Getting closer.
I did this:

  - platform: rest
    resource: http://machinename:61208/api/2/processlist/name/kodi.exe
    name: Kodi Monitor
    method: GET
    payload: '{ "status": "R" }'

It created a sensor but the sensor lists everything instead of what i put as the payload:

sensor.kodi_monitor {“kodi.exe”: [{“memory_info”: [234303488, 248160256, 353595500, 316395520, 234303488, 554592, 515696, 289376, 75224, 248160256, 328175616, 248160256], “io_counters”: [36452658409, 159395343, 36452657913, 159395343, 1], “status”: “R”, “username”: “machine\username”, “cmdline”: [“C:\Program Files (x86)\Kodi\kodi.exe”], “time_since_update”: 31.007773637771606, “pid”: 6916, “standard_stats”: true, “nice”: 32, “memory_percent”: 1.3713187894862762, “name”: “kodi.exe”, “ppid”: 1320, “cpu_times”: [72602.241396, 33616.9206917, 0, 0], “mandatory_stats”: true, “cpu_percent”: 12.1}]}

Add value_template: and

I tried:

  - platform: command_line
    command: curl -X GET http://othermachine:61208/api/2/processlist/name/kodi.exe
    name: Kodi Monitor
    scan_interval: 604800
    value_template: '{{ value_json.status }}'

No luck figuring this out

The API returns…

{
  "smartd": [
    {
      "username": "root",
      "status": "S",
      "cpu_times": [
        0.01,
        0,
        0,
        0
      ],
      "name": "smartd",
      "mandatory_stats": true,
      "cmdline": "/usr/sbin/smartd -n -q never",
      "standard_stats": true,
      "cpu_percent": 2,
      "pid": 1077,
      "io_counters": [
        0,
        0,
        0,
        0,
        0
      ],
      "memory_percent": 0.02557626287395782,
      "memory_info": [
        4272128,
        25759744,
        3543040,
        548864,
        0,
        770048,
        0
      ],
      "time_since_update": 33.667556047439575,
      "nice": 0
    }
  ]
}

So, the sensor need to point to the value you want to show.

sensor:
  - platform: rest
    resource: http://10.0.10.173:61208/api/2/processlist/name/smartd
    value_template: '{{ value_json["smartd"][0]["cpu_percent"] }}'

Got it!
I plugged in your value_template:
value_template: ‘{{ value_json[“kodi.exe”][0][“status”] }}’

And it works.
If the process is running it returns “R” if not then it’s listed as unknown.

Thanks for all your help!

How does this work if there are multiple outputs? (like querying docker containers, and there are 4 or more docker containers). I see the [0] in there assuming that is the first result.
I guess my actual question is how do you manage the results if you don’t know how many results there are? can you get it to list ALL the containers.[*].name and their state?