Menu
Grafana Cloud

IBM DB2 integration for Grafana Cloud

IBM DB2 is a relational database management system designed to store, manage, and retrieve data efficiently. This integration for Grafana Cloud allows users to collect metrics and logs for monitoring an IBM DB2 database.

Metrics include active connections, row operations, bufferpool hit ratio, tablespace usage, average lock wait time, deadlocks, and active locks.

This integration supports IBM DB2 9.7 and onwards.

This integration includes 3 useful alerts and 1 pre-built dashboard to help monitor and visualize IBM DB2 metrics and logs.

Before you begin

In order for the integration to properly work, you must set up the IBM DB2 Prometheus Exporter to export metrics from IBM DB2.

Activating IBM DB2 database

For DB2 to accurately report metric values, the database being monitored must be “explicitly activated”. Doing so will make it so that certain metric values are correctly incremented and not periodically reset. However, it does result in a performance impact on the environment DB2 is running in. The size of this impact will depend on the system, but will result in the most accurate data reported by DB2 and, subsequently, this exporter. To explicitly activate a database, connect to DB2 and run the command activate database <dbname> and disconnect. Now DB2 will correctly increment and store metrics.

db2
activate database sample
quit

To deactivate a database, connect to db2 and run the command deactivate database <dbname> and disconnect. Doing so will reset the metrics reported by DB2. The database must be reactivated in order for metrics to be properly incremented, stored, and reported by DB2. Note: Whether or not the database is activated only affects DB2’s ability to report metrics, it does not affect DB2’s behavior as a database.

Set up IBM DB2 Exporter

The exporter can be run by following this guide.

Note: The exporter uses a driver that is not compatible with ARM64 architectures. Therefore the exporter cannot be used on an ARM64 machine.

The exporter serves metrics for only one database, so to monitor multiple databases multiple exporters will need to be set up. By default, the exporter serves metrics at port 9953 but can be configured to use a different port. Use the flag --web.listen-address=;<port> when running the exporter to serve metrics at a different port. This can be done so that the Grafana Agent can report metrics for multiple databases by scraping from multiple exporters.

Once deployed, the Grafana Agent will be able to scrape the IBM DB2 Exporter.

Install IBM DB2 integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find IBM DB2 and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send IBM DB2 metrics and logs to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboard and alerts to your Grafana Cloud instance, and you can start monitoring your IBM DB2 setup.

Post-install configuration for the IBM DB2 integration

After enabling the metrics generation, instruct the Grafana Agent to scrape your IBM DB2 database.

Logs are found where the DB2 instance is located, inside the sqllib directory. For a single member environment, logs will be available at /path/to/inst/sqllib/db2dump/db2diag.log. For multi-member environments logs are located at /path/to/inst/sqllib/db2dump/DIAG*/db2diag.log. You can edit the __path__ label for logs to match your environment.

If multiple databases are being monitored by the Grafana Agent, and subsequently, multiple exporters are running, then be sure to add additional targets to the metrics scrape config.

If you want to show logs and metrics signals correlated in your dashboards as a single pane of glass, ensure the following:

  • instance label values for metrics and logs should be set to the hostname:port passed to the exporter which is used to connect to IBM DB2 and monitor the specified database.

Make sure to change targets in the snippet according to your environment.

