Skip to content

Commit

Permalink
Finalize systemd service, timer and documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
darold committed Jul 9, 2017
1 parent c7c3f85 commit bd54cd1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 48 deletions.
34 changes: 15 additions & 19 deletions README
Expand Up @@ -96,30 +96,26 @@ USAGE
not already exits.

Using systemd unit files
pgcluu comes with a systemd service file pgcluu.service and a timer unit
file pgcluu.timer. The last one will trigger the first one periodically.
This is sample files that you may want to adapt following your needs.
pgcluu comes with systemd service files:

Default for pgcluu.service has been set to end after 3 minutes with the
--end-after=3M option. Edit the file to set path to your $OUTPUTDIR and
$STATDIR, and $PGPASSWORD. Change if needed how long the collect will
last.
- pgcluu_collectd.service: execute pgcluu_collectd as a daemon to collect statistics.
- pgcluu.service: execute pgcluu to generate reports.
- pgcluu.timer: run periodically pgcluu.service

Default for pgcluu.timer has been set to start pgcluu.service every
three hours with the OnUnitActiveSec=3h. Again, change it if needed.
Refer to man:systemd.timer(5) for more options.
This is sample files that you may want to adapt to your Linux
distribution or your needs. To install them after editing use commands
below:

Once the two files have been edited accordingly, copy them in your
system systemd directory, /etc/systemd/system. As root, start and enable
the timer:
cp pgcluu_collectd.service /usr/lib/systemd/system/
cp pgcluu.service /usr/lib/systemd/system/
cp pgcluu.timer /usr/lib/systemd/system/

systemctl start pgcluu.timer
systemctl daemon-reload
systemctl enable pgcluu_collectd.service
systemctl enable pgcluu.service
systemctl enable pgcluu.timer

You can at anytime see if the timer is still active with the following
command:

systemctl list-timers
systemctl start pgcluu_collectd.service
systemctl start pgcluu.timer

COLLECTING STATISTICS
To generate reports about your PostgreSQL Cluster Utilization you must
Expand Down
30 changes: 14 additions & 16 deletions doc/pgCluu.pod
Expand Up @@ -103,27 +103,25 @@ generated into the output directory if those files does not already exits.

=head3 Using systemd unit files

pgcluu comes with a systemd service file pgcluu.service and a timer unit file
pgcluu.timer. The last one will trigger the first one periodically. This is
sample files that you may want to adapt following your needs.
pgcluu comes with systemd service files:

Default for pgcluu.service has been set to end after 3 minutes with the
--end-after=3M option. Edit the file to set path to your $OUTPUTDIR and
$STATDIR, and $PGPASSWORD. Change if needed how long the collect will last.
- pgcluu_collectd.service: execute pgcluu_collectd as a daemon to collect statistics.
- pgcluu.service: execute pgcluu to generate reports.
- pgcluu.timer: run periodically pgcluu.service

Default for pgcluu.timer has been set to start pgcluu.service every three
hours with the OnUnitActiveSec=3h. Again, change it if needed. Refer to
man:systemd.timer(5) for more options.
This is sample files that you may want to adapt to your Linux distribution or
your needs. To install them after editing use commands below:

Once the two files have been edited accordingly, copy them in your system
systemd directory, /etc/systemd/system. As root, start and enable the timer:
cp pgcluu_collectd.service /usr/lib/systemd/system/
cp pgcluu.service /usr/lib/systemd/system/
cp pgcluu.timer /usr/lib/systemd/system/

systemctl start pgcluu.timer
systemctl daemon-reload
systemctl enable pgcluu_collectd.service
systemctl enable pgcluu.service
systemctl enable pgcluu.timer

You can at anytime see if the timer is still active with the following command:

systemctl list-timers
systemctl start pgcluu_collectd.service
systemctl start pgcluu.timer

=head1 COLLECTING STATISTICS

Expand Down
10 changes: 7 additions & 3 deletions pgcluu.service
Expand Up @@ -7,15 +7,19 @@


[Unit]
Description=Postgresql performance and auditing
Description=Postgresql performance and auditing reporting
Documentation=man:pgcluu(1)


[Service]
PermissionsStartOnly=true
User=postgres
Environment=STATDIR=/var/lib/pgcluu/data
Environment=REPORTDIR=/var/lib/pgcluu/report
ExecStartPre=-/usr/bin/find ${REPORTDIR} -mindepth 1 -type f -delete
ExecStart=/usr/local/bin/pgcluu -o ${REPORTDIR} ${STATDIR}
ExecStartPre=-/bin/mkdir -p $REPORTDIR
ExecStartPre=-/bin/chown postgres: $REPORTDIR
ExecStart=/usr/local/bin/pgcluu -o $REPORTDIR $STATDIR

[Install]
WantedBy=multi-user.target

4 changes: 2 additions & 2 deletions pgcluu.timer
Expand Up @@ -2,8 +2,8 @@
Description=Run periodically pgcluu.service

[Timer]
OnBootSec=15min
OnUnitActiveSec=1h
OnBootSec=5min
OnUnitActiveSec=5min

[Install]
WantedBy=timers.target
Expand Down
22 changes: 14 additions & 8 deletions pgcluu_collectd.service
@@ -1,25 +1,31 @@
# Start script to run pgcluu_collectd as daemon
#
# Feel free to modify the name of the PostgreSQL service following
# Feel free to modify the name of the PostgreSQL service and the path to following
# your installation.
#
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F



[Unit]
Description=Postgresql performance and auditing
Description=Postgresql performance and auditing statistics collecting
Documentation=man:pgcluu(1)
After=postgresql-9.x.service
Wants=postgresql-9.x.service


[Service]
Type=forking
PermissionsStartOnly=true
User=postgres
Environment=STATDIR=/var/lib/pgcluu/data
ExecStart=/usr/local/bin/pgcluu_collectd -D $STATDIR
ExecReload=/bin/kill -HUP $MAINPID
Environment=PIDFILE=/var/run/postgresql/pgcluu_collectd.pid
ExecStartPre=-/bin/mkdir -p $STATDIR
ExecStartPre=-/bin/chown postgres: $STATDIR
ExecStart=/usr/local/bin/pgcluu_collectd --daemonize --rotate-daily --pid-file $PIDFILE $STATDIR
ExecStop=/usr/local/bin/pgcluu_collectd -k --pid-file $PIDFILE
KillMode=process
Restart=on-failure
RestartSec=60s
PIDFile=/var/run/postgresql/pgcluu_collectd.pid

[Install]
WantedBy=multi-user.target

0 comments on commit bd54cd1

Please sign in to comment.