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 / nrmysqlreceiver / nrpostgresqlreceiver metrics. Custom metrics collected via sqlqueryreceiver appear under the same Oracle, SQL Server, MySQL, or PostgreSQL entity in New Relic as the built-in receiver data, provided the entity-linking attributes are 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 `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: "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 displayed 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 resource/add_event_name and resource/add_host processors to set server.address and server.port to the same values used by the database receiver. Without this, custom metrics will not be linked to the database entity.
Add the processors in the processors: section:
processors: batch: resource/add_event_name: attributes: - key: server.address value: "<YOUR_DB_HOST>" action: upsert resource/add_host: attributes: - key: server.port value: "<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: [batch] exporters: [otlp/newrelic] logs/oracledb: receivers: [nroracledb] processors: [batch] exporters: [otlp/newrelic]
metrics/custom: receivers: [sqlquery/oracle] processors: [resource/add_event_name, resource/add_host, batch] exporters: [otlp/newrelic]重要
Add both resource/add_event_name and 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 | server.address/server.port not set or mismatched | Add resource/add_event_name and resource/add_host processors with the correct values |
| Metrics not under database entity | Metric name missing required prefix | Ensure metric names start with oracledb. |
If none of the above resolves the issue, check the collector's own logs for errors:
$sudo journalctl -u nrdot-collector -fAdd 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 default 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 displayed 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 server.address and server.port to the same values 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: server.address value: "<YOUR_DB_HOST>" action: upsert - key: server.port value: "<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/custom: receivers: [sqlquery] processors: [resource/add_host, batch] exporters: [otlp]重要
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 agoAdd the sqlqueryreceiver block inside the receivers: section of your existing mysql-config.yaml, alongside the existing nrmysql block:
receivers: nrmysql: ...
sql_query/mysql: driver: mysql
# Approach 1: Use the `host`, `port`, `database`, `username`, and `password` fields to connect to your database. The receiver will construct the datasource string 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: "<YOUR_DB_USERNAME>:<YOUR_DB_PASSWORD>@tcp(<YOUR_DB_HOST>:<YOUR_DB_PORT>)/<YOUR_DATABASE_NAME>"
collection_interval: 60s queries: - sql: "<YOUR_CUSTOM_SQL>" metrics: - metric_name: mysql.<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 MySQL host name or IP address. For example, |
| Your MySQL port number. The default value is |
| The database to connect to. For example |
| Your MySQL monitoring username. For example |
| Your MySQL monitoring password. |
| 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 displayed in New Relic. Must be prefixed with |
| 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 |
重要
MySQL's datasource connection string uses the format <user>:<password>@tcp(<host>:<port>)/<dbname>. Don't reuse another database's connection-string format here.
Naming convention
Metric names must start with mysql. 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.
Pipeline configuration
Add a metrics/custom pipeline in the service.pipelines: section of the config, alongside the existing pipeline:
service: pipelines: metrics/mysql: receivers: [nrmysql] processors: [batch] exporters: [otlp/newrelic] metrics/custom: receivers: [sql_query/mysql] processors: [batch] exporters: [otlp/newrelic]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 'mysql.%'SINCE 1 hour agoTroubleshooting
| Issue | Cause | Fix |
|---|---|---|
| Error 1045: Access denied for user | Wrong username/password | Double-check credentials; use the individual-fields approach rather than hand-building the datasource string |
| Error 1146: Table doesn't exist / SQL syntax error | Custom SQL references a table/column that doesn't exist on this MySQL/MariaDB version, or uses unsupported syntax | Test the query directly against the instance first with the same user before adding it to the receiver config |
| Metrics not under database entity | Metric name missing mysql. prefix | Ensure metric names start with mysql. |
| TLS/SSL negotiation error connecting to a TLS-enforcing server | Driver defaults to no TLS unless configured | Set the tls parameter under additional_params to match the server's TLS requirements |
If none of the above resolves the issue, check the collector's own logs for errors:
$sudo journalctl -u nrdot-collector -fAdd the sqlqueryreceiver block inside the receivers: section of your existing postgres-config.yaml, alongside the existing nrpostgresql block:
receivers: nrpostgresql: ...
sql_query/postgres: driver: postgres
# 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> additional_params: sslmode: disable
# Approach 2: Use the `datasource` field to provide a full connection string. # datasource: "host=<YOUR_DB_HOST> port=<YOUR_DB_PORT> user=<YOUR_DB_USERNAME> password=<YOUR_DB_PASSWORD> dbname=<YOUR_DATABASE_NAME> sslmode=disable"
collection_interval: 60s queries: - sql: "<YOUR_CUSTOM_SQL>" metrics: - metric_name: postgresql.<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 hostname or IP address. For example, |
| Your port number. The default value is |
| Your database name to use as the initial connection context. For example |
| Your PostgreSQL database username. For example |
| Your PostgreSQL database password. |
| 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 displayed in New Relic. Must be prefixed with |
| 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 |
重要
If your PostgreSQL server requires TLS, set sslmode accordingly under additional_params (Approach 1) or in the datasource string (Approach 2) — for example sslmode: require. When omitted, the underlying driver defaults to negotiating SSL for non-local connections, which fails against a server that isn't configured for it.
Naming convention
Metric names must start with postgresql. 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
nrpostgresql synthesizes its database entity from server.address and server.port. Add a resource/add_host processor to stamp the same server.address/server.port values 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_host: attributes: - key: server.address value: "<YOUR_DB_HOST>" action: upsert - key: server.port value: "<YOUR_DB_PORT>" action: upsert重要
If your nrpostgresql pipeline already has a resource/* processor setting server.address/server.port (for example resource/postgresql), reuse that same processor in the metrics/custom pipeline below instead of duplicating it — both receivers must stamp identical values to attach to the same entity.
Pipeline configuration
Add a metrics/custom pipeline in the service.pipelines: section of the config, alongside the existing pipelines:
service: pipelines: metrics/postgresql: receivers: [nrpostgresql] processors: [resource/add_host, batch] exporters: [otlp/newrelic] logs/postgresql: receivers: [nrpostgresql] processors: [resource/add_host, batch] exporters: [otlp/newrelic] metrics/custom: receivers: [sql_query/postgres] processors: [resource/add_host, 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 'postgresql.%'SINCE 1 hour agoTroubleshooting
| Issue | Cause | Fix |
|---|---|---|
pq: SSL is not enabled on the server | sslmode not set, driver defaulted to negotiating SSL | Set sslmode: disable (or the mode your server supports) under additional_params, or in the datasource string |
pq: password authentication failed for user | Wrong username/password, or special characters not escaped in a raw datasource string | Use Approach 1 (individual fields) — the receiver URL-escapes username/password automatically — or manually escape special characters in datasource |
| Metrics not under database entity | Metric name missing required postgresql. prefix, or server.address/server.port not set or mismatched | Ensure metric names start with postgresql., and add resource/add_host (or reuse the existing nrpostgresql resource processor) with the correct host/port values |
If none of the above resolves the issue, check the collector's own logs for errors:
$sudo journalctl -u nrdot-collector -f