Top
Enterprise Postgres 17 Operation Guide

9.8.1 Metrics Collection

Metrics collection uses psql commands to retrieve metrics and the AWS CLI to forward metrics to Amazon CloudWatch.

  1. Preparation

    Refer to the AWS documentation, install the AWS CLI, and configure it to transfer metrics to Amazon CloudWatch. Use AWS CLI 2.x or later.

  2. Create a metrics collection script

    Sample scripts for collecting metrics are stored in the following location under the Fujitsu Enterprise Postgres installation directory. Create a script for collecting metrics by referring to the sample script. For the metrics collected by the sample script, refer to "9.8.3 Metrics Collected by the Sample Script".

    <Install directory>/share/putting-metrics-to-monitoring-tool.sh.sample

    Edit the following connection information defined in the sample script.

    • Amazon CloudWatch connection destination to store metrics

      Define the Amazon CloudWatch Namespace to collect metrics in “NAMESPACE”.

      NAMESPACE="YOUR Cloud Watch NAMESPACE"
    • Database connection destination for collecting metrics

      Edit the variables below to define the PostgreSQL information for retrieving metrics.

      PGHOST: Specify the host name to connect to.

      PGPORT: Specify the port to connect to.

      PGDATABASE: Specify the database name to connect to.

      PGUSER: Specify the PostgreSQL user to use for connection. To view all statistical information for all sessions, specify a superuser or a role with the built-in role pg_read_all_stats privileges.

  3. Setting environment variables

    To run the metrics collection script, you must set the path where the Fujitsu Enterprise Postgres server feature and AWS CLI are installed in the environment variable PATH.

    The following is an example of how to set environment variables when the AWS CLI is installed in /awscli/bin.
    If you want to set environment variables within a script, write them at the beginning of the script before the environment variable for the database connection destination.

    export PATH=/opt/fsepv<x>server64/bin:/awscli/bin:$PATH
  4. Define the database connection credentials

    If necessary, define the password and the storage location of the SSL communication certificate in an environment variable or configuration file.

  5. Periodically run metrics collection scripts

    Use crontab or similar to periodically run the metrics collection script as the OS user who can transfer metrics using the aws cloudwatch put-metric-data command.

    Below is an example of a crontab definition for collecting metrics every 10 minutes.

    $ cat /var/spool/cron/<Running User>
    */10 * * * * /<Script placement destination>/putting-metrics-to-monitoring-tool.sh

    Edit the script to run periodically using the "crontab -e" command.

    When running with crontab, you can use rsyslog to output the script's standard output to a log file and detect whether the script is running normally or abnormally.

    The metrics collection interval should be determined based on the purpose of collection. The following are examples of collection intervals.

    • Long intervals, such as once every 10 minutes or once an hour, are recommended when monitoring to check operational trends.

    • Short intervals, such as once a minute, are recommended when monitoring to quickly respond to increases in load, such as a sudden increase in the number of connections.

    If the collection interval is short, the load may increase because the number of queries to the database increases accordingly. Consider the business load when deciding on the execution interval and the queries to be executed for metric collection.