Skip to content

Commit

Permalink
rls v1.7.3 add mem used sensor fix disk used sensor
Browse files Browse the repository at this point in the history
- Add `fs_disk_used` value
- Correct Disk Used % sensor to use "used" vs. "free" value
- Convert memory values from floating point string to integer (precision not necessary)
- Add new Mem Used % sensor
  • Loading branch information
ironsheep committed Feb 18, 2023
1 parent f35c698 commit 9300ed4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 42 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# ChangeLog

Sat, 18 Feb 2023 14:22:52 -0700 v1.7.3

- Add `fs_disk_used` value
- Correct Disk Used % sensor to use "used" vs. "free" value
- Convert memory values from floting point string to integer (precision not necessary)
- Add new Mem Used % sensor

Sat, 11 Feb 2023 14:28:59 -0700 v1.7.2

- Repair fetch of versions, now every 12 hours
Expand Down
27 changes: 20 additions & 7 deletions ISP-RPi-mqtt-daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import requests
from urllib3.exceptions import InsecureRequestWarning

script_version = "1.7.2"
script_version = "1.7.3"
script_name = 'ISP-RPi-mqtt-daemon.py'
script_info = '{} v{}'.format(script_name, script_version)
project_name = 'RPi Reporter MQTT2HA Daemon'
Expand Down Expand Up @@ -416,7 +416,7 @@ def getDeviceMemory():
if 'MemAvail' in currLine:
mem_avail = float(lineParts[1]) / 1024
# Tuple (Total, Free, Avail.)
rpi_memory_tuple = (mem_total, mem_free, mem_avail)
rpi_memory_tuple = (mem_total, mem_free, mem_avail) # [0]=total, [1]=free, [2]=avail.
print_line('rpi_memory_tuple=[{}]'.format(rpi_memory_tuple), debug=True)

def refreshPackageInfo():
Expand Down Expand Up @@ -1174,6 +1174,7 @@ def isAliveTimerRunning():
LD_FS_USED = "disk_used"
LDS_PAYLOAD_NAME = "info"
LD_CPU_USE = "cpu_load"
LD_MEM_USED = "mem_used"

if interval_in_minutes < 5:
LD_CPU_USE_JSON = "cpu.load_1min_prcnt"
Expand All @@ -1200,10 +1201,12 @@ def isAliveTimerRunning():
json_value="timestamp", json_attr="yes", icon='mdi:raspberry-pi', device_ident="RPi-{}".format(rpi_fqdn))),
(LD_SYS_TEMP, dict(title="RPi Temp {}".format(rpi_hostname), device_class="temperature",
no_title_prefix="yes", unit="°C", json_value="temperature_c", icon='mdi:thermometer')),
(LD_FS_USED, dict(title="RPi Used {}".format(rpi_hostname),
no_title_prefix="yes", json_value="fs_free_prcnt", unit="%", icon='mdi:sd')),
(LD_FS_USED, dict(title="RPi Disk Used {}".format(rpi_hostname),
no_title_prefix="yes", json_value="fs_used_prcnt", unit="%", icon='mdi:sd')),
(LD_CPU_USE, dict(title="RPi CPU Use {}".format(rpi_hostname),
no_title_prefix="yes", json_value=LD_CPU_USE_JSON, unit="%", icon=LD_CPU_USE_ICON)),
(LD_MEM_USED, dict(title="RPi Mem Used {}".format(rpi_hostname),
no_title_prefix="yes", json_value="mem_used_prcnt", unit="%", icon='mdi:memory')),
])

