JDBC

Overview Copied

The JDBC (Java Database Connectivity) Collection Agent plugin uses JDBC to gather data from a database by executing user-specified queries.

JDBC drivers Copied

The following JDBC drivers are packaged with the JDBC plugin:

A JDBC plugin configured to connect to the databases above will work out of the box.

For databases not listed above, add their corresponding JDBC driver jar file to the classpath when running the collection agent.

java -cp /opt/sybase/jConnect-16_0/classes/jconn4.jar:<Netprobe directory>/collection_agent/collection-agent-3.2.2-exec.jar "-Dlogback.configurationFile=<Netprobe directory>/collection_agent/logback.xml" com.itrsgroup.collection.ca.Main "collection-agent-jdbc-sybase.yml"

Plugin configuration reference Copied

collectors:
  - name: jdbc
    type: plugin
    className: JdbcCollector

    # Interval (in millis) between query execution (optional, defaults to 1 minute)
    collectionInterval: 60000

    # Number of worker threads (i.e. concurrent query executors).
    # Default value shown.
    workerThreads: 1

    # Connection details
    connection:
      # Mandatory. The JDBC Url which identifies the database to connect to
      url: jdbc:mysql://localhost:5005/geneos_db
      
      # Username used to connect to the database
      user: <database user>
      
      # Password of the said username
      password: <database password>

      # Properties file which contains connection properties. For debugging purposes/advanced users only.
      propertiesFile: <filename of properties file>

    # Array of query configurations. Multiple queries can be specified.
    queryConfigs:
        # Mandatory. Query to run
      - query: "show processlist"

        # Mandatory. Unique identifier of this query. This will be used in logs and signal events.
        name: "Process List"
        
        # Mandatory. Dimensions added to each datapoint. At least one dimension is required from either dbColumns or static key-value pairs.
        # Dimensions common to all queries defined can be configured under the commonQueryConfig section.
        dimensions:

          # List of DB columns to use as datapoint dimensions.
          dbColumns:
            - Id
            - User
            - Host
            - db

          # Map of static key-value pairs that will be added as a dimension to each datapoint.
          static:
            queryAlias: "Process List"

        # List of DB columns that will be added as datapoints
        dataPoints:
            # Column Name
          - column: Command
            # DataPoint type. Possible values: StatusMetric, Gauge, Counter, EntityAttribute
            type: EntityAttribute

          - column: Time
            type: Gauge
            # unit parameter is only applicable to gauge.
            # Possible values are as described in Unit class.
            unit: seconds

          - column: State
            type: StatusMetric

          - column: Info
            type: EntityAttribute

        # Columns that are not specified in the dimensions or datapoints config will be treated as a datapoint.
        # If the SQL data is of numeric SQL type, it will be treated as a Gauge by default.
        # If it is a Date, Time, or Timestamp type, it will be treated as an EntityAttribute.
        # Otherwise, it will be treated as a StatusMetric.

    # Common query configuration that will be applied to all queries defined in queryConfigs.
    # These configurations can also be placed inside a specific query configuration.
    # The query-specific configuration overrides the common config below 2 configs are the same.
    commonQueryConfig:
        # Query timeout in seconds. Default is no timeout.
        timeout: 5
        
        # The timezone offset used to process TIMESTAMP (without time zone) data. Default is "+00:00" or UTC.
        timestampZoneOffset: "+08:00"
        
        dimensions:
            dbColumns:
              - ID
            static:
                urlAlias: "LocalHost:5005 geneos_db"
        dataPoints:
            - column: comment
              type: EntityAttribute
            

Translation of database result set to datapoints Copied

You must specify how to translate the data returned by the query into datapoints in each query-configuration section.

For example, the query in the example configuration above returns the result set below:

