Skip to content

Commit

Permalink
#17 pgstatsmon should support discovering backend IPs via nic_tag regex
Browse files Browse the repository at this point in the history
#18 pgstatsmon shouldn't try to create functions that depend on missing functions
Reviewed by: Kelly McLaughlin <[email protected]>
Approved by: Kelly McLaughlin <[email protected]>
  • Loading branch information
KodyKantor committed Aug 23, 2018
1 parent adf968a commit c3c085e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
8 changes: 7 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# pgstatsmon Changelog

## Not yet released.
## Not yet released
None

## 1.1.0
* #18 pgstatsmon shouldn't try to create functions that depend on missing functions
* #17 pgstatsmon should support discovering backend IPs via nic_tag regex
* #14 Collect metrics about vacuum progress
* #13 pgstatsmon could poll pg_statio_user_tables and pg_statio_user_indexes

## 1.0.0
Expand Down
21 changes: 10 additions & 11 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ static parameters are ignored.
If you have a Triton installation you can instruct pgstatsmon to poll VMAPI
for information about deployed (and running) Postgres instances. pgstatsmon
will poll VMAPI at a user-defined interval. VMAPI VM and NIC tags must be
provided to help pgstatsmon find the proper instances.
provided to help pgstatsmon find the proper instances. The NIC tag is in the
form of a regular expression.

Only one VMAPI can currently be targeted. This means that if you have a three
datacenter Triton deployment you will need to stand up three instances of
Expand Down Expand Up @@ -91,23 +92,21 @@ When pgstatsmon first encounters a new backend it attempts to do a few things.
- Connects to the database as the 'postgres' user
- Check if the database is a synchronous or asynchronous peer. If it is,
pgstatsmon doesn't perform the rest of these steps
- Collects the database server version number
- Creates a non-superuser (defined in the pgstatsmon configuration file) that
pgstatsmon will use on subsequent Postgres connection attempts
- Creates two functions to allow pgstatsmon to glean information about Postgres
that is usually hidden from non-superusers
* get_stat_activity()
* Returns an unfiltered version of pg_stat_activity. When queried by a
non-superuser pg_stat_activity will hide queries from superusers (like
autovacuum operations).
* get_stat_replication()
* Returns an unfiltered version of pg_stat_replication. When queried by a
non-superuser pg_stat_replication will display very little information.
This function allows pgstatsmon to track things like WAL positions.
- Creates functions to allow pgstatsmon to glean information about Postgres
that is usually hidden from non-superusers. Examples of these are
'get_stat_activity()' and 'get_stat_replication()'.

If this initial setup operation fails for some reason, pgstatsmon will continue
to attempt to run the setup on every metric collection 'tick' and skip metric
collection for the backend needing to be set up.

If one of the initial setup steps is known to be incompatible with certain
PG versions it is skipped, which may result in query errors during metric
collection.

## Metrics collected

pgstatsmon collects a lot of metrics from Postgres. The most up-to-date list of
Expand Down
41 changes: 40 additions & 1 deletion lib/dbinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ function stop_if_standby(args, callback) {
});
}

/*
* Get the version number of the Postgres server. This is used later to
* determine whether or not we should set up some of the stat collection
* functions (replication stats, vacuum progress stats).
*/
function get_db_version(args, callback) {
var query;
var res;
var server_version_num;

server_version_num = 'server_version_num';
query = mod_util.format('SHOW %s', server_version_num);

res = args.client.query(query);
res.once('row', function (row) {
args.pg_version = row[server_version_num];
});

res.on('error', function (err) {
callback(err);
});

res.on('end', function () {
callback();
});
}

/*
* create a restricted Postgres user for pgstatsmon
*/
Expand Down Expand Up @@ -166,6 +193,11 @@ function create_activity_function(args, callback) {
* create a function for pgstatsmon to view unfiltered pg_stat_replication stats
*/
function create_replication_function(args, callback) {
if (args.pg_version < 90400) {
/* not supported */
callback();
return;
}
var query;
query = 'CREATE OR REPLACE FUNCTION public.get_stat_replication()'
+ ' RETURNS SETOF pg_stat_replication AS \'SELECT * FROM'
Expand All @@ -179,6 +211,11 @@ function create_replication_function(args, callback) {
* create a function for pgstatsmon to gather vacuum progress
*/
function create_progress_vacuum_function(args, callback) {
if (args.pg_version < 90600) {
/* not supported */
callback();
return;
}
var query;
query = 'CREATE OR REPLACE FUNCTION public.get_stat_progress_vacuum('
+ 'out relname name, '
Expand Down Expand Up @@ -255,12 +292,14 @@ function setup_monitoring_user(args, callback) {
var log = args.log;
var arg = {
'conf': args,
'client': null
'client': null,
'pg_version': null
};
mod_vasync.pipeline({
'funcs': [
connect_to_database,
stop_if_standby,
get_db_version,
create_user,
create_activity_function,
create_replication_function,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"restify": "6.3.4",
"vasync": "2.2.0",
"verror": "1.10.0",
"vmapi-resolver": "1.0.0"
"vmapi-resolver": "2.0.0"
},
"author": "Joyent, Inc",
"license": "MPL-2.0"
Expand Down

0 comments on commit c3c085e

Please sign in to comment.