print_line('Announcing RPi Monitoring device to MQTT broker for auto-discovery ...')
Expand Down Expand Up @@ -1320,6 +1323,8 @@ def isPeriodTimerRunning():
RPI_DATE_LAST_UPDATE = "last_update"
RPI_FS_SPACE = 'fs_total_gb' # "fs_space_gbytes"
RPI_FS_AVAIL = 'fs_free_prcnt' # "fs_available_prcnt"
RPI_FS_USED = 'fs_used_prcnt' # "fs_used_prcnt"
RPI_RAM_USED = 'mem_used_prcnt' # "mem_used_prcnt"
RPI_SYSTEM_TEMP = "temperature_c"
RPI_GPU_TEMP = "temp_gpu_c"
RPI_CPU_TEMP = "temp_cpu_c"
Expand Down Expand Up @@ -1383,7 +1388,9 @@ def send_status(timestamp, nothing):
else:
rpiData[RPI_DATE_LAST_UPDATE] = ''
rpiData[RPI_FS_SPACE] = int(rpi_filesystem_space.replace('GB', ''), 10)
rpiData[RPI_FS_AVAIL] = int(rpi_filesystem_percent, 10)
# TODO: consider eliminating RPI_FS_AVAIL/fs_free_prcnt as used is needed but free is not... (can be calculated)
rpiData[RPI_FS_AVAIL] = 100 - int(rpi_filesystem_percent, 10)
rpiData[RPI_FS_USED] = int(rpi_filesystem_percent, 10)

rpiData[RPI_NETWORK] = getNetworkDictionary()

Expand All @@ -1394,6 +1401,11 @@ def send_status(timestamp, nothing):
rpiRam = getMemoryDictionary()
if len(rpiRam) > 0:
rpiData[RPI_MEMORY] = rpiRam
ramSizeMB = int('{:.0f}'.format(rpi_memory_tuple[0], 10)) # "mem_space_mbytes"
# used is total - free
ramUsedMB = int('{:.0f}'.format(rpi_memory_tuple[0] - rpi_memory_tuple[2]), 10)
ramUsedPercent = int((ramUsedMB / ramSizeMB) * 100)
rpiData[RPI_RAM_USED] = ramUsedPercent # "mem_used_prcnt"

rpiCpu = getCPUDictionary()
if len(rpiCpu) > 0:
Expand Down Expand Up @@ -1488,8 +1500,9 @@ def getMemoryDictionary():
# Tuple (Total, Free, Avail.)
memoryData = OrderedDict()
if rpi_memory_tuple != '':
memoryData[RPI_MEM_TOTAL] = '{:.3f}'.format(rpi_memory_tuple[0])
memoryData[RPI_MEM_FREE] = '{:.3f}'.format(rpi_memory_tuple[2])
# TODO: remove free fr
memoryData[RPI_MEM_TOTAL] = int(rpi_memory_tuple[0])
memoryData[RPI_MEM_FREE] = int(rpi_memory_tuple[2])
#print_line('memoryData:{}"'.format(memoryData), debug=True)
return memoryData

Expand Down
75 changes: 40 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,57 @@ Each RPi device is reported as:

### RPi MQTT Topics

Each RPi device is reported as four topics:
Each RPi device is reported as five topics:

| Name | Device Class | Units | Description |
| --------------- | ------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `~/monitor` | 'timestamp' | n/a | Is a timestamp which shows when the RPi last sent information, carries a template payload conveying all monitored values (**attach the lovelace custom card to this sensor!**) |
| `~/temperature` | 'temperature' | degrees C | Shows the latest system temperature |
| `~/disk_used` | none | percent (%) | Shows the amount of root file system used |
| `~/disk_used` | none | percent (%) | Shows the percent of root file system used |
| `~/cpu_load` | none | percent (%) | Shows CPU load % over the last 5 minutes |
| `~/mem_used` | none | percent (%) | Shows the percent of RAM used |

### RPi Monitor Topic

The monitored topic reports the following information:

