Top
Enterprise Postgres 17 Operation Guide

8.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 "8.8.3 Metrics Collected by the Sample Script".

    <Install directory>\share\putting-metrics-to-monitoring-tool.ps1.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 PATH environment variable can be added to the environment variables of the user running the metrics collection script, or added within the script.

    The following is an example configuration when the AWS CLI is installed in C:\Program Files\Amazon\AWSCLIV2.

    set PATH = "C:\Program Files\Fujitsu\fsepv<x>server64\bin;C:\Program Files\Amazon\AWSCLIV2;%PATH%"

    When setting environment variables within a script, make sure to write them at the beginning of the script, before the environment variable for the database connection destination.

    $env:PATH = "C:\Program Files\Fujitsu\fsepv<x>server64\bin;C:\Program Files\Amazon\AWSCLIV2;" + $env: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 a task scheduler 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 task scheduler definition for collecting metrics every 10 minutes.

    # Task Scheduler screen
    Right-click on "Task Scheduler Library"
    -> Select Create basic task
    
    # Definition when creating a task
    1. Create a basic task
     Enter "Name" and "Description" and click "Next"
    2. Trigger
     Select "Daily" and click "Next"
    3. Daily
     Start: Any date
     Interval: 1 day
     Select and click "Next"
    4. Operation
     Select "Start a program" and click "Next"
    5. Start a program
     Enter the following and click "Next"
     Program/script: C:\Windows\System32\cmd.exe
     Add arguments: /c ""C:\Program Files\PowerShell\7\pwsh.exe" -ExecutionPolicy Bypass -File "( Script placement location)\putting-metrics-to-monitoring-tool.ps1" >> "( Log storage location)\put-metrics.log" 2>&1"
    6. Completed
     Check "Open the Properties dialog for this task when I click Finish" and click "Finish"
    
    # Properties screen
    1. General tab
     Check "Run whether user is logged on or not"
     Define the user who will run the task with "Change User or Group"
    2. Trigger tab
     Repeat every: Check the box and select 10 minutes from the dropdown
    

    In this example, the script's standard output is output to the log file "put-metrics.log", allowing you to detect whether the script is running normally or abnormally. Note that in this example, the log file continues to be output, so we recommend using a task scheduler or similar to periodically rotate and delete the logs.

    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.