| 1 |
NAME |
| 2 |
pgCluu - PostgreSQL Cluster utilization |
| 3 |
|
| 4 |
DESCRIPTION |
| 5 |
pgCluu is a PostgreSQL performance monitoring and auditing tool. |
| 6 |
|
| 7 |
It is a Perl program used to perform a full audit of a PostgreSQL |
| 8 |
Cluster and System performance. It is divided in two parts: |
| 9 |
|
| 10 |
- A collector used to grab statistics on the PostgreSQL cluster using |
| 11 |
the psql command line utility and sar from the sysstat package. |
| 12 |
|
| 13 |
- A pure Perl grapher that will generate all HTML and charts output |
| 14 |
without any requirements. |
| 15 |
|
| 16 |
If you don't need system utilization reports or don't want to install |
| 17 |
the sysstat package, you can disable it at command line. You will only |
| 18 |
have reports about your PostgreSQL Cluster. If you are running pgCluu |
| 19 |
from a central server using option -h to monitor remotely a PostgreSQL |
| 20 |
Cluster, the call to sar is automatically disabled. |
| 21 |
|
| 22 |
If you just want to have system utilization reports or generate graphs |
| 23 |
from a sar data file, it's also possible. |
| 24 |
|
| 25 |
SYNOPSIS |
| 26 |
PostgreSQL and System metrics collector. |
| 27 |
|
| 28 |
pgcluu_collectd [options] output_dir |
| 29 |
|
| 30 |
Report generator. |
| 31 |
|
| 32 |
pgcluu [options] -o report_dir input_dir |
| 33 |
|
| 34 |
REQUIREMENT |
| 35 |
pgCluu comes with two Perl scripts. You need a modern Perl distribution, |
| 36 |
the psql client and the sar command line utility (sysstat). The sysstat |
| 37 |
package is optional, you can still use pgCluu to generate reports about |
| 38 |
your PostgreSQL Cluster without it. |
| 39 |
|
| 40 |
Charts are rendered using a Javascript library so you don't need |
| 41 |
anything else. Your browser will do all the work. |
| 42 |
|
| 43 |
INSTALLATION |
| 44 |
Installation from package |
| 45 |
Installation of pgCluu can be done through the PostgreSQL Global |
| 46 |
Development Group (PGDG) repositories. See how to install the PGDG |
| 47 |
repositories at the following URLs for Debian and Ubuntu: |
| 48 |
|
| 49 |
https://wiki.postgresql.org/wiki/Apt |
| 50 |
|
| 51 |
and Redhat, CentOs, Fedora, Scientific Linux and Oracle Enterprise |
| 52 |
Linux: |
| 53 |
|
| 54 |
https://yum.postgresql.org/ |
| 55 |
|
| 56 |
Once it is done you can simply install pgCluu with commands: |
| 57 |
|
| 58 |
sudo apt install pgcluu |
| 59 |
sudo yum install pgcluu |
| 60 |
|
| 61 |
Look at the package information to know where files are specifically |
| 62 |
installed. See next two chapters to see which default installation paths |
| 63 |
are used. |
| 64 |
|
| 65 |
Installation from sources |
| 66 |
Download the tarball from GitHub and unpack the archive: |
| 67 |
|
| 68 |
tar xzf pgcluu-3.x.tar.gz |
| 69 |
cd pgcluu-3.x/ |
| 70 |
perl Makefile.PL |
| 71 |
make && sudo make install |
| 72 |
|
| 73 |
This will copy the Perl scripts pgcluu_collectd and pgcluu into |
| 74 |
/usr/local/bin directory and the man page to |
| 75 |
/usr/local/share/man/man1/pgcluu.1p.gz. Those are the default |
| 76 |
installation directories for 'site' install on some well-known |
| 77 |
distribution but the path could change. |
| 78 |
|
| 79 |
If you want to install all under /usr location, use INSTALLDIRS='vendor' |
| 80 |
as an argument of Makefile.PL. The script will be installed into |
| 81 |
/usr/bin/pgcluu and the manpage into /usr/share/man/man1/pgcluu.1p.gz. |
| 82 |
|
| 83 |
For example, to install everything just like Debian does, proceed as |
| 84 |
follows: |
| 85 |
|
| 86 |
perl Makefile.PL INSTALLDIRS=vendor |
| 87 |
|
| 88 |
By default INSTALLDIRS is set to site. |
| 89 |
|
| 90 |
The directory where statistics will be saved is /var/lib/pgcluu/data and |
| 91 |
the default directory for reports is /var/lib/pgcluu/report. |
| 92 |
|
| 93 |
The CGI script is installed into /var/lib/cgi-bin/pgcluu.cgi and the |
| 94 |
Apache configuration file into /etc/apache/conf-available/pgcluu.conf. |
| 95 |
This file allow acces to resources files (CSS and JS files) from |
| 96 |
installation directory /usr/local/share/pgcluu/rsc/. Access is granted |
| 97 |
to local user only by default. |
| 98 |
|
| 99 |
All scripts (pgcluu_collectd, pgcluu and pgcluu.cgi) are reading |
| 100 |
configuration file from /usr/local/etc/pgcluu.conf. This file is mainly |
| 101 |
use by the CGI script but some directives are dedicated to |
| 102 |
pgcluu_collectd and pgcluu script to define the retention days for |
| 103 |
example. |
| 104 |
|
| 105 |
Custom installation |
| 106 |
The installation of pgCluu can be fully customized through environment |
| 107 |
variables (RSCDIR,CGIDIR,CONFDIR,PIDDIR,STATDIR,APACHECONF,MANDIR, |
| 108 |
DOCDIR,SYSTEMDDIR,RETENTION). These variables are passed to Makefile.PL |
| 109 |
as command line arguments or can be exported as environment variables |
| 110 |
before running "perl Makefile.PL". |
| 111 |
|
| 112 |
The default values for these variables are: |
| 113 |
|
| 114 |
DESTDIR => /usr/local |
| 115 |
INSTALLDIRS => site |
| 116 |
CONFDIR => DESTDIR/etc |
| 117 |
PIDDIR => /var/run/postgres |
| 118 |
STATDIR => /var/lib/pgcluu/data |
| 119 |
REPORTDIR => /var/lib/pgcluu/data |
| 120 |
RSCDIR => DESTDIR/share/pgcluu |
| 121 |
CGIDIR => /usr/lib/cgi-bin |
| 122 |
APACHECONF => /etc/apache2/conf-available |
| 123 |
MANDIR => DESTDIR/share/man |
| 124 |
DOCDIR => DESTDIR/share/doc |
| 125 |
SYSTEMDIR => DESTDIR/lib/systemd/system |
| 126 |
RETENTION => 0 |
| 127 |
|
| 128 |
If INSTALLDIRS is set to 'vendor': |
| 129 |
|
| 130 |
CONFDIR => /etc |
| 131 |
DESTDIR => /usr |
| 132 |
|
| 133 |
The configuration file is auto-generated by the Makefile.PL script and |
| 134 |
saved into CONFDIR/pgcluu.conf. If the destination file exists it is not |
| 135 |
overridden. The file is also saved as example in the directory |
| 136 |
DOCDIR/pgcluu/examples/pgcluu.conf.dist |
| 137 |
|
| 138 |
The directory where pgcluu_collectd will store statistics is defined |
| 139 |
with STATDIR which is by default /var/lib/pgcluu/data. The directory |
| 140 |
where pgcluu will generate static html reports is defined by REPORTDIR. |
| 141 |
The default is /var/lib/pgcluu/report. Both directory must be owned by |
| 142 |
the postgres user. |
| 143 |
|
| 144 |
The man page is saved as DESTDIR/share/man/pgcluu.1p.gz and a symbolic |
| 145 |
link pgcluu_collectd.1p.gz is created to this file. The documentation, |
| 146 |
README, changelog.gz, LICENSE files are saved under DESTDIR/share/doc/. |
| 147 |
|
| 148 |
For the CGI mode, the resources (css and js files from the cgi-bin/rsc) |
| 149 |
are saved under the DESTDIR/share/pgcluu/rsc directory. The CGI script |
| 150 |
is saved under /usr/lib/cgi-bin/pgcluu.cgi. The Apache configuration |
| 151 |
file under /etc/apache2/conf-available/pgcluu.conf with a symbolic link |
| 152 |
/etc/apache2/conf-enabled/pgcluu.conf created to this file. Its content: |
| 153 |
|
| 154 |
Alias /pgcluu RSCDIR/ |
| 155 |
<Directory RSCDIR/> |
| 156 |
Options FollowSymLinks MultiViews |
| 157 |
AllowOverride None |
| 158 |
Require local |
| 159 |
#Require ip 192.1.168.0/24 |
| 160 |
</Directory> |
| 161 |
|
| 162 |
The systemd files (pgcluu_collectd.service,pgcluu.service,pgcluu.timer) |
| 163 |
are saved as examples into DOCDIR/pgcluu/examples/ and into the systemd |
| 164 |
directory SYSTEMDDIR/ |
| 165 |
|
| 166 |
The right path to the configuration file is set into all scripts pgcluu, |
| 167 |
pgcluu_collectd and pgcluu.cgi. The path where the pid file must be |
| 168 |
saved is replaced into pgcluu_collectd with the value of PIDFILE |
| 169 |
variable. |
| 170 |
|
| 171 |
Paths to scripts, pid directory, statistics and reports are replaced in |
| 172 |
all systemd service files following the values of the environment |
| 173 |
variable explain here. |
| 174 |
|
| 175 |
USAGE |
| 176 |
Manually |
| 177 |
See next two chapters for a complete description of the command line |
| 178 |
options. For the impatient, here some simple commands that could be run |
| 179 |
as postgres user: |
| 180 |
|
| 181 |
mkdir /tmp/stat_db1/ |
| 182 |
pgcluu_collectd -D -i 60 /tmp/stat_db1/ |
| 183 |
LOG: Detach from terminal with pid: 11323 |
| 184 |
|
| 185 |
or with more options |
| 186 |
|
| 187 |
pgcluu_collectd -D -i 60 /tmp/stat_db1/ -h 10.10.1.1 -U postgres -d mydb |
| 188 |
LOG: Detach from terminal with pid: 14671 |
| 189 |
|
| 190 |
wait some time and activity on your PostgreSQL Cluster... Then stop the |
| 191 |
pgcluu_collectd daemon and generate the report: |
| 192 |
|
| 193 |
pgcluu_collectd -k |
| 194 |
LOG: Received terminating signal. |
| 195 |
mkdir /tmp/report_db1/ |
| 196 |
pgcluu -o /tmp/report_db1/ /tmp/stat_db1/ |
| 197 |
|
| 198 |
You should obtain something like example at |
| 199 |
http://pgcluu.darold.net/example/ |
| 200 |
|
| 201 |
By default all javascript, css and the webfont fontawesome are |
| 202 |
automatically generated into the output directory if those files does |
| 203 |
not already exits. |
| 204 |
|
| 205 |
Using systemd unit files |
| 206 |
pgcluu comes with systemd service files: |
| 207 |
|
| 208 |
- pgcluu_collectd.service: execute pgcluu_collectd as a daemon to collect statistics. |
| 209 |
- pgcluu.service: execute pgcluu to generate reports. |
| 210 |
- pgcluu.timer: run periodically pgcluu.service |
| 211 |
|
| 212 |
These files are installed automatically by the install script or the |
| 213 |
package into /lib/systemd/system/. To activate these services proceed as |
| 214 |
follow: |
| 215 |
|
| 216 |
systemctl daemon-reload |
| 217 |
systemctl enable pgcluu_collectd.service |
| 218 |
systemctl enable pgcluu.service |
| 219 |
systemctl enable pgcluu.timer |
| 220 |
systemctl start pgcluu_collectd.service |
| 221 |
systemctl start pgcluu.timer |
| 222 |
|
| 223 |
Be warn that storing indefinitely statistics with pgcluu_collectd can |
| 224 |
fill you disk space in the short or medium term. You have to remove |
| 225 |
obsolete statistics manually using a cron job or using the embedded |
| 226 |
retention feature by adding option '--retention ndays' to |
| 227 |
pgcluu_collectd call or by changing the value of |
| 228 |
STATS_COLLECTD_RETENTION configuration directive in file |
| 229 |
/usr/local/etc/pgcluu.conf or /etc/pgcluu.conf file following your |
| 230 |
installation. You can also set STATS_REPORT_RETENTION to limit the |
| 231 |
retention of reports directories or use option '--retention ndays' with |
| 232 |
pgcluu. Default is to preserve collected data for the past 30 days. |
| 233 |
|
| 234 |
If you want to use the CGI mode you also have activate pgcluu caching by |
| 235 |
enabling value STATS_REPORT_CACHING in the configuration file and using |
| 236 |
pgcluu.service+pgcluu.timer. If you don"t want to use systemd you can |
| 237 |
simply run pgcluu script with the -C option and execute it periodically |
| 238 |
through a cron job. |
| 239 |
|
| 240 |
Note that the systemd service files set the privilege to the data and |
| 241 |
report directory to user postgres and group www-data. By this way |
| 242 |
reports are readable through an httpd server for static reports and data |
| 243 |
are readable through the CGI if enabled. Command executed by the |
| 244 |
pgcluu_collectd.service file (daemon part) are: |
| 245 |
|
| 246 |
/bin/mkdir -p $STATDIR |
| 247 |
/bin/chown postgres:www-data $STATDIR |
| 248 |
/bin/chmod u=rwX,g=rsX,o= $STATDIR |
| 249 |
|
| 250 |
The pgcluu.service file (client part) execute commands: |
| 251 |
|
| 252 |
/bin/mkdir -p $REPORTDIR |
| 253 |
/bin/chown postgres:www-data $REPORTDIR |
| 254 |
/bin/chmod u=rwX,g=rsX,o= $REPORTDIR |
| 255 |
|
| 256 |
In case you don't want to use systemd service files you will have to |
| 257 |
execute these commands manually before tunning pgCluu. |
| 258 |
|
| 259 |
For pgcluu reports, the output directory can be defined in the |
| 260 |
configuration file using the STATS_REPORT_OUTDIR directive. |
| 261 |
|
| 262 |
COLLECTING STATISTICS |
| 263 |
To generate reports about your PostgreSQL Cluster Utilization you must |
| 264 |
collect statistics before. pgcluu_collectd is here for that. It can be |
| 265 |
run in a daemon mode (option -D) or in interactive mode for debugging |
| 266 |
purpose. All you need is to provide a directory where data will be |
| 267 |
stored. Statistics will be pooled at a default interval of 60 seconds, |
| 268 |
using option -i you can customize it. See below for a complete list of |
| 269 |
command line options. |
| 270 |
|
| 271 |
pgcluu_collectd usage |
| 272 |
usage: pgcluu_collectd [options] output_dir |
| 273 |
|
| 274 |
output_dir: full path to directory where pgcluu_collectd will |
| 275 |
store statistics. |
| 276 |
|
| 277 |
options: |
| 278 |
|
| 279 |
-B, --enable-buffercache enable buffercache statistics if pg_buffercache |
| 280 |
extension is installed. |
| 281 |
-c, --capture create a snapshot of the PostgreSQL installation |
| 282 |
into tmp/pgcluu_capture.tar.gz. |
| 283 |
-C, --end-counter=NUM terminate program after NUM reports. |
| 284 |
-d, --dbname=DATABASE database name to connect to. Default to current user. |
| 285 |
-D, --daemonize detach from console and enter in daemon mode. |
| 286 |
-E, --end-after=NUM self terminate the program after a given number of |
| 287 |
seconds. Can be written: 7200 or 120M or 2H, for |
| 288 |
days use 7D for example to stop collecting data |
| 289 |
after seven days. |
| 290 |
-f, --pid-file=FILE path to pid file. Default: /var/run/postgresql/pgcluu_collectd.pid. |
| 291 |
-h, --host=HOSTNAME database server host or socket directory |
| 292 |
-i, --interval=NUM time to wait between runs |
| 293 |
-k, --kill stop current pgcluu_collectd running daemon. |
| 294 |
-m, --metric=METRIC set a coma separated list of metrics to perform. |
| 295 |
-M, --max-size=SIZE self terminate program when the size of the output |
| 296 |
directory exceed a given size. Can be written: 2GB |
| 297 |
or 2000MB. |
| 298 |
-n, --no-pg_stats-dump don't collect statistics from the pg_stats view. |
| 299 |
-p, --port=PORT database port(s) to connect to. Defaults to 5432. |
| 300 |
-P, --psql=BIN path to the psql command. Default: psql. |
| 301 |
-Q, --no-statement do not collect statistics from pg_stat_statements. |
| 302 |
-r, --rotate-daily force daily rotation of data files. |
| 303 |
-R, --rotate-hourly force hourly rotation of data files. |
| 304 |
-s, --sar=BIN path to sar sysstat command. Default: sar. |
| 305 |
-S, --disable-sar disable collect of system statistics with sar. |
| 306 |
-t, --lock-timeout=NUM terminate metric SQL query after N second in case it |
| 307 |
wait too much time because of a lock. Default: 3 |
| 308 |
-T, --no-tablespace disable lookup at tablespace when the connect user |
| 309 |
is not superuser to avoid printing an error message. |
| 310 |
-U, --dbuser=USERNAME database user to connect as. Default to current user. |
| 311 |
-v, --verbose Print out debug informations. |
| 312 |
-V, --version Show pgcluu_collectd version and exit. |
| 313 |
-w, --no-waitevent don't collect wait event stats from pg_wait_sampling. |
| 314 |
-W, --password=pass database password. |
| 315 |
-z, --compress force compression of rotated data files. |
| 316 |
--included-db=DATABASE collect statistics only for those databases present |
| 317 |
in a comma separated list of database names. |
| 318 |
--list-metric list available metrics actions that can be performed. |
| 319 |
--sysinfo get operating system infos and exit (sysinfo.txt). |
| 320 |
--no-sysinfo do not collect operating system information at all. |
| 321 |
--no-database do not collect database statistics at all. |
| 322 |
--pgbouncer-args=OPTIONS Option to used to connect to the pgbouncer system |
| 323 |
database. Ex: -p 6432 -U postgres -h 192.168.1.100 |
| 324 |
You must at least give one parameter to enable |
| 325 |
pgbouncer monitoring. |
| 326 |
--sar-file=FILE path to sar output data file for sysstat stats |
| 327 |
Default to output_dir/sar_stats.dat. |
| 328 |
--stat-type all|user Set stats tables to read. Values: 'all' or 'user' to |
| 329 |
look at pg_stat_(all|user) tables. Default: user. |
| 330 |
--pgversion X.Y force the PostgreSQL version to the given value. |
| 331 |
--pgservice NAME Name of service inside of the pg_service.conf file. |
| 332 |
--exclude-time RANGE exclude a laps of time by giving the start and end |
| 333 |
hours. |
| 334 |
--cron-user=USERNAME collect crontab settings for the given username (in |
| 335 |
this case pgcluu_collectd need to be run as root). |
| 336 |
Default is to use USERNAME environment variable or |
| 337 |
postgres when it is not defined. |
| 338 |
--package-list=CMD command to list PostgreSQL packages. Default is to |
| 339 |
autodetect package type and using command 'rpm -qa' |
| 340 |
or 'dpkg -l'. If you have an other system you can |
| 341 |
set a custom command. A filter on keyword 'postgres' |
| 342 |
is appended to the command: ' | grep postgres'. |
| 343 |
--retention NDAYS number of rolling days to keep in data directory in |
| 344 |
incremental mode. Default is to store indefinitely. |
| 345 |
--disable-pidstat do not collect metrics from pidstat command. |
| 346 |
--help print usage |
| 347 |
|
| 348 |
Use those options to execute sar on the remote host defined by the -h |
| 349 |
option, otherwise it will be executed locally: |
| 350 |
|
| 351 |
--enable-ssh activate the use of ssh to run sysstat remotely. |
| 352 |
--ssh-program ssh path to the ssh program to use. Default: ssh. |
| 353 |
--ssh-user username connection login name. Default to running user. |
| 354 |
--ssh-identity file path to the identity file to use. |
| 355 |
--ssh-timeout second timeout to ssh connection failure. Default 10. |
| 356 |
--ssh-options options list of -o options to use for the ssh connection. |
| 357 |
Options always used: |
| 358 |
-o ConnectTimeout=$ssh_timeout |
| 359 |
-o PreferredAuthentications=hostbased,publickey |
| 360 |
|
| 361 |
For example, as postgres user to monitor locally a full PostgreSQL |
| 362 |
cluster: |
| 363 |
|
| 364 |
mkdir /tmp/stat_db1/ |
| 365 |
pgcluu_collectd -D -i 60 /tmp/stat_db1/ |
| 366 |
|
| 367 |
to collect statistics from pgbouncer too, and limit database statistics |
| 368 |
to a single database: |
| 369 |
|
| 370 |
pgcluu_collectd -D -i 60 /tmp/stat_db1/ -h 10.10.1.1 -U postgres -d mydb |
| 371 |
--pgbouncer-args='-p 5342' |
| 372 |
|
| 373 |
to disable statistics collect between 22:30 and 06:30 the next day: |
| 374 |
|
| 375 |
pgcluu_collectd -D -i 60 /tmp/stat_db1/ --exclude-time "22:30-06:30" |
| 376 |
|
| 377 |
to collect statistics from a remote server: |
| 378 |
|
| 379 |
pgcluu_collectd -D -i 60 /tmp/statdb1/ -h 10.0.0.1 -U postgres --disable-sar |
| 380 |
|
| 381 |
the same but with collecting system statistics using remote sar calls: |
| 382 |
|
| 383 |
pgcluu_collectd -D -i 60 /tmp/statdb1/ -h 10.0.0.1 -U postgres --enable-ssh |
| 384 |
--ssh-user postgres --ssh-identity /var/lib/postgresql/.ssh/id_rsa.pub |
| 385 |
|
| 386 |
You may need a .pgpass and be able to establish passwordless ssh |
| 387 |
connections to be able to collect statistics from remote hosts. |
| 388 |
|
| 389 |
Then after some time and activities on the database, stop the daemon as |
| 390 |
follow: |
| 391 |
|
| 392 |
pgcluu_collectd -k |
| 393 |
|
| 394 |
or by sending sigterm to the pgcluu_collectd's pid. |
| 395 |
|
| 396 |
You can run the collector in incremental mode using a daily or a hourly |
| 397 |
statistics rotation: |
| 398 |
|
| 399 |
pgcluu_collectd -D -i 60 /tmp/stat_db1/ --rotate-daily |
| 400 |
|
| 401 |
On a server with huge activity you may want to use --rotate-hourly and |
| 402 |
compression mode with --compress option. If you have limited disk space |
| 403 |
you can restrict the retention time of statistics files using option |
| 404 |
--retention with the storage day limit. |
| 405 |
|
| 406 |
Statistics files |
| 407 |
The output directory with all statistics collected should look likes: |
| 408 |
|
| 409 |
/tmp/stat_db1/ |
| 410 |
|-- commit_memory.csv |
| 411 |
|-- end-pg_statio_user_indexes.csv |
| 412 |
|-- end-pg_statio_user_sequences.csv |
| 413 |
|-- end-pg_statio_user_tables.csv |
| 414 |
|-- end-pg_stat_user_functions.csv |
| 415 |
|-- end-pg_stat_user_indexes.csv |
| 416 |
|-- end-pg_stat_user_tables.csv |
| 417 |
|-- end-pg_stat_xact_user_functions.csv |
| 418 |
|-- end-pg_stat_xact_user_tables.csv |
| 419 |
|-- fs_stat_use.csv |
| 420 |
|-- pg_class_size.csv |
| 421 |
|-- pg_database_size.csv |
| 422 |
|-- pg_db_role_setting.csv |
| 423 |
|-- pg_hba.conf |
| 424 |
|-- pg_ident.conf |
| 425 |
|-- pg_nondefault_settings.csv |
| 426 |
|-- pg_prepared_xact.csv |
| 427 |
|-- pg_settings.csv |
| 428 |
|-- pg_stat_archiver.csv |
| 429 |
|-- pg_stat_bgwriter.csv |
| 430 |
|-- pg_stat_connections.csv |
| 431 |
|-- pg_stat_count_indexes.csv |
| 432 |
|-- pg_stat_database_conflicts.csv |
| 433 |
|-- pg_stat_database.csv |
| 434 |
|-- pg_stat_hash_indexes.csv |
| 435 |
|-- pg_stat_invalid_indexes.csv |
| 436 |
|-- pg_statio_user_indexes.csv |
| 437 |
|-- pg_statio_user_sequences.csv |
| 438 |
|-- pg_statio_user_tables.csv |
| 439 |
|-- pg_stat_locks.csv |
| 440 |
|-- pg_stat_missing_fkindexes.csv |
| 441 |
|-- pg_stat_redundant_indexes.csv |
| 442 |
|-- pg_stat_replication.csv |
| 443 |
|-- pg_stat_unlogged.csv |
| 444 |
|-- pg_stat_unused_indexes.csv |
| 445 |
|-- pg_stat_user_functions.csv |
| 446 |
|-- pg_stat_user_indexes.csv |
| 447 |
|-- pg_stat_user_tables.csv |
| 448 |
|-- pg_stat_xact_user_functions.csv |
| 449 |
|-- pg_stat_xact_user_tables.csv |
| 450 |
|-- pg_tablespace_size.csv |
| 451 |
|-- pg_xlog_stat.csv |
| 452 |
|-- postgresql.auto.conf |
| 453 |
|-- postgresql.conf |
| 454 |
|-- sar_stats.dat |
| 455 |
|-- sysinfo.txt |
| 456 |
|
| 457 |
Then now you can proceed with pgcluu to generate reports. |
| 458 |
|
| 459 |
Additional statistics from extensions |
| 460 |
To be able to report top statements, wait events and subxact statistics |
| 461 |
you need to create the related extensions into a single database and use |
| 462 |
this database for primary connection to pgcluu_collectd using the -d |
| 463 |
option. |
| 464 |
|
| 465 |
The related extension are pg_stat_statements, pg_wait_sampling and |
| 466 |
pg_subxact_counters. |
| 467 |
|
| 468 |
Rotation and compression |
| 469 |
When used the --rotate-daily or --rotate-hourly commands line option |
| 470 |
will force pgcluu_collectd to rotate daily or hourly all statistic's |
| 471 |
files. In this case, statistics files will be created in a subdirectory |
| 472 |
based on rotation frequency, output_dir/year/month/day[/hour]. This is |
| 473 |
called the incremental mode. |
| 474 |
|
| 475 |
To save filesystem space it is possible to enable compression of all |
| 476 |
rotated files during the rotation process. Just activate the -z or |
| 477 |
--compress command line option. You can also use the --retention option |
| 478 |
to set the storage time limit in days. |
| 479 |
|
| 480 |
Incremental mode |
| 481 |
This mode is enabled when --rotate-daily or --rotate-hourly command line |
| 482 |
options are used. It allow pgcluu to build reports incrementally by days |
| 483 |
or hours. In this mode you don't have to build reports per day or hour |
| 484 |
pgcluu will do the work automatically, just give it the top statistics |
| 485 |
directory. |
| 486 |
|
| 487 |
pgcluu -o /var/www/pgcluu/reports/ /var/lib/pgcluu/data/ |
| 488 |
|
| 489 |
pgcluu will detect that --rotate-daily or --rotate-hourly have been used |
| 490 |
to collect data and generate reports for each day or hours stored. |
| 491 |
Previous directories already processed will not be processed again |
| 492 |
unless this was the the last one. |
| 493 |
|
| 494 |
The daily or hourly basis statistic storage also allow the use of the |
| 495 |
CGI script pgcluu.cgi to have dynamic reports and temporal search. See |
| 496 |
"Using dynamic mode" chapter. |
| 497 |
|
| 498 |
When used the --rotate-daily or --rotate-hourly commands line option |
| 499 |
will force pgcluu_collectd to rotate daily or hourly all statistic's |
| 500 |
files. In this case, statistics files will be created in a subdirectory |
| 501 |
based on rotation frequency, output_dir/year/month/day[/hour]. This is |
| 502 |
called the incremental mode. |
| 503 |
|
| 504 |
To save filesystem space it is possible to enable compression of all |
| 505 |
rotated files during the rotation process. Just activate the -z or |
| 506 |
--compress command line option. You can also use the --retention option |
| 507 |
to set the storage time limit in days. |
| 508 |
|
| 509 |
Capture mode |
| 510 |
The goal of this mode is to be able to obtain a simple report about the |
| 511 |
PostgreSQL installation without collected metrics others than database |
| 512 |
and tablespace size. This report can be use by ITs to better understand |
| 513 |
the configuration and things that need to be tuned. |
| 514 |
|
| 515 |
To enable this mode, just run pgcluu_collectd with the single option -c |
| 516 |
or --capture. Other command line options will not be taken in account. |
| 517 |
pgcluu_collectd will create e temporary directory /tmp/pgcluu_capture to |
| 518 |
store temporary data and will removed if after building a compressed tar |
| 519 |
archive: /tmp/pgcluu_capture.tar.gz. This is this archive that can be |
| 520 |
used with pgcluu to build a snapshot report of the instance. pgcluu will |
| 521 |
automatically detect this mode. |
| 522 |
|
| 523 |
GENERATING REPORTS |
| 524 |
Static HTML reports |
| 525 |
To generate a pgCluu report about a PostgreSQL Cluster you must, at |
| 526 |
least, have a directory that contains all data files generated by |
| 527 |
pgcluu_collectd or pgstats. In this directory, if you have a file named |
| 528 |
sar_stats.dat or sadc_stats.dat for binary sadc data file, it will be |
| 529 |
taken to build report about system utilization. If you just want to make |
| 530 |
a report from a sar file use the -i or -I options. |
| 531 |
|
| 532 |
usage: pgcluu [options] [-i sar_file | -I sadc_file] [input_dir] |
| 533 |
|
| 534 |
input_dir: directory where pgcluu_collectd or pgstats and sar data |
| 535 |
files are stored. |
| 536 |
|
| 537 |
options: -b, --begin datetime start date/time for the data to be parsed |
| 538 |
(time of current timezone). -C, --cache generate cache files only |
| 539 |
(.bin), no html output. -d, --db-only dbname only report for the whole |
| 540 |
cluster and the given database name. You can use it multiple time or |
| 541 |
give a comma separated list of database name. -D, --device-only dev only |
| 542 |
report I/O stats for a particular device You can use it multiple time or |
| 543 |
give a comma separated list of device name, ex: sda,sdc. -e, --end |
| 544 |
datetime end date/time for the data to be parsed (time of current |
| 545 |
timezone). -i, --sar-file=FILE path to the sar text data file to read to |
| 546 |
generate system reports. Default to input_dir/sar_stats.dat. -I, |
| 547 |
--sadc-file=FILE sadc binary data file to read to generate system |
| 548 |
reports. Default to input_dir/sadc_stats.dat. -n, --top-number Top |
| 549 |
number of tables or indexes I/O stats to show. Default is set to top 10. |
| 550 |
Set it to 0 to show all. -N, --network-only iface only report stats for |
| 551 |
a particular network interface. You can use it multiple times or give a |
| 552 |
comma separated list of network interfaces, ex: eth0,eth1. -o, |
| 553 |
--output=DIR output directory -r, --reverse-date By default pgcluu look |
| 554 |
at mm/dd/yy format in sar file. When enabled pgcluu will look at |
| 555 |
dd/mm/yy format. -s, --sadf=BIN path to the sadf sysstat command used to |
| 556 |
read the sadc binary data file. Default: /usr/bin/sadf. -S, |
| 557 |
--disable-sar disable collect of system statistics with sar. -t, |
| 558 |
--with-table table Only report for the whole tables and the given table |
| 559 |
name. You can use it multiple time or give a comma separated list of |
| 560 |
database name. -T, --no-table Do not report statistics related to |
| 561 |
tables. -v, --verbose Print out debug informations. -V, --version Show |
| 562 |
pgcluu version and exit. -x, --external-menu Save menu in menu.html and |
| 563 |
load it into each report using w3-include-html attribut from w3.js. This |
| 564 |
will only work if acces to HTML reports is through a Web server, not |
| 565 |
using the file:// protocol. -z, --timezone +/-XX Set the number of |
| 566 |
hour(s) from GMT of the timezone, Eg: -z +02 Usually autodetected. Use |
| 567 |
this to adjust date/time from the sar output, pgcluu use GMT time to |
| 568 |
draw charts. -Z, --stats-timezone +/-XX Set the number of hour(s) from |
| 569 |
GMT of the timezone. Eg: -Z +02 Usually autodetected. Use this to adjust |
| 570 |
date/time from the cluster and system stats output, pgcluu use GMT time. |
| 571 |
--from-sa-file instruct pgcluu that file specified by the -i option uses |
| 572 |
the standard system activity daily data file. --charset used to set the |
| 573 |
HTML charset to be used. Default: utf-8. --retention NDAYS number of |
| 574 |
rolling days to keep in report directory. Default is to store |
| 575 |
indefinitely. --help print usage |
| 576 |
|
| 577 |
For example, you can generate all HTML reports from data files stored |
| 578 |
into /tmp/stat_db1/ with the following commands: |
| 579 |
|
| 580 |
mkdir /tmp/report_db1/ |
| 581 |
pgcluu -o /tmp/report_db1/ /tmp/stat_db1/ |
| 582 |
|
| 583 |
If you just want reports of some databases, use the following: |
| 584 |
|
| 585 |
pgcluu -o /tmp/report_db1/ /tmp/stat_db1/ --db-only "db1,db2,db3" |
| 586 |
|
| 587 |
If you just want to create a report from a sar output file: |
| 588 |
|
| 589 |
sar -p -A 10 60 > /root/my_sar_file.txt |
| 590 |
pgcluu -o /tmp/report_sar/ -i /root/my_sar_file.txt |
| 591 |
|
| 592 |
or from a daily sa file: |
| 593 |
|
| 594 |
sar -p -A -f /var/log/sa/sa18 > /root/my_sar_file.txt |
| 595 |
pgcluu -o /tmp/report_sar/ -i /root/my_sar_file.txt --from-sa-file |
| 596 |
|
| 597 |
and from a sa binary file: |
| 598 |
|
| 599 |
pgcluu -o /tmp/report_sar/ -i /var/log/sysstat/sa22 |
| 600 |
|
| 601 |
or the sa text file if you don't have the same version of sysstat: |
| 602 |
|
| 603 |
pgcluu -o /tmp/report_sar/ -i /var/log/sysstat/sar23 --from-sa-file |
| 604 |
|
| 605 |
If pgcluu_collectd have been run in incremental mode you can limit the |
| 606 |
number of retention days used for the reports: |
| 607 |
|
| 608 |
pgcluu -o /tmp/report_sar/ /tmp/stat_db1/ --retention 30 |
| 609 |
|
| 610 |
A static report will be built for each day or hour following the |
| 611 |
rotation used with pgcluu_collectd. |
| 612 |
|
| 613 |
Dynamic reports (CGI) |
| 614 |
Dynamics reports are build by a CGI script named pgcluu.cgi that can be |
| 615 |
found in the cgi-bin repository of the source code. It allow you to |
| 616 |
select the time period to build reports and to look at all differents |
| 617 |
reports for this period just as with static HTML reports. After |
| 618 |
installation from sources or binary packages the CGI might be found in |
| 619 |
/usr/lib/cgi-bin/pgcluu.cgi or /var/www/cgi-bin/pgcluu.cgi following |
| 620 |
your distribution. |
| 621 |
|
| 622 |
To use pgCluu in CGI mode, you need a Web server (here we use Apache) |
| 623 |
and a cron task to build the cache periodically. |
| 624 |
|
| 625 |
First enable CGI mode. |
| 626 |
|
| 627 |
sudo a2enmod cgi |
| 628 |
sudo service apache2 restart |
| 629 |
|
| 630 |
Then the CGI need to find the statistics directory where pgcluu_collectd |
| 631 |
mostly /var/lib/pgcluu/data/. The content of this repository must be |
| 632 |
readable by the Apache user (www-data). |
| 633 |
|
| 634 |
Take care to restrict access to your server and the CGI as information |
| 635 |
about your database and server are exposed in the reports. |
| 636 |
|
| 637 |
The CGI script, pgcluu.cgi, use resources files (CSS and javascript). |
| 638 |
They are stored in the cgi-bin/rsc/ directory of the source |
| 639 |
distribution. Install this repository onto the DocumentRoot of your Web |
| 640 |
server, for example: |
| 641 |
|
| 642 |
sudo mkdir /var/www/pgcluu/ |
| 643 |
sudo cp -rf cgi-bin/rsc /var/www/pgcluu/ |
| 644 |
|
| 645 |
Then edit /etc/pgcluu.conf, copy it from sources cgi-bin/pgcluu.conf if |
| 646 |
it doesn't exists. Change the RSC_BASE and INPUT_DIR configuration |
| 647 |
directive to match your installation. Here in our example: |
| 648 |
|
| 649 |
RSC_BASE /pgcluu/rsc/ |
| 650 |
INPUT_DIR /var/lib/pgcluu/data |
| 651 |
|
| 652 |
Now we can start the data collection. For the moment pgcluu.conf is only |
| 653 |
read by the CGI pgcluu.cgi but this might change in the future. |
| 654 |
|
| 655 |
To let pgCluu start collecting data, you can use the following command |
| 656 |
(you can change it to however you like). We will need postgres user for |
| 657 |
this. |
| 658 |
|
| 659 |
sudo su - postgres |
| 660 |
/usr/local/bin/pgcluu_collectd -D -i 60 --rotate-daily /var/lib/pgcluu/data |
| 661 |
|
| 662 |
This will rotate you data daily. This is also the default in the systemd |
| 663 |
service file. |
| 664 |
|
| 665 |
Plugging the CGI directly to the CSV statistics files will result in |
| 666 |
very slow generation reports. To improve speed caching must be used, you |
| 667 |
must execute periodically pgcluu in cache mode. Run it manually the |
| 668 |
first time |
| 669 |
|
| 670 |
/usr/local/bin/pgcluu --cache /var/lib/pgcluu/data |
| 671 |
|
| 672 |
then add a cron task to execute the command each five or ten minutes: |
| 673 |
|
| 674 |
*/5 * * * * /usr/local/bin/pgcluu --cache /var/lib/pgcluu/data |
| 675 |
|
| 676 |
If you are using systemd pgcluu.timer service then caching can be |
| 677 |
enabled using STATS_REPORT_CACHING directive. Enabling this mode |
| 678 |
generate cache files (*.bin) in the statistics directory and disable |
| 679 |
static HTML reports generation. |
| 680 |
|
| 681 |
To see your reports, go to the following URL: |
| 682 |
|
| 683 |
http://localhost/cgi-bin/pgcluu.cgi |
| 684 |
|
| 685 |
Or change localhost by your fqdn server name. |
| 686 |
|
| 687 |
Note that here pgcluu_collectd and pgcluu scripts are found in |
| 688 |
/usr/local/bin/ which is the default for an installation from sources |
| 689 |
but with an installation from binary package you might find them into |
| 690 |
/usr/bin/. |
| 691 |
|
| 692 |
The CGI mode allow you to select the period of time used to generate the |
| 693 |
statistics reports. Using default pgcluu_collectd 60 seconds interval, a |
| 694 |
daily graph will have 1440 points. Having too much timeseries to render |
| 695 |
is not a good point for performances so we are limiting to the first |
| 696 |
seven days of the selected period. This mean a maximum of 10080 points |
| 697 |
for one week, this seems a safe limit. Feel free to increase or reduce |
| 698 |
the limit following the server and client resources. This is controlled |
| 699 |
by |
| 700 |
|
| 701 |
MAX_RENDERED_DAYS 7 |
| 702 |
|
| 703 |
configuration directive in pgcluu.conf |
| 704 |
|
| 705 |
LICENSE |
| 706 |
Copyright (c) 2012-2024, Gilles Darold |
| 707 |
|
| 708 |
pgCluu is licenced under the PostgreSQL Licence a liberal Open Source |
| 709 |
license, similar to the BSD or MIT licenses. That mean that all parts of |
| 710 |
the program are open source and free of charge. |
| 711 |
|
| 712 |
Permission to use, copy, modify, and distribute this software and its |
| 713 |
documentation for any purpose, without fee, and without a written agreement |
| 714 |
is hereby granted, provided that the above copyright notice and this |
| 715 |
paragraph and the following two paragraphs appear in all copies. |
| 716 |
|
| 717 |
IN NO EVENT SHALL Dalibo BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, |
| 718 |
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, |
| 719 |
ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF |
| 720 |
Dalibo HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 721 |
|
| 722 |
Gilles Darold SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT |
| 723 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 724 |
PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, |
| 725 |
AND Gilles Darold HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, |
| 726 |
UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 727 |
|
| 728 |
This is the case for both, pgcluu_collectd and the grapher pgcluu |
| 729 |
programs. |
| 730 |
|
| 731 |
AUTHORS |
| 732 |
pgCluu is an original development of Gilles Darold. |
| 733 |
|
| 734 |
Some parts of the collector are taken from pgstats a C program writen by |
| 735 |
Guillaume Lelarge and especially the SQL queries including the |
| 736 |
compatibility with all PostgreSQL versions. See |
| 737 |
https://github.com/gleu/pgstats |
| 738 |
|
| 739 |
Btw pgCluu grapher is compatible with files generated by pgstats, sar |
| 740 |
and sadc so you can use it independantly to graph those data. Some part |
| 741 |
of the sar output parser are taken from SysUsage. See |
| 742 |
http://sysusage.darold.net/ |
| 743 |
|