Systeminfo Binding: Get info from multiple partitions

  • Platform information:
    • Hardware: ARM
    • OS: Debian 9
    • Java Runtime Environment: 11
    • openHAB version: 3.0.0
  • Issue of the topic: please be detailed explaining your issue

Have successfully installed the Systeminfo Binding.
Here are the ‘disks’ on my system

# df
Filesystem                    1K-blocks   Used Available Use% Mounted on
udev                              10240      0     10240   0% /dev
tmpfs                            413620    308    413312   1% /run
/dev/disk/by-label/userdata     1105856 562236    515668  53% /mnt/.rwfs
/dev/disk/by-partlabel/rootfs    160256 160256         0 100% /mnt/.rofs
aufs-root                       1105856 562236    515668  53% /
tmpfs                           1034048      0   1034048   0% /dev/shm
tmpfs                              5120      0      5120   0% /run/lock
tmpfs                           1034048      0   1034048   0% /sys/fs/cgroup
tmpfs                            413620      0    413620   0% /tmp
/dev/mmcblk0p7                  1515376   2304   1480960   1% /srv
/dev/mmcblk1                    7529096 823872   6299720  12% /data

The sysinfo binding is reporting this partition:

/dev/disk/by-label/userdata     1105856 562236    515668  53% /mnt/.rwfs

So far - so good.

But also want to capture the data for

/dev/mmcblk1                    7529096 823872   6299720  12% /data

I have read Systeminfo - Bindings | openHAB which says

The groups marked with “(deviceIndex)” may have device index attached to the Channel Group.

  • channel ::= channel_group & (deviceIndex) & # channel_id
  • deviceIndex ::= number > 0
  • (e.g. storage1#available)

The group process is using a configuration parameter “pid” instead of “deviceIndex”. This makes it possible to change the tracked process at runtime.

The binding uses this index to get information about a specific device from a list of devices (e.g on a single computer several local disks could be installed with names C:, D:, E:\ - the first will have deviceIndex=0, the second deviceIndex=1 etc). If device with this index is not existing, the binding will display an error message on the console.

Unfortunately this feature can’t be used at the moment without manually adding these new channel groups to the thing description (located in OH-INF/thing/computer.xml).

But those instructions do not seem to apply to OH3. Specifically not clear what to edit to see my other partition.

If I look at the item that is working fine for the main partition, I see:
systeminfo:computer:MQTT:storage#usedPercent

I think I need to add a new channel that looks like
systeminfo:computer:MQTT:storage1#usedPercent

But how?

I’d take a different approach:

Use a bash script which reads the input from df, greps for the line and updates some items via the REST api:

#!/bin/bash
numbers=$(df | grep '/dev/mmcblk1' | grep -E -o "[0-9]+")
number_of_blocks=$(echo $numbers | cut -d" " -f1)
used=$(echo $numbers | cut -d" " -f2)
available=$(echo $numbers | cut -d" " -f3)
used_percent=$(echo $numbers | cut -d" " -f4)

#and then Update the items
curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$state" "http://$OHIP:8080/rest/items/$item/state"

then add the script to a crontab with crontab -e so the measurements get updated frequently

Felix

Thanks! Got that to work.

:slight_smile:

1 Like

Can you please mark my post as solution so the thread becomes solved. This way it is easier to find it for future people having the same problem :wink:

Felix: Could not tag the exact post as a solution (Maybe because it had been edited?) So I tagged the next one from you instead. Thanks again.

Meanwhile … I had to edit your code a tiny bit, and I added Unused memory as well. For completeness here is what is running hourly under cron.

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

getNumbers(){
 disk=$1
 firstField=$2

 numbers=$(df | grep $disk | grep -E -o "[0-9]+")
 number_of_blocks=$(echo $numbers | cut -d" " -f$firstField)
 ((firstField+=1))
 used=$(echo $numbers | cut -d" " -f$firstField)
 ((firstField+=1))
 available=$(echo $numbers | cut -d" " -f$firstField)
 ((firstField+=1))
 used_percent=$(echo $numbers | cut -d" " -f$firstField)
}

 getNumbers '/dev/mmcblk1' 2
 curl -X PUT --header "Content-Type: text/plain" \
            --header "Accept: application/json" \
            "http://mqtt.lan:8080/rest/items/LocalHost_Disk1Used/state"\
            -d $used_percent

 getNumbers 'aufs-root' 1
 curl -X PUT --header "Content-Type: text/plain" \
            --header "Accept: application/json" \
            "http://mqtt.lan:8080/rest/items/LocalHost_Disk0Used/state"\
            -d $used_percent

# Free Memory

#LocalHost_RAMUsed
numbers=$(free | grep 'Mem:' | grep -E -o "[0-9]+")
RAMtotal=$(echo $numbers | cut -d" " -f1)
RAMused=$(echo $numbers | cut -d" " -f2)
used_percent=$((100*$RAMused/$RAMtotal))
curl -X PUT --header "Content-Type: text/plain" \
            --header "Accept: application/json" \
            "http://mqtt.lan:8080/rest/items/LocalHost_RAMUsed/state" \
            -d $used_percent

1 Like