mysql> show processlist;
+----+-------------+-----------------+-----------+---------+------+----------+------------------+
| Id | User        | Host            | db        | Command | Time | State    | Info             |
+----+-------------+-----------------+-----------+---------+------+----------+------------------+
|  7 | geneos_user | localhost:51558 | geneos_db | Query   |    0 | starting | show processlist |
|  8 | geneos_user | localhost:54952 | geneos_db | Sleep   |    3 |          | NULL             |
+----+-------------+-----------------+-----------+---------+------+----------+------------------+
2 rows in set (0.00 sec)

The configuration above specifies the following:

With the configuration above, the first datapoint in the first row will be the Command column, which you must define as an EntityAttribute datapoint type. The datapoint will then contain the following:

Handling of invalid data Copied

Dimension values should never be null or empty. If the value of any of the dimensions is null or empty, the datapoints in that row will be ignored. If the value of a datapoint column is null or empty, that datapoint will be ignored.

Timestamp processing Copied

SQL has two timestamp types:

By default, timestamp data types are published as EntityAttribute. However, it is also possible to specify it as a gauge or counter. In such cases, the unit will automatically be set to EPOCH_MILLISECONDS.

Properties file Copied

The connection: propertiesFile: configuration can be used to specify a file containing database-specific configurations. To specify database-specific properties, define one property per line in the file with the following format:

 `dataSource.<property name>=<property value>`

For example, to add TLS support for MySQL, the following MySQL-specific properties should be added to the connection: propertiesFile: configuration:

dataSource.sslMode=VERIFY_IDENTITY
dataSource.trustCertificateKeyStoreUrl=file:///home/mysql/certs/catruststore
dataSource.trustCertificateKeyStorePassword=mypassword
dataSource.clientCertificateKeyStoreUrl=file:///home/mysql/certs/keystore
dataSource.clientCertificateKeyStoreType=PKCS12
dataSource.clientCertificateKeyStorePassword=mypassword 

Other database-specific JDBC drivers may also have their own set of properties.

Example configuration Copied

The following collector configuration runs the show processlist query, which returns a list of all the current processes running on the server.

connection:
  url: jdbc:mariadb://ab1-23-45-678-910.ap-southeast-2.compute.amazonaws.com:1111/geneos_db
  user: admin
  password: password

queryConfigs:
  - query: "show processlist"
    name: "Process List"

    dimensions:
      dbColumns:
        - Id
      static:
        table: "processes"
        database: "Geneos DB"

    dataPoints:
          - column: User
            type: EntityAttribute
          - column: Host
            type: EntityAttribute
          - column: db
            type: EntityAttribute
          - column: Command
            type: EntityAttribute
          - column: Time
            type: Gauge
            unit: seconds
          - column: State
            type: StatusMetric
          - column: Info
            type: EntityAttribute

This query returns a result set like the following:

mysql> show processlist;
+---------+------+------------------------+------------+----------+-------+-----------+------------------+
| Id      | User | Host                   | db         | Command  | Time  | State     | Info             |
+---------+------+------------------------+------------+----------+-------+-----------+------------------+
| 811536  | root | 119.92.192.242:51110   | geneos_db  | Query    | 0     | starting  | show processlist |
+---------+------+------------------------+------------+----------+-------+-----------+------------------+
1 row in set (0.00 sec)

The Id column is defined as a dimension in the example configuration above because it is the unique identifier for each process in the result set. The configuration also defines static dimensions for the table="processes" and database="Geneos DB", which will be added as dimensions to the datapoints. The rest of the data are then treated as datapoints.

As an example, let’s consider the User column. An EntityAttribute type of a datapoint will be created for this column based on the configuration. This data point will have the following fields:

In order to create a Dynamic Entity dataview for this configuration, it is necessary to set up a Dynamic Entity mapping as follows:

image

JDBC Dynamic Entity dataview: image

You can also check for errors in the collector by viewing the Netprobe Info > Dynamic Entities Health > Signals self-monitoring dataview. For more information, see Signals in Dynamic Entities Health. image

["Geneos"] ["Geneos > Netprobe"] ["User Guide"]

Was this topic helpful?