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 Grafana Alloy can report metrics for multiple databases by scraping from multiple exporters.
Once deployed, Grafana Alloy will be able to scrape the IBM DB2 Exporter.
Install IBM DB2 integration for Grafana Cloud
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find IBM DB2 and click its tile to open the integration.
- 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.
- 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.
Configuration snippets for Grafana Alloy
Simple mode
These snippets are configured to scrape a single IBM DB2 instance running locally with default ports.
First, manually copy and append the following snippets into your alloy configuration file.
Metrics snippets
prometheus.scrape "metrics_integrations_integrations_ibm_db2" {
targets = [{
__address__ = "localhost:9953",
instance = constants.hostname,
}]
forward_to = [prometheus.remote_write.metrics_service.receiver]
job_name = "integrations/ibm-db2"
}
Logs snippets
linux
local.file_match "logs_integrations_integrations_ibm_db2" {
path_targets = [{
__address__ = "localhost",
__path__ = "/home/*/sqllib/db2dump/{DIAG*,db2diag.log}/db2diag.log",
instance = constants.hostname,
job = "integrations/ibm-db2",
}]
}
loki.process "logs_integrations_integrations_ibm_db2" {
forward_to = [loki.write.grafana_cloud_loki.receiver]
stage.multiline {
firstline = "\\d+-\\d+-\\d+-\\d+.\\d+.\\d+.\\d+\\+\\d+\\s[A-Z0-9]+\\s+LEVEL:\\s[a-zA-Z]+"
max_lines = 0
max_wait_time = "3s"
}
}
loki.source.file "logs_integrations_integrations_ibm_db2" {
targets = local.file_match.logs_integrations_integrations_ibm_db2.targets
forward_to = [loki.process.logs_integrations_integrations_ibm_db2.receiver]
}
Advanced mode
The following snippets provide examples to guide you through the configuration process.
To instruct Grafana Alloy to scrape your IBM DB2 instances, manually copy and append the snippets to your alloy configuration file, then follow subsequent instructions.
Advanced metrics snippets
prometheus.scrape "metrics_integrations_integrations_ibm_db2" {
targets = [{
__address__ = "localhost:9953",
instance = constants.hostname,
}]
forward_to = [prometheus.remote_write.metrics_service.receiver]
job_name = "integrations/ibm-db2"
}
To monitor your IBM DB2 instance, you must use a discovery.relabel component to discover your IBM DB2 Prometheus endpoint and apply appropriate labels, followed by a prometheus.scrape component to scrape it.
Configure the following properties within each discovery.relabel
component:
__address__
: The address to your IBM DB2 Prometheus metrics endpoint.instance
label:constants.hostname
sets theinstance
label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this IBM DB2 instance. Make sure this label value is the same for all telemetry data collected for this instance.
If you have multiple IBM DB2 servers to scrape, configure one discovery.relabel
for each and scrape them by including each under targets
within the prometheus.scrape
component.
Advanced logs snippets
linux
local.file_match "logs_integrations_integrations_ibm_db2" {
path_targets = [{
__address__ = "localhost",
__path__ = "/home/*/sqllib/db2dump/{DIAG*,db2diag.log}/db2diag.log",
instance = constants.hostname,
job = "integrations/ibm-db2",
}]
}
loki.process "logs_integrations_integrations_ibm_db2" {
forward_to = [loki.write.grafana_cloud_loki.receiver]
stage.multiline {
firstline = "\\d+-\\d+-\\d+-\\d+.\\d+.\\d+.\\d+\\+\\d+\\s[A-Z0-9]+\\s+LEVEL:\\s[a-zA-Z]+"
max_lines = 0
max_wait_time = "3s"
}
}
loki.source.file "logs_integrations_integrations_ibm_db2" {
targets = local.file_match.logs_integrations_integrations_ibm_db2.targets
forward_to = [loki.process.logs_integrations_integrations_ibm_db2.receiver]
}
To monitor your IBM DB2 instance logs, you will use a combination of the following components:
- local.file_match defines where to find the log file to be scraped. Change the following properties according to your environment:
__address__
: The IBM DB2 instance address__path__
: The path to the log file.instance
label:constants.hostname
sets theinstance
label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this IBM DB2 instance. Make sure this label value is the same for all telemetry data collected for this instance.
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.
- loki.process defines how to process logs before sending it to Loki.
- loki.source.file sends logs to Loki.
Grafana Agent static configuration (deprecated)
The following section shows configuration for running Grafana Agent in static mode which is deprecated. You should use Grafana Alloy for all new deployments.
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 Grafana Alloy can report metrics for multiple databases by scraping from multiple exporters.
Once deployed, Grafana Alloy will be able to scrape the IBM DB2 Exporter.
Install IBM DB2 integration for Grafana Cloud
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find IBM DB2 and click its tile to open the integration.
- 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.
- 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 thehostname: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.
Configuration snippets for Grafana Agent
Below metrics.configs.scrape_configs
, insert the following lines and change the URLs according to your environment:
- 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.
- 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.
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 (logs)
Alerts
The IBM DB2 integration includes the following useful alerts:
Alert | Description |
---|---|
IBMDB2HighLockWaitTime | Warning: The average amount of time waiting for locks to become free is abnormally large. |
IBMDB2HighNumberOfDeadlocks | Critical: There are deadlocks occurring in the database. |
IBMDB2LogUsageReachingLimit | Warning: 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
- up
Changelog
# 1.0.0 - December 2023
- Added Grafana Agent Operator configuration snippet to support IBM DB2 in kubernetes cluster
- Added cluster selector to dashboard for kubernetes support
- Added default cluster label to agent config
- Bump version to 1.0.0
# 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.