| Name | Sub-name | Description |
| ------------------- | ------------------ | --------------------------------------------------------------------------------------------------- |
| `rpi_model` | | tinyfied hardware version string |
| `ifaces` | | comma sep list of interfaces on board [w,e,b] |
| `temperature_c` | | System temperature, in [°C] (0.1°C resolution) Note: this is GPU temp. if available, else CPU temp. |
| `temp_gpu_c` | | GPU temperature, in [°C] (0.1°C resolution) |
| `temp_cpu_c` | | CPU temperature, in [°C] (0.1°C resolution) |
| `up_time` | | duration since last booted, as [days] |
| `last_update` | | updates last applied, as [date] |
| `fs_total_gb` | | / total space in [GBytes] |
| `fs_free_prcnt` | | / free space [%] |
| `host_name` | | hostname |
| `fqdn` | | hostname.domain |
| `ux_release` | | os release name (e.g., buster) |
| `ux_version` | | os version (e.g., 4.19.66-v7+) |
| `reporter` | | script name, version running on RPi |
| `networking` | | lists for each interface: interface name, mac address (and IP if the interface is connected) |
| `drives` | | lists for each drive mounted: size in GB, % used, device and mount point |
| `cpu` | | lists the model of cpu, number of cores, etc. |
| | `hardware` | typically the Broadcom chip ID (e.g. BCM2835) |
| | `model` | model description string (e.g., ARMv7 Processor rev 4 (v7l)) |
| | `number_cores` | number of cpu cores [1,4] |
| | `bogo_mips` | reported performance of this RPi |
| | `serial` | serial number of this RPi |
| | `load_1min_prcnt` | average % cpu load during prior minute (avg per core) |
| | `load_5min_prcnt` | average % cpu load during prior 5 minutes (avg per core) |
| | `load_15min_prcnt` | average % cpu load during prior 15 minutes (avg per core) |
| `memory` | | shows the total amount of RAM in MB and the available ram in MB |
| `reporter` | | name and version of the script reporting these values |
| `reporter_releases` | | list of latest reporter formal versions |
| `report_interval` | | interval in minutes between reports from this script |
| `throttle` | | reports the throttle status value plus interpretation thereof |
| `timestamp` | | date, time when this report was generated |
| Name | Sub-name | Description |
| ------------------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------- |
| `rpi_model` | | tinyfied hardware version string |
| `ifaces` | | comma sep list of interfaces on board [w,e,b] |
| `temperature_c` | | System temperature, in [°C] (0.1°C resolution) Note: this is GPU temp. if available, else CPU temp. (used by HA sensor) |
| `temp_gpu_c` | | GPU temperature, in [°C] (0.1°C resolution) |
| `temp_cpu_c` | | CPU temperature, in [°C] (0.1°C resolution) |
| `up_time` | | duration since last booted, as [days] |
| `last_update` | | updates last applied, as [date] |
| `fs_total_gb` | | / (root) total space in [GBytes] |
| `fs_free_prcnt` | | / (root) available space [%] |
| `fs_used_prcnt` | | / (root) used space [%] (used by HA sensor) |
| `host_name` | | hostname |
| `fqdn` | | hostname.domain |
| `ux_release` | | os release name (e.g., buster) |
| `ux_version` | | os version (e.g., 4.19.66-v7+) |
| `reporter` | | script name, version running on RPi |
| `networking` | | lists for each interface: interface name, mac address (and IP if the interface is connected) |
| `drives` | | lists for each drive mounted: size in GB, % used, device and mount point |
| `cpu` | | lists the model of cpu, number of cores, etc. |
| | `hardware` | - typically the Broadcom chip ID (e.g. BCM2835) |
| | `model` | - model description string (e.g., ARMv7 Processor rev 4 (v7l)) |
| | `number_cores` | - number of cpu cores [1,4] |
| | `bogo_mips` | - reported performance of this RPi |
| | `serial` | - serial number of this RPi |
| | `load_1min_prcnt` | - average % cpu load during prior minute (avg per core) |
| | `load_5min_prcnt` | - average % cpu load during prior 5 minutes (avg per core) |
| | `load_15min_prcnt` | - average % cpu load during prior 15 minutes (avg per core) |
| `memory` | | shows the RAM configuration in MB for this RPi |
| | `size_mb` | - total memory Size in MBytes |
| | `free_mb` | - available memory in MBytes |
| `mem_used_prcnt` | | shows the amount of RAM currently in use (used by HA sensor) |
| `reporter` | | name and version of the script reporting these values |
| `reporter_releases` | | list of latest reporter formal versions |
| `report_interval` | | interval in minutes between reports from this script |
| `throttle` | | reports the throttle status value plus interpretation thereof |
| `timestamp` | | date, time when this report was generated |

_NOTE: cpu load averages are divided by the number of cores_

Expand Down

0 comments on commit 9300ed4

Please sign in to comment.