SIGAR (Systeminfo Binding) on another device

Hi All,
I am using SIGAR to monitor the System information of my Openhab Host.
But i got another Linux device (Rpi) which i want to be monitored within openhab.
Due to limited memory of a raspberry pi, i do not want to install openhab twice.
Required informations from my slave:
Uptime, CPU Load (Percentage) Ram usage, in % and in MB

What about a cronjob with SIGAR and sending the values to OpenHAB.

Thank you in advance.

Install mosquitto on your openHAB server and setup an MQTT broker. Then install the mosquitto client libraries on your Pi (very lightweight) and write a script to publish your SIGAR readings to MQTT topics. Then setup openHAB to subscribe to your SIGAR topics and voila - you have your SIGAR data in openHAB.

You don’t have to usemosquitto on the RPi, you could use any number of MQTT libraries for other languages.

Hi,

you can try my psmqtt utility which shares CPU, RAM and other parameters using MQTT protocol. After you can add them to Openhab using MQTT binding

It doesn’t use SIGAR and written in Python

Thanks,
i have a few questions: is it possible to send the Systems formatted uptime (like SIGAR) over mqtt?
How do i start the script, if my system starts (create a bash script under init.d or similar?)

is it possible to send the Systems formatted uptime (like SIGAR) over mqtt?

actually psutil library (used by my tool) provides boot_time parameter that is unix timestamp of moment when box was booted. It isn’t supported now by my tool but it’s easy to add. But I have to think how add formatted representation of uptime parameter

How do i start the script, if my system starts (create a bash script under init.d or similar?)

I use /etc/rc.local for it (and other similar scripts)

1 Like

