Infrastructure at your Service

In the last post we’ve installed the temBoard repository and the UI. As this alone is not so much fun, we’ll be installing the temBoard agent on another SLES 15 machine in this post. We’ll end up with one PostgreSQL instance registered in the temBoard repository and this instance is constantly monitored. With the repository and the UI we had the requirement to use Python 2.7, but this is not anymore required for the temBoard agent. Lets go.

What I’ve already prepared, is the PostgreSQL instance we want the agent to monitor:

[email protected]:/u02/pgdata/13/PG1/ [PG1] psql -l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

As pip3 is already available we can go straight ahead and install the temBoard agent:

[email protected]:/u02/pgdata/13/PG1/ [PG1] sudo sudo pip3 install temboard-agent
Collecting temboard-agent
  Downloading https://files.pythonhosted.org/packages/58/6e/3d5c772587e48b17cc6fa5a1569daab0d879845828c792f16ecec49564ae/temboard_agent-7.6-py2.py3-none-any.whl (115kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 122kB 1.5MB/s 
pygobject 3.34.0 requires pycairo>=1.11.1, which is not installed.
Installing collected packages: temboard-agent
Successfully installed temboard-agent-7.6
You are using pip version 10.0.1, however version 21.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

First issue, but easy to fix:

[email protected]:/u02/pgdata/13/PG1/ [PG1] sudo zypper in cairo-devel
[email protected]:/u02/pgdata/13/PG1/ [PG1] sudo pip3 install pycairo
Collecting pycairo
  Using cached pycairo-1.20.0.tar.gz (344 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: pycairo
  Building wheel for pycairo (PEP 517) ... done
  Created wheel for pycairo: filename=pycairo-1.20.0-cp36-cp36m-linux_x86_64.whl size=246164 sha256=e25a94a3a0801e25db8eee9b1080d793b7a6dd313b12b011e56888509e411362
  Stored in directory: /root/.cache/pip/wheels/09/91/ec/f970f7c0cd3fba778c7150409181074fdfc2af42148486561d
Successfully built pycairo
Installing collected packages: pycairo
Successfully installed pycairo-1.20.0

Once again:

[email protected]:/u02/pgdata/13/PG1/ [PG1] sudo sudo pip3 install temboard-agent
Requirement already satisfied: temboard-agent in /usr/lib/python3.6/site-packages (7.6)
[email protected]:/u02/pgdata/13/PG1/ [PG1] which temboard-agent
/usr/bin/temboard-agent
[email protected]:/u02/pgdata/13/PG1/ [PG1] temboard-agent --version
Traceback (most recent call last):
  File "/usr/bin/temboard-agent", line 7, in 
    from temboardagent.scripts.agent import main
  File "/usr/lib/python3.6/site-packages/temboardagent/scripts/agent.py", line 12, in 
    from ..cli import Application
  File "/usr/lib/python3.6/site-packages/temboardagent/cli.py", line 5, in 
    from .postgres import Postgres
  File "/usr/lib/python3.6/site-packages/temboardagent/postgres.py", line 8, in 
    import psycopg2.extensions
ModuleNotFoundError: No module named 'psycopg2'

For connecting to PostgreSQL psycopg2 must be there as well:

[email protected]:/u02/pgdata/13/PG1/ [PG1] sudo pip3 install psycopg2-binary
Collecting psycopg2-binary
  Downloading psycopg2_binary-2.8.6-cp36-cp36m-manylinux1_x86_64.whl (3.0 MB)
     |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 3.0 MB 1.3 MB/s 
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.8.6
[email protected]:/u02/pgdata/13/PG1/ [PG1] temboard-agent --version
 INFO: Starting temboard-agent 7.6.
7.6

The agent is ready, lets proceed with the configuration. As with the UI in the last post, there is a configuration script:

[email protected]:/u02/pgdata/13/PG1/ [PG1] ls -l /usr/share/temboard-agent/
total 24
-rwxr-xr-x 1 root root 7318 Apr  1 11:32 auto_configure.sh
-rwxr-xr-x 1 root root  682 Apr  1 11:32 purge.sh
drwxr-xr-x 1 root root  276 Apr  1 11:32 quickstart
-rwxr-xr-x 1 root root  674 Apr  1 11:32 restart-all.sh
-rw-r--r-- 1 root root 2843 Apr  1 11:32 temboard-agent.conf
-rw-r--r-- 1 root root  176 Apr  1 11:32 temboard-agent.logrotate

Again, make sure that psql can be executed and all the environment variable match your environment:

[email protected]:/u02/pgdata/13/PG1/ [PG1] sudo su -
localhost:~ $ export ETCDIR=/u01/app/postgres/local/dmk/etc/
localhost:~ $ export VARDIR=/u01/app/postgres/local/dmk/bin
localhost:~ $ export LOGDIR=/u01/app/postgres/local/dmk/log
localhost:~ $ export SYSUSER=postgres
localhost:~ $ export PGHOST=/tmp
localhost:~ $ export PATH=/u01/app/postgres/product/13/db_2/bin:$PATH
localhost:~ $ sudo -Eu postgres psql 
could not change directory to "/root": Permission denied
psql (13.2)
Type "help" for help.

postgres=# 

Once you’ve that ready run the configuration:

localhost:~ $ /usr/share/temboard-agent/auto_configure.sh
FQDN is not properly configured. Set agent hostname with TEMBOARD_HOSTNAME env var..
Failure. See /var/log/temboard-agent-auto-configure.log for details.

Ok, this error message is clear:

localhost:~ $ export TEMBOARD_HOSTNAME=sles15tbagent.it.dbi-services.com
localhost:~ $ /usr/share/temboard-agent/auto_configure.sh
Using hostname sles15tbagent.it.dbi-services.com.
Configuring for PostgreSQL user postgres.
Configuring for cluster on port 5432.
Configuring for cluster at /u02/pgdata/13/PG1.
Configuring temboard-agent in /u01/app/postgres/local/dmk/etc//13/pg5432/temboard-agent.conf .
Saving auto-configuration in /u01/app/postgres/local/dmk/etc//13/pg5432/temboard-agent.conf.d/auto.conf
Configuring temboard-agent to run on port 2345.
Enabling systemd unit [email protected]

Success. You can now start temboard-agent using:

    systemctl start [email protected]

For registration, use secret key deb91ab1322007536e2e8284b26bdb5c .
See documentation for detailed instructions.

As we had troubles with the systemd unit file in the last post, lets have a look at it:

localhost:~ $ systemctl status [email protected]
● [email protected] - PostgreSQL Remote Control Agent 13/pg5432
   Loaded: loaded (/usr/lib/systemd/system/[email protected]; enabled; vendor preset: disabled)
   Active: inactive (dead)
localhost:~ $ cat /usr/lib/systemd/system/[email protected]
[Unit]
Description=PostgreSQL Remote Control Agent %I
After=network.target [email protected]%i.service
AssertPathExists=/etc/temboard-agent/%I/temboard-agent.conf

[Service]
Type=simple
User=postgres
Group=postgres
ExecStart=/usr/bin/env SYSTEMD=1 temboard-agent -c /etc/temboard-agent/%I/temboard-agent.conf

[Install]
WantedBy=multi-user.target

This again points to the wrong configuration file, ours is here:

localhost:~ $ cat /u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.conf
#
#   T E M B O A R D   A G E N T   C O N F I G U R A T I O N
#
# This file contains all possible settings of temBoard agent, with defaults for
# quickstart. temBoard agent overrides values of this file with .conf files
# found in directory named after this filename, with .d suffix. e.g.
# temboard-agent.conf.d/auto.conf is likely to override some values of this
# file.
#

[temboard]
# Bind port.
port = 2345
# Bind address.
address = 192.168.22.211
# User & password file.
users = users
# Plugins in use.
plugins = ["monitoring", "dashboard", "pgconf", "administration", "activity", "maintenance", "statements"]
# SSL: certificat file path (.pem)
ssl_cert_file = /u01/app/postgres/local/dmk/etc/13/pg5432/server.pem
# SSL: private key file path (.key)
ssl_key_file = /u01/app/postgres/local/dmk/etc/13/pg5432/server.key
# Hostname must be an unique and valid FQDN : e.g. db1.mydomain.foo
# If you leave this empty, then the system wide hostname will be used
# Note : `localhost` is not a correct value
hostname = sles15tbagent
# Key
key = SECRETKEYTOBECHANGED

[postgresql]
# Unix socket path.
host = /tmp
# PG port number.
port = 5432
# Super-user name.
user = postgres
# Super-user password.
# password =
# Default database.
dbname = postgres
# Instance name.
instance = main

[logging]
# Available methods for logging: stderr, syslog or file
method = stderr
# Syslog facility.
# facility = local0
# Log destination, should be /dev/log for syslog on Linux system.
# When using file logging method, this is referencing the log file path.
# destination = /var/log/temboard-agent/temboard-agent.log
# Log level, can be: DEBUG, INFO, WARNING, ERROR or CRITICAL.
level = INFO

### PLUGINS ###
[dashboard]
# Dashboard plugin part
# Interval, in second, between each run of the process collecting
# data used to render the dashboard. Default: 2
# scheduler_interval = 2
# Number of record to keep. Default: 150
# history_length = 150

[monitoring]
# Monitoring plugin part.
# DB name list (comma separator) to supervise. * for all.
dbnames = *
# List of probes to run, comma separator, * for all.
# Available probes: bgwriter,blocks,btree_bloat,cpu,db_size,filesystems_size,heap_bloat,loadavg,locks,memory,process,replication_connection,replication_lag,sessions,tblspc_size,temp_files_size_delta,wal_files,xacts
# when monitoring a standby server, 'wal_file' probe shouldn't be loaded.
probes = *
# Interval, in second, between each run of the process executing
# the probes. Default: 60
# scheduler_interval = 60

[administration]
# External command used for start/stop PostgreSQL.
# This commands actually works on Debian jessie.
pg_ctl = '/usr/lib/postgresql/9.4/bin/pg_ctl %s -D /var/lib/postgresql/9.4'

[statements]
# Statements plugin part.
# DB name hosting pg_stat_statements view (the one where the extension has
# been created with "CREATE EXTENSION")
dbname = postgres

Once more, adjust the the systemd service file (I am creating a static one here):

localhost:~ $ cat /usr/lib/systemd/system/temboard-age[email protected]
[Unit]
Description=PostgreSQL Remote Control Agent %I
After=network.target [email protected]%i.service
AssertPathExists=/u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.conf

[Service]
Type=simple
User=postgres
Group=postgres
ExecStart=/usr/bin/env SYSTEMD=1 temboard-agent -c /u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.conf

[Install]
WantedBy=multi-user.target
localhost:~ $ mv /usr/lib/systemd/system/[email protected] /usr/lib/systemd/system/temboard-agent.service
localhost:~ $ systemctl daemon-reload
localhost:~ $ systemctl status temboard-agent.service
● temboard-agent.service - PostgreSQL Remote Control Agent 
   Loaded: loaded (/usr/lib/systemd/system/temboard-agent.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Before starting with systemd, lets try to start with the postgres user. Before we do that we need to create a user which will be used for authentication later on:

localhost:~ $ su - postgres
[email protected]:/home/postgres/ [pg132] temboard-agent-adduser -c /u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.conf
 INFO: Starting temboard-agent-adduser 7.6.
ERROR: Invalid temboard_ssl_key_file from config: /etc/ssl/private/temboard-agent-13-pg5432.key: File not found...
CRITI: Failed to load configuration.
[email protected]:/home/postgres/ [pg132] sudo ls -l /etc/ssl/private/temboard-agent-13-pg5432.key
-rw------- 1 root root 1704 Apr  1 11:46 /etc/ssl/private/temboard-agent-13-pg5432.key

Again the issue with the key file, so:

[email protected]:/home/postgres/ [pg132] sudo mv /etc/ssl/private/temboard-agent-13-pg5432.key /u01/app/postgres/local/dmk/etc/
[email protected]:/home/postgres/ [pg132] sudo chown postgres:postgres /u01/app/postgres/local/dmk/etc/temboard-agent-13-pg5432.key
[email protected]:/home/postgres/ [pg132] cat /u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.conf | grep key
# SSL: private key file path (.key)
ssl_key_file = /u01/app/postgres/local/dmk/etc/temboard-agent-13-pg5432.key
key = SECRETKEYTOBECHANGED

Once more:

[email protected]:/home/postgres/ [pg132] temboard-agent-adduser -c /u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.conf
 INFO: Starting temboard-agent-adduser 7.6.
ERROR: Invalid temboard_ssl_key_file from config: /etc/ssl/private/temboard-agent-13-pg5432.key: File not found...
CRITI: Failed to load configuration.

Seems the location of the key file is somehow hard coded, so workaround this like this:

[email protected]:/home/postgres/ [pg132] sudo ln -s /u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.key /etc/ssl/private/temboard-agent-13-pg5432.key
[email protected]:/home/postgres/ [pg132] sudo chmod 755 /etc/ssl/private
[email protected]:/home/postgres/ [pg132] ls /etc/ssl/private/temboard-agent-13-pg5432.key
/etc/ssl/private/temboard-agent-13-pg5432.key
[email protected]:/home/postgres/ [pg132] temboard-agent-adduser -c /u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.conf
 INFO: Starting temboard-agent-adduser 7.6.
Username: admin
Password: 
Retype password: 
Done.

The user/password combination will be written to the users file:

[email protected]:/home/postgres/ [pg132] cat /u01/app/postgres/local/dmk/etc/13/pg5432/users 
admin:xiet7KLumux50Q2dmV/FBue2zqtexElavkVAKnEYN/rw2YLIn51TQsXb3u8FPm4wiuHUTtEjjvBIrtBPAgRMsA==

That should be all and we should be able to start the agent:

[email protected]:/home/postgres/ [pg132] temboard-agent --config /u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.conf 
 INFO: Starting temboard-agent 7.6.
 INFO: Found plugin monitoring = temboardagent.plugins.monitoring:MonitoringPlugin.
 INFO: Found plugin dashboard = temboardagent.plugins.dashboard:DashboardPlugin.
 INFO: Found plugin pgconf = temboardagent.plugins.pgconf:PgConfPlugin.
...
 INFO: Starting .
 INFO: Starting .
 INFO: Starting .

Looks fine, lets try with systemd:

sles15tbagent:/home/postgres $ systemctl start temboard-agent.service
sles15tbagent:/home/postgres $ systemctl status temboard-agent.service
● temboard-agent.service - PostgreSQL Remote Control Agent 
   Loaded: loaded (/usr/lib/systemd/system/temboard-agent.service; disabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-04-03 14:42:21 CEST; 4s ago
 Main PID: 9299 (temboard-agent)
    Tasks: 5
   CGroup: /system.slice/temboard-agent.service
           β”œβ”€9299 temboard-agent: 13/pg5432: main process
           β”œβ”€9301 temboard-agent: 13/pg5432: worker pool
           └─9302 temboard-agent: 13/pg5432: scheduler

sles15tbagent:/home/postgres $ ps -ef | grep temboard
postgres  9299     1  0 14:42 ?        00:00:00 temboard-agent: 13/pg5432: main process
postgres  9301  9299  0 14:42 ?        00:00:00 temboard-agent: 13/pg5432: worker pool
postgres  9302  9299  0 14:42 ?        00:00:00 temboard-agent: 13/pg5432: scheduler
root      9804  9249  0 14:44 pts/1    00:00:00 grep --color=auto temboard

The final step is to register the agent to the WebUI:

[email protected]:/home/postgres/ [PG1] temboard-agent-register -c /u01/app/postgres/local/dmk/etc/13/pg5432/temboard-agent.conf --host $(hostname --fqdn) --port 2345 --groups default https://192.168.22.210:8888
 INFO: Starting temboard-agent-register 7.6.
 INFO: Getting system & PostgreSQL informations from the agent (https://sles15tbagent:2345/discover) ...
Login at https://192.168.22.210:8888 ...
 Username: admin
 Password: 
Registering instance/agent to https://192.168.22.210:8888 ...
Done.

Heading over to the WebUI confirms, that the agent is registered and the PostgreSQL instance is monitored:

So, even if there are no pre-build packages for your distribution, it should be quite easy to get temBoard up and running.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Daniel Westermann
Daniel Westermann

Principal Consultant & Technology Leader Open Infrastructure