Preview
We're still working on this feature, but we'd love for you to try it out!
This feature is currently provided as part of a preview pursuant to our pre-release policies.
The sqlqueryreceiver is an OpenTelemetry Collector receiver that lets you run any custom SQL query against your database and ingest the results as metrics into New Relic.
Use this when you want to monitor data not covered by the built-in nroracledbreceiver / nrsqlserverreceiver metrics. Custom metrics collected via sqlqueryreceiver appear under the same Oracle or SQL Server entity in New Relic as the built-in receiver data, provided host.name is configured correctly.
Prerequisites
- The database user configured in the datasource must have
SELECTprivilege on any view or table you intend to query. - The collector binary must include the
sqlqueryreceivercomponent.
Configuration
Add the sqlqueryreceiver block inside the receivers: section of your existing oracle-config.yaml, alongside the existing nroracledb block:
receivers: nroracledb:
...
sqlquery/oracle: driver: oracle
# Approach 1: Use the `endpoint`, `username`, `password`, and `service` fields to connect to your database. The receiver will construct the datasource URL for you. # host: <YOUR_DB_HOST> # port: <YOUR_DB_PORT> # database: <YOUR_DATABASE_NAME> # username: <YOUR_DB_USERNAME> # password: <YOUR_DB_PASSWORD>
# Approach 2: Use the `datasource` field to provide a full connection string. datasource: "oracle://<YOUR_DB_USERNAME>:<YOUR_DB_PASSWORD>@<YOUR_DB_HOST>:<YOUR_DB_PORT>/<YOUR_SERVICE_NAME>"
collection_interval: 60s queries: - sql: "<YOUR_CUSTOM_SQL>" metrics: - metric_name: oracledb.<YOUR_METRIC_NAME> value_column: <RESULT_COLUMN> attribute_columns: [<DIMENSION_COLUMN_1>, <DIMENSION_COLUMN_2>] value_type: doubleSet the following parameters for each metric:
Parameter | Description |
|---|---|
| Your hostname or IP address. For example, |
| Your port number. The default value is set to |
| Your Oracle database username. For example |
| Your Oracle database password. |
| Your Oracle service name. For example |
| How often to run the queries and collect metrics. For example, |
| The SQL query to run. 重要Ensure that your custom queries don't collect or expose PII or sensitive data. |
| Your metric name display in New Relic. Use |
| The column from the query result whose value becomes the metric value. For example |
| Data type of the value column. Options: |
| OTLP metric type. Use |
| Unit of measurement for the metric value. Used as metadata in New Relic. For example |
| Columns from the query result that become metric labels/dimensions. Used to filter and facet in NRQL. For example |
重要
For Oracle CDB users (C## prefix), encode # as %23 in the datasource URL. For example: c##newrelic must be c%23%23newrelic
Naming convention
Metric names must start with oracledb. to be associated with the correct entity in New Relic. Metrics with a different prefix will be ingested but will not appear under the database entity.
Entity synthesis
Add a resource/add_host processor to set host.name to the same value used by the database receiver. Without this, custom metrics will not be linked to the database entity.
Add the processor in the processors: section:
processors: batch: resource/add_event_name: attributes: - key: host.address value: "<YOUR_DB_HOST>" action: upsert resource/add_host: attributes: - key: host.name value: "<YOUR_DB_HOST>:<YOUR_DB_PORT>" action: upsertPipeline configuration
Add a metrics/custom pipeline in the service.pipelines: section of the config, alongside the existing pipelines:
service: pipelines: metrics/oracledb: receivers: [nroracledb] processors: [resource/add_event_name, batch] exporters: [otlp/newrelic] logs/oracledb: receivers: [nroracledb] processors: [resource/add_event_name, batch] exporters: [otlp/newrelic]
metrics/custom: receivers: [sqlquery/oracle] processors: [resource/add_host, resource/add_event_name, batch] exporters: [otlp/newrelic]重要
Add resource/add_host before batch in the processor list.
NRQL to validate data
After restarting the collector, run the following to confirm custom metrics are arriving:
SELECT uniques(metricName) FROM MetricWHERE otel.library.name LIKE '%sqlqueryreceiver%'AND metricName LIKE 'oracledb.%'SINCE 1 hour agoTroubleshooting
| Issue | Cause | Fix |
|---|---|---|
ORA-00942: table or view does not exist | Database user missing SELECT privilege | Grant SELECT ON <VIEW_NAME> to the user |
missing port in address | # in username/password not URL-encoded | Replace # with %23 in the datasource URL |
| No data in New Relic | host.name not set or mismatched | Add resource/add_host processor with the correct host value |
| Metrics not under database entity | Metric name missing required prefix | Ensure metric names start with oracledb. for Oracle database or sqlserver. for SQL Server. |
Add the sqlqueryreceiver block inside the receivers: section of your SQL Server collector configuration, alongside the existing nrsqlserver block:
receivers: nrsqlserver: ...
sqlquery: driver: sqlserver
#Approach 1: Use the `host`, `port`, `database`, `username`, and `password` fields to connect to your database. The receiver will construct the datasource URL for you. # host: <YOUR_DB_HOST> # port: <YOUR_DB_PORT> # database: <YOUR_DATABASE_NAME> # username: <YOUR_DB_USERNAME> # password: <YOUR_DB_PASSWORD>
# Approach 2: Use the `datasource` field to provide a full connection string. datasource: "sqlserver://<YOUR_DB_USERNAME>:<YOUR_DB_PASSWORD>@<YOUR_DB_HOST>:<YOUR_DB_PORT>?database=<YOUR_DATABASE_NAME>" collection_interval: 30s queries: - sql: "<YOUR_CUSTOM_SQL>" metrics: - metric_name: sqlserver.<YOUR_METRIC_NAME> value_column: <VALUE_COLUMN> value_type: <VALUE_TYPE> data_type: <DATA_TYPE> unit: <UNIT> attribute_columns: ["<ATTRIBUTE_COLUMNS>"]
- sql: "<YOUR_CUSTOM_SQL>" metrics: - metric_name: sqlserver.<YOUR_METRIC_NAME> value_column: <VALUE_COLUMN> value_type: <VALUE_TYPE> data_type: <DATA_TYPE> unit: <UNIT> attribute_columns: ["<ATTRIBUTE_COLUMNS>"]Set the following parameters for each metric:
Parameter | Description |
|---|---|
| Your server hostname or IP address. For example, |
| Your server port number. The defaults value is set to |
| Your SQL Server username. Omit for Windows Domain/GMSA authentication. For example |
| Your SQL Server password. Omit for Windows Domain/GMSA authentication. For example |
| Your database name to use as the initial connection context. For example |
| How often to run the queries and collect metrics. For example, |
| The SQL query to run. For example, 重要Ensure that your custom queries don't collect or expose PII or sensitive data. |
| Your metric name display in New Relic. Use |
| The column from the query result whose value becomes the metric value. For example |
| Data type of the value column. Options: |
| OTLP metric type. Use |
| Unit of measurement for the metric value. Used as metadata in New Relic. For example |
| Columns from the query result that become metric labels/dimensions. Used to filter and facet in NRQL. For example |
Naming convention
Metric names must start with sqlserver. to be associated with the correct entity in New Relic. Metrics with a different prefix will be ingested but will not appear under the database entity.
Entity synthesis
Add a resource/add_host processor to set host.name to the same value used by the database receiver. Without this, custom metrics will not be linked to the database entity.
Add the processor in the processors: section:
processors: resource/add_host: attributes: - key: service.instance.id value: "<YOUR_DB_HOST>:<YOUR_DB_PORT>" action: upsertPipeline configuration
Add a metrics/custom pipeline in the service.pipelines: section of the config, alongside the existing pipelines:
service: pipelines: metrics/sqlquery: receivers: [sqlquery] processors: [resource/add_host, batch] exporters: [otlphttp]重要
Add resource/add_host before batch in the processor list.
NRQL to validate data
After restarting the collector, run the following to confirm custom metrics are arriving:
SELECT uniques(metricName) FROM MetricWHERE otel.library.name LIKE '%sqlqueryreceiver%'AND metricName LIKE 'sqlserver.%'SINCE 1 hour ago