Here is how it is done in the Systeminfo Binding:
( https://sourceforge.net/p/hyperic-hq/mailman/message/5040942/ )

`+ public static String getFormattedUptime(double uptime) {

  •    String retval = "";
    
  •    int days = (int)uptime / (60*60*24);
    
  •    int minutes, hours;
    
  •    if (days != 0) {
    
  •        retval += days + " " + ((days > 1) ? "days" : "day") + ", ";
    
  •    }
    
  •    minutes = (int)uptime / 60;
    
  •    hours = minutes / 60;
    
  •    hours %= 24;
    
  •    minutes %= 60;
    
  •    if (hours != 0) {
    
  •        retval += hours + ":" + minutes;
    
  •    }
    
  •    else {
    
  •        retval += minutes + " min";
    
  •    }
    
  •    return retval;
    
  • }`

Hey,
Why is there a different percentage for the ram usage, than it should be, based on the RAM Usage in megabytes?
By the way: your output is showing bytes, so you need to transform the item, dividing by 1000000

I’ve checked sources of psutil and found that percents are calculated as
avail = free + buffers + cached
used = total - free
percent = usage_percent((total - avail), total, _round=1)

So in your case (of course if all 4 parameters are get at the same moment of time)
total = 971
free = 579
used = 392 (40%)
avail = 85% * 971 = 825
buffers+cached = avail-free=825-579=246

By the way: your output is showing bytes, so you need to transform the item, dividing by 1000000

I’m still not sure that formatting of output data is a task for my tool. Need to think more about it

Dominic,

I’ve updated branch with new feature (not documented yet)
Now values could be formatted using templates
Please install jinja2 pip module and after you can use

virtual_memory/free/{{x|MB}} - to get free RAM in MB
boot_time/{{x|uptime}} - boot time formatted as uptime

Thanks, now it’s working like a charm.

Has anyone an idea how to display the uptime of a certain process with sigar?
The main controller still uses SIGAR to display the Stats.

String VMuptime “Uptime VM [%s]” {systeminfo=“UptimeFormatted:60000”}
String OHuptime “Uptime OH [%s]” {systeminfo=“ProcessUptimeFormatted:60000:$$”}
String DBuptime “DB [%s]” {systeminfo=“ProcessUptimeFormatted:60000:4215”}

“DBuptime” does not work at the moment.
It is a Dashing Cotrolpanel, the PID is stored in a file ( /dashing/tmp/pids/thin.pid )
The process is called thin server

How can i get the uptime of a certain Process within OpenHAB?

I’ve upgraded psmqtt a bit and now you can use:

processes/pid[|path|to|pid|file.pid]/create_time/{{x|uptime}} - to get uptime of process using .pid file or
processes/name[name*pattern]/create_time/{{x|uptime}} - using pattern for process name

also there is an option (see Schedule section of README) to use more pretty looking MQTT topics for such ugly task names

Hi Eschava,
thank you for this update.

The best feature for me (Uptime of certain process) is not working for me.
this ist my output (i use both formats), when launching the application:

./psmqtt.sh Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "psmqtt.py", line 181, in run self.s.run() File "/usr/lib/python2.7/sched.py", line 117, in run action(*argument) File "psmqtt.py", line 146, in on_timer run_task(task, task) File "psmqtt.py", line 50, in run_task if task.startswith(topic_prefix): AttributeError: 'dict' object has no attribute 'startswith'

my items:
String Dashuptime "Uptime formatted [%s]" (Systeminfo) {mqtt="<[mosquitto:smarthome/db_uptime:state:default]"} String Dashuptime_2 "Uptime formatted [%s]" (Systeminfo) {mqtt="<[mosquitto:smarthome/processes/pid[|dashing|tmp|pids|thin.pid]/create_time/{{x|uptime}}:state:default]"}

psmqtt.conf:
{"processes/pid[|dashing|tmp|pids|thin.pid]/create_time/{{x|uptime}}":"db_uptime"}, "processes/pid[|dashing|tmp|pids|thin.pid]/create_time/{{x|uptime}}",

no syntax error is reported, therefore i am stuck

Your configuration is a bit wrong (dict is an element of list) but I think it could be convinient in some cases so now it should be supported by parser.
Please update from github for this fix but please note that now default prefix for mqtt topic is /psmqtt/COMPUTER_NAME (to avoid conflict if several computers have psmqtt run)

Thanks but there is a difference between Unix/Linux and Windows OS regarding the System variables.

COMPUTERNAME is for Windows hosts,
HOSTNAME for Linux hosts.

but, in my case none of them is working:

Hostname

Traceback (most recent call last):
  File "psmqtt.py", line 38, in <module>
    topic_prefix = cf.get('mqtt_topic_prefix', 'psmqtt/' + os.environ['HOSTNAME'] + '/')
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'HOSTNAME'

Computername:

./psmqtt.sh
Traceback (most recent call last):
  File "psmqtt.py", line 38, in <module>
    topic_prefix = cf.get('mqtt_topic_prefix', 'psmqtt/' + os.environ['COMPUTERNAME'] + '/')
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'COMPUTERNAME'

Thanks for feedback!
Replaced with socket.gethostname()

1 Like

Hi @eschava,

I am trying to use psmqtt on several computer but I’m always receiving the message

Cannot load configuration from file psmqtt.conf: [Errno 2] No such file or directory: ‘psmqtt.conf’

Do you have any idea what I am doing wrong? I would really appreciate your help.

Looks like the default folder when you run psmqtt.py is not same where psmqtt.py is located and that’s why it cannot locate psmqtt.conf. I can adjust the code to be smarter but without code changes, you have two options:

  • change default folder to the psmqtt before running psmqtt.py
  • set full path for the psqmtt.conf file to the PSMQTTCONFIG environment variable

@eschava
I installed this yesterday and I am trying to get the uptime without the formatting
Also
These is no CPU temperature information, is that something you could add?

@vzorglub
to get uptime in seconds please use “boot_time” request
CPU temperature information was added in recent versions of psutil library and not implemented yet in psmqtt. I’ll add support for it at the nearest time

Thanks because in the docs on github it says:

boot_time - System boot time as a Unix timestamp
And I interpreted that as “time of last boot” not “up time”