PostgreSQL: How To Upgrade The temBoard Agent To Version 7.10

8 days ago, Dalibo released temBoard version 7.10, and I wanted to take this opportunity to show you how to upgrade the temBoard Agent to version 7.10.  You might think that simply running a yum localupdate will be enough, however, in case you want to unleash the full potential you need to do a few things more.

There are a lot of features and fixes that went into the temBoard agent. Here I show you the most important ones that came with temBoard 7.10 and 7.9.

Agent features/fixes with version 7.10

  • Fix database probes always executed on same database
  • Reduce reconnexion in monitoring probes
  • Explicitly requires psycopg2 2.7+ on debian
  • Ignore loopback and tmpfs file systems
  • Drop Python2 support
  • Build RHEL8 package with RockyLinux 8

Agent features/fixes with version 7.9

  • Monitor only local filesystem size
  • Set umask 027 in auto_configure.sh
  • Details components version in temboard-agent –version output
  • Fix sysv init script shipped on systemd by debian package

In case you want to know more, I recommend to check out the following links.

https://github.com/dalibo/temboard/releases

https://temboard.readthedocs.io/en/latest/CHANGELOG/

But now lets get into the upgrade process of the agent itself. It is made of the following steps.

  • Shut down all agents running
  • Update the rpm package
  • Adjust the temBoard agent systemd service
  • Adjust the temBoard agent monitoring/probes.py file
  • Start all agents

Shutdown all agents

To shutdown all agents in one shot I use the following while loop.

$ systemctl -l | grep temboard | grep -v system- | awk '{ print $1 }' | while read i
   do
     sudo systemctl stop $i
   done

Update the rpm package

Note: On RHEL 7 – Some python 3 components might be installed as well, depending if they are already installed or not

$ sudo yum -y localupdate --disableexcludes=main temboard-agent-7.10-1.el7.noarch.rpm

Adjust the temBoard agent systemd service

Setting the Environment=”LD_LIBRARY_PATH=/app/lib/postgres/pgproduct/pg-12.10/lib” variable in the systemd file is a quite important step. By doing so, you can make sure that you can use the latest libpq features.

$ sudo vi /usr/lib/systemd/system/temboard-agent@.service

$ cat /usr/lib/systemd/system/temboard-agent@.service

[Unit]
Description=PostgreSQL Remote Control Agent %I
After=network.target postgresql@%i.service
AssertPathExists=/etc/temboard-agent/%I/temboard-agent.conf

[Service]
Type=simple
User=postgres
Group=postgres
Environment="LD_LIBRARY_PATH=/app/lib/postgres/pgproduct/pg-12.10/lib"
ExecStart=/usr/bin/env SYSTEMD=1 temboard-agent -c /etc/temboard-agent/%I/temboard-agent.conf

[Install]
WantedBy=multi-user.target


$ sudo systemctl daemon-reload

Adjust the temBoard agent monitoring/probes.py file

There is a missing comma after upstream. Correct the probes.py file (Missing Comma), so that the SQL is executed correctly.


$ sudo vi /usr/lib/python3.6/site-packages/temboardagent/plugins/monitoring/probes.py

-- search for upstream

SELECT '{p_host}' AS upstream,  <- This comma after upstream is missing
CASE 
   WHEN COUNT(*) > 0 THEN 1 
   ELSE 0 
END AS connected
FROM pg_stat_wal_receiver
WHERE status='streaming' AND
conninfo LIKE '%host={p_host}%';

Start all agents

For starting all agents, I use the following script. It has a little sleep built-in, so that not all agents are firing at the same time.


$ /app/lib/postgres/pgbase/local/bin/restart-agents.sh

#!/bin/bash -eu
#------------------------------------------------------------------------------------------------------------------------#
#-- Author: William Sescu
#--
#-- Purpose: Restart Temboard Agents
#--
#--
#--
#--
#-- History:
#-- Date        Version         Who     What
#-- 26.09.2019  Version: 0.1    SW0     Created initial version
#-- 10.10.2019  Version: 0.2    SW0     Rewrote Restart Agent Procedure
#-- 14.02.2020  Version: 0.3    SW0     Added sleep 3, so that the agents are not fired at the same time
#--
#------------------------------------------------------------------------------------------------------------------------#
#-- Debugging

