Monitor memory usage

From Domoticz
Jump to navigation Jump to search

Purpose

Logging memory usage of a process running on your raspberry pi

Dependencies - hardware / software / operating system

Running on linux variants like the default Raspberry Pi image

Domoticz Setup - switches, variables, version

Create a virtual sensor

1. Create dummy device in the Setup/Hardware panel

2. Create virtual 'Percentage' device (using 'Create Virtual Sensors'

3. Note the IDX in the Setup/Devices screen

Installation instructions

Login using SSH

Stay in the /home/pi directory

create a script: "nano MemoryLogging.sh"

change to executable "chmod +x MemoryLogging.sh"

add the script to crontab using "crontab -e", add a line like this:

*/10 * * * * /home/pi/MemoryLogging.sh

this will execute the script every 10 minutes

Script with comments

#!/bin/bash
#Retrieve memory usage of the system in percentage
MEMUSG=`free -m|grep "Mem"|awk '{print $3/($4+$3) * 100}'`
#save memory usage to domoticz, replace with you IP, Portnumber and IDX
OUTPUT=`curl "http://192.168.1.3:8080/json.htm?type=command&param=udevice&idx=59&nvalue=0&svalue=$MEMUSG"`

Example of use (if relevant) i.e. output files / screen displays

Check the device in the utility tab