Debian Codegraph @

doc/pgCluu.pod

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