yaml
{
  configs: [
    {
      config: |||
        job_name: integrations/ibm-db2
        metrics_path: /metrics
        static_configs: 
          - targets:
            - localhost:9953
            labels:
              instance: <your-db2-database-host>:<your-db2-database-port>
      |||,
      type: 'metric_scrape',
    },
    {
      config: |||
        job_name: integrations/ibm-db2
        static_configs:
          - targets: [localhost] 
            labels:
              instance: <your-db2-database-host>:<your-db2-database-port>
              __path__: /home/*/sqllib/db2dump/{DIAG*,db2diag.log}/db2diag.log
        pipeline_stages:
          - multiline:
            firstline: '\d+-\d+-\d+-\d+.\d+.\d+.\d+\+\d+\s[A-Z0-9]+\s+LEVEL:\s[a-zA-Z]+'
      |||,
      type: 'log_scrape',
    },
  ],
}

Configuration snippets for Grafana Agent

Below metrics.configs.scrape_configs, insert the following lines and change the URLs according to your environment:

yaml
    - job_name: integrations/ibm-db2
      metrics_path: /metrics
      static_configs: 
        - targets:
          - localhost:9953
          labels:
            instance: '<your-instance-name>'

Below logs.configs.scrape_configs, insert the following lines according to your environment.

yaml
    - job_name: integrations/ibm-db2
      static_configs:
        - targets: [localhost] 
          labels:
            instance: '<your-instance-name>'
            __path__: /home/*/sqllib/db2dump/{DIAG*,db2diag.log}/db2diag.log
            job: integrations/ibm-db2
      pipeline_stages:
        - multiline:
          firstline: '\d+-\d+-\d+-\d+.\d+.\d+.\d+\+\d+\s[A-Z0-9]+\s+LEVEL:\s[a-zA-Z]+'

Full example configuration for Grafana Agent

Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the IBM DB2 integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.

yaml
integrations:
  prometheus_remote_write:
  - basic_auth:
      password: <your_prom_pass>
      username: <your_prom_user>
    url: <your_prom_url>
  agent:
    enabled: true
    relabel_configs:
    - action: replace
      source_labels:
      - agent_hostname
      target_label: instance
    - action: replace
      target_label: job
      replacement: "integrations/agent-check"
    metric_relabel_configs:
    - action: keep
      regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
      source_labels:
      - __name__
  # Add here any snippet that belongs to the `integrations` section.
  # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
logs:
  configs:
  - clients:
    - basic_auth:
        password: <your_loki_pass>
        username: <your_loki_user>
      url: <your_loki_url>
    name: integrations
    positions:
      filename: /tmp/positions.yaml
    scrape_configs:
      # Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
    - job_name: integrations/ibm-db2
      static_configs:
        - targets: [localhost] 
          labels:
            instance: '<your-instance-name>'
            __path__: /home/*/sqllib/db2dump/{DIAG*,db2diag.log}/db2diag.log
            job: integrations/ibm-db2
      pipeline_stages:
        - multiline:
          firstline: '\d+-\d+-\d+-\d+.\d+.\d+.\d+\+\d+\s[A-Z0-9]+\s+LEVEL:\s[a-zA-Z]+'
metrics:
  configs:
  - name: integrations
    remote_write:
    - basic_auth:
        password: <your_prom_pass>
        username: <your_prom_user>
      url: <your_prom_url>
    scrape_configs:
      # Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
      # For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
    - job_name: integrations/ibm-db2
      metrics_path: /metrics
      static_configs: 
        - targets:
          - localhost:9953
          labels:
            instance: '<your-instance-name>'
  global:
    scrape_interval: 60s
  wal_directory: /tmp/grafana-agent-wal

Dashboards

The IBM DB2 integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • IBM DB2 overview

IBM DB2 overview (metrics)

IBM DB2 overview (metrics)

IBM DB2 overview (logs)

IBM DB2 overview (logs)

Alerts

The IBM DB2 integration includes the following useful alerts:

AlertDescription
IBMDB2HighLockWaitTimeWarning: The average amount of time waiting for locks to become free is abnormally large.
IBMDB2HighNumberOfDeadlocksCritical: There are deadlocks occurring in the database.
IBMDB2LogUsageReachingLimitWarning: The amount of log space available for the DB2 instance is running out of space, rotate logs or delete unnecessary storage usage.

Metrics

The most important metrics provided by the IBM DB2 integration, which are used on the pre-built dashboard and Prometheus alerts, are as follows:

  • ibm_db2_application_active
  • ibm_db2_bufferpool_hit_ratio
  • ibm_db2_deadlock_total
  • ibm_db2_lock_usage
  • ibm_db2_lock_wait_time
  • ibm_db2_log_operations_total
  • ibm_db2_log_usage
  • ibm_db2_row_total
  • ibm_db2_tablespace_usage
  • ibm_db2_up

Changelog

md
# 0.0.3 - September 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.0.2 - August 2023

* Add regex filter for logs datasource

# 0.0.1 - July 2023

* Initial release

Cost

By connecting your IBM DB2 instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.