# set -x

#------------------------------------------------------------------------------------------------------------------------#


if ! hash sudo systemctl &>/dev/null; then
        echo "ERROR: You must restart manually temboard-agent services" >&2
        exit 0
fi

echo "INFO: Running systemctl reset-failed and daemon-reload"
sudo systemctl reset-failed
sudo systemctl daemon-reload
sudo systemctl is-system-running

if ! sudo systemctl is-system-running &>/dev/null ; then
        echo "ERROR: You must restart manually temboard-agent services" >&2
        echo "ERROR: Check with sudo systemctl list-units --state=failed"
        echo "ERROR: Correct it, and run afterwards sudo systemctl reset-failed"
        exit 0
fi


#------------------------------------------------------------------------------------------------------------------------#

prefix=temboard-agent@

# search for files in the /etc/systemd/ directory

echo "INFO: Search for temboard-agent files in the /etc/systemd/ directory"
sudo find /etc/systemd/system/multi-user.target.wants/ -name "${prefix}*"

active_units="$(sudo systemctl --all --plain list-units ${prefix}* | grep -Po ${prefix}.*\\.service ||:)"

if [ -z "${active_units}" ] ; then
        echo "ERROR: No units found for temboard-agent" >&2
        exit 0;
fi

exit_code=0
for unit in ${active_units} ; do
        echo "INFO: Restarting $unit" >&2
        sudo systemctl stop $unit
        sleep 3
        sudo systemctl start $unit
        # if ! sudo systemctl restart $unit ; then
        #               echo "ERROR: Failed to restart $unit" >&2
        #       exit_code=1
        # fi
done

exit $exit_code

#------------------------------------------------------------------------------------------------------------------------#

Check that the agent has loaded the correct libpq

Red Hat 7.x comes with a quite old version per default (libpq 9.2.24), however, if you want to use all features, you need to make sure, that the systemd service shows “INFO: Using libpq 12.10”

$ temboard-agent --version
 INFO: Starting temboard-agent 7.10.
temBoard agent 7.10
System Red Hat Enterprise Linux Server 7.9 (Maipo)
Python 3.6.8 (/usr/bin/python3)
psycopg2 2.7.7 (dt dec pq3 ext) libpq 9.2.24  <-- this is the old libpq

$ sudo systemctl status temboard-agent@12-pg55007.service
● temboard-agent@12-pg55007.service - PostgreSQL Remote Control Agent 12/pg55007
   Loaded: loaded (/usr/lib/systemd/system/temboard-agent@.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-03-04 07:44:12 CET; 2s ago
 Main PID: 6928 (temboard-agent)
   CGroup: /system.slice/system-temboard\x2dagent.slice/temboard-agent@12-pg55007.service
           ├─6928 temboard-agent: 12/pg55007: main process
           ├─6947 temboard-agent: 12/pg55007: worker pool
           └─6948 temboard-agent: 12/pg55007: scheduler

Mar 04 07:44:12 host01 systemd[1]: Started PostgreSQL Remote Control Agent 12/pg55007.
Mar 04 07:44:13 host01 env[6928]: INFO: Starting temboard-agent 7.10.
Mar 04 07:44:13 host01 env[6928]: INFO: Running on Red Hat Enterprise Linux Server 7.9 (Maipo).
Mar 04 07:44:13 host01 env[6928]: INFO: Using Python 3.6.8 (/usr/bin/python3).
Mar 04 07:44:13 host01 env[6928]: INFO: Using libpq 12.10, Psycopg2 2.7.7 (dt dec pq3 ext).  <-- this is the new libpq

Conclusion

Upgrading the temBoard agent looks like an easy step. However, if you want to use its full potential you might want to switch to a more recent libpq version. In regards to the issue with the typo in the SQL statements. That one should be fixed in the next temBoard agent release.