• /
  • EnglishEspañol日本語한국어Português
  • Log inStart now

New Relic Metrics Adapter

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 program pursuant to our pre-release policies.

You can use metrics from your New Relic account to autoscale applications and services in your Kubernetes cluster by deploying the New Relic Metrics Adapter. This adapter fetches the metric values from New Relic and makes them available for the Horizontal Pod Autoscalers.

The newrelic-k8s-metrics-adapter implements the external.metrics.k8s.io API to support the use of external metrics based New Relic NRQL queries results. Once deployed, the value for each configured metric is fetched using the NerdGraph API based on the configured NRQL query.

The metrics adapter exposes the metrics over a secured endpoint with TLS.

Diagram showing the New Relic metrics adapter in a cluster

New Relic metrics adapter in a cluster.

Requirements

Installation

To install the New Relic Metrics Adapter, we provide the newrelic-k8s-metrics-adapter Helm chart, which is also included in the nri-bundle chart used to deploy all New Relic Kubernetes components.

  1. If not already installed, install our Kubernetes integration.

  2. Upgrade the installation to include the New Relic Metrics Adapter with the following command:

    bash
    $
    helm upgrade --install newrelic newrelic/nri-bundle \
    >
    --namespace newrelic --create-namespace --reuse-values \
    >
    --set metrics-adapter.enabled=true \
    >
    --set newrelic-k8s-metrics-adapter.personalAPIKey=YOUR_NEW_RELIC_PERSONAL_API_KEY \
    >
    --set newrelic-k8s-metrics-adapter.config.accountID=YOUR_NEW_RELIC_ACCOUNT_ID \
    >
    --set newrelic-k8s-metrics-adapter.config.externalMetrics.external_metric_name.query=NRQL query

Please notice and adjust the following flags:

  • metrics-adapter.enabled: Must be set to true so the metrics adapter chart is installed.
  • newrelic-k8s-metrics-adapter.personalAPIKey: Must be set to valid New Relic Personal API key.
  • newrelic-k8s-metrics-adapter.config.accountID: Must be set to valid New Relic account where metrics are going to be fetched from.
  • newrelic-k8s-metrics-adapter.config.externalMetrics.external_metric_name.query: Adds a new external metric where:
    • external_metric_name: The metric name.
    • query: The base NRQL query that is used to get the value for the metric.

Tip

Alternatively, you can use a values.yaml file that can be passed to the helm command with the --values flag. Values files can contain all parameters needed to configure the metrics explained in the configuration section.

Configuration

You can configure multiple metrics in the metrics adapter and change some parameters to modify the behaviour of the metrics cache and filtering. To see the full list and descriptions of all parameters that can be modified, refer to the chart README.md and values.yaml files.

How it works

The following example is a Helm values file that enable the metrics adapter on the nri-bundle chart installation, and configures the nginx_average_requests metric:

metrics-adapter:
enabled: true
newrelic-k8s-metrics-adapter:
personalAPIKey: <Personal API Key>
config:
accountID: <Account ID>
externalMetrics:
nginx_average_requests:
query: "FROM Metric SELECT average(nginx.server.net.requestsPerSecond) SINCE 2 MINUTES AGO"

Caution

The default time span for metrics is 1h. Therefore, you should define queries with the SINCE clause to adjust the time span according to your environment and needs.

There is an HPA consuming the external metric as follows:

kind: HorizontalPodAutoscaler
apiVersion: autoscaling/v2beta2
metadata:
name: nginx-scaler
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx
minReplicas: 1
maxReplicas: 10
metrics:
- type: External
external:
metric:
name: nginx_average_requests
selector:
matchLabels:
k8s.namespaceName: nginx
target:
type: Value
value: 10000

Based on the HPA definition, the controller manager fetches the metrics from the external metrics API which are served by the New Relic metrics adapter.

The New Relic metrics adapter receives the query including the nginx_average_requests metric name and all the selectors, and searches for a matching metric name in the internal memory based on the configured metrics. Then, it adds the selectors to the query to form a final query that is executed using NerdGraph to fetch the value from New Relic. The above example will generate a query like the following:

FROM Metric SELECT average(nginx.server.net.requestsPerSecond)
WHERE clusterName=CLUSTER_NAME AND `k8s.namespaceName`='nginx' SINCE 2 MINUTES AGO

Notice that a clusterName filter has been automatically added to the query to exclude metrics from other clusters in the same account. You can remove it by using the removeClusterFilter configuration parameter. Also the value is cached for a period of time defined by the cacheTTLSeconds configuration parameter, whose default is 30 seconds.

Troubleshooting

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.