Example Dockerized New Relic Agent with PostgreSQL Metrics Integration for Aptible
This repository contains an example setup for monitoring PostgreSQL metrics using the New Relic agent in a Dockerized environment. It is tailored for Aptible deployments, with seamless integration to collect database performance metrics.
To configure the New Relic agent and database connections, set the following environment variables:
- Description: Your New Relic account's license key, required for reporting metrics to New Relic
- Example:
1234567890abcdef1234567890abcdef12345678
- Description: Polling interval in seconds, defaulted to
30s
. - Example:
15s
- Description: This is used to configure
event_queue_depth
which adjusts the size of the queue the Infrastructure agent uses to store events before sending them to New Relic. Default: 5000 - Example:
10000
-
Description: A comma-delimited list of PostgreSQL database URLs in the format:
postgresql://USER:PASSWORD@HOST:PORT/DB_NAME|DATABASE_HANDLE|NEW_RELIC_ENV_LABEL
Multiple database URLs can be provided, separated by commas.
-
Example:
postgresql://user1:[email protected]:5432/database1|database-instance-1|test,postgresql://user2:[email protected]:5432/database2|database-instance-2|staging
- Description: Your New Relic account's license key, required for reporting metrics to New Relic
- Example:
1234567890abcdef1234567890abcdef12345678
-
Clone this repository:
git clone https://github.com/yourusername/newrelic-metrics-example.git
-
Navigate to the repository directory:
cd newrelic-metrics-example
-
Build the Docker image:
docker build -t newrelic-metrics-example .
-
Run the container with the required environment variables:
docker run -e NEW_RELIC_LICENSE_KEY=1234567890abcdef1234567890abcdef12345678 \ -e PSQL_URLS="postgresql://user1:[email protected]:5432/database1|database-instance-1|test,postgresql://user2:[email protected]:5432/database2|database-instance-2|staging" \ newrelic-metrics-example
Follow these steps to deploy the New Relic metrics agent on Aptible:
-
Clone the repository:
git clone https://github.com/aptible/newrelic-metrics-example.git cd newrelic-metrics-example
-
Create a new Aptible app (
newrelic-metrics
is just a sample name used in this example):aptible apps:create newrelic-metrics
-
Add Aptible as a remote:
git remote add aptible [email protected]:app-name/newrelic-metrics.git
-
Configure the app environment, substituting your own values below:
aptible config:set --app newrelic-metrics \ NEW_RELIC_LICENSE_KEY=your-license-key \ PSQL_URLS=your-database-urls
-
Deploy to Aptible:
git push aptible main
- Ensure that the PostgreSQL databases are accessible from the container's network
- The New Relic license key and database urls must remain confidential; avoid sharing them in public repositories
This project is open-source and available under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request if you have suggestions or improvements.