Skip to content
no0p edited this page Oct 16, 2014 · 3 revisions

It's nice to think of pgsampler as a more generic tool for limited character data out of Postgresql on a periodic basis.

It may or may not be a good idea, but there is no reason different metrics, or even aggregated data, could not be exported.

Collecting a new metric

create the function in a file

The functions all exist in /lib/commands/

write the function.

Take a look at other commands for example. Generally there are two types of commands, functions that execute an SQL statement and functions that collect data from an internal function or the filesystem.

Functions which use SPI are designed to be trivial to implement. Consider <a href="https://github.com/no0p/pgsampler/blob/master/lib/commands/heartbeat.c>heartbeat.c which instantiates a string for an sql statement and passes it to the function exec_to_command. Then return the result.

Add a call to the function in control_loop.

Note that different groups of commands are run at different frequencies depending on the block they are in. Frequencies are keyed on the cycle variable and controlled by sampling rate GUCs.

Take a look at other calls to commands. Depending on the output mode, the result is passed directly to write_to_csv or appended to a commands string buffer. When it is in output mode, this commands string will be written to a socket.

Add the function prototype to pgsampler.h

Update the Makefile

Add a reference to the new command file similar to other commands.

Final Remarks

If you have any issues please get in touch. robert@relsys.io

Clone this wiki locally