Define New Relic dashboards as code and reconcile them to an account
Project description
newrelic-as-code
Define New Relic dashboards as code and reconcile them to an account.
New Relic resources should be defined in version-controlled Python and reconciled to the account on deploy, never hand-edited in the UI. You describe dashboards as pydantic models and the library handles finding the resources it manages, creating/updating/deleting them to match your declared set, and refusing to clobber anything it didn't create.
Reconcile is safe by design:
- Managed by tag. The library only touches dashboards carrying its
managed-bytag. A same-named dashboard without the tag is refused, never overwritten — so hand-built dashboards are safe. - Orphan cleanup. A managed dashboard that's no longer in your declared set is deleted.
- Dry run. Pass
dry_run=Trueto print what would change without touching the account.
Installation
pip install newrelic-as-code
Usage
There's one widget class per visualization — LineWidget, BillboardWidget,
TableWidget, … — each exposing exactly the config that visualization supports.
You pick the widget, not a visualization string, so a config can never disagree
with its chart type.
from newrelic_as_code import (
BillboardThreshold,
BillboardWidget,
Dashboard,
EU_ENDPOINT,
Layout,
Legend,
LineWidget,
NewRelicUpdater,
NrqlQuery,
Page,
YAxisLeft,
)
dashboard = Dashboard(
name='My service',
pages=[
Page(
name='Overview',
widgets=[
LineWidget(
title='Throughput',
layout=Layout(column=1, row=1),
nrql_queries=[
NrqlQuery(
query='SELECT rate(count(*), 1 minute) '
'FROM Transaction TIMESERIES',
),
],
legend=Legend(enabled=True),
y_axis_left=YAxisLeft(zero=True),
),
BillboardWidget(
title='Error count',
layout=Layout(column=5, row=1),
nrql_queries=[
NrqlQuery(query='SELECT count(*) FROM TransactionError'),
],
thresholds=[
BillboardThreshold(alert_severity='critical', value=100),
],
),
],
),
],
)
updater = NewRelicUpdater(
account_id=1234567,
api_key='NRAK-...',
# Defaults to the US region; pass EU_ENDPOINT (or any full URL) for others.
endpoint=EU_ENDPOINT,
# The tag that marks dashboards this tool owns. Choose a value unique to your
# deployment so several deployments can coexist in one account.
managed_tag_value='my-service-deploy',
)
updater.sync([dashboard])
Notes
- One widget per visualization.
LineWidget,AreaWidget,BarWidget,StackedBarWidget,PieWidget,BillboardWidget,TableWidget,HeatmapWidget,HistogramWidget,JsonWidget,FunnelWidget,BulletWidget,MarkdownWidget. Each carries its own config fields directly (no separate config object to keep in sync with a visualization string). - Account id.
account_idis the account dashboards are created in, and is injected into anyNrqlQuerythat sets neitheraccount_idnoraccount_ids. Setaccount_id(single) oraccount_ids(multi-account) on a query to override. - Escape hatch. New Relic's per-widget
rawConfigurationis an untyped scalar, so the typed fields cover the keys we model — anything else goes throughraw={...}on any widget, which is merged over (and wins against) the typed output. For an entirely unmodeled visualization, the genericWidgettakes avisualizationstring and a fullraw_configurationdict. - Variables. Dashboard-level template variables (ENUM, NRQL, and STRING) are
supported via the
Variablemodel andDashboard(variables=[...]). - No builder. The library's surface is the plain model tree — you construct widgets directly. Layout/composition helpers (grid math, managed banners) belong in your own code, since they're specific to how you lay dashboards out.
- Extensible reconcile.
sync()reconciles dashboards today. The reconcile core (find-by-managed-tag → create/update/delete-orphaned → refuse-unmanaged → dry-run) is resource-agnostic, so alert policies/conditions can be added as additional resource types later without reshaping it.
License
MIT
Not affiliated with or endorsed by New Relic, Inc. "New Relic" is a trademark of New Relic, Inc.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file newrelic_as_code-0.2.0.tar.gz.
File metadata
- Download URL: newrelic_as_code-0.2.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5fda2d2cb176e15d712b6e0ff753e1ed824b5bcea3c526631bde16d7ccd580f
|
|
| MD5 |
2da08af7bf24297b0724ec8753d803ae
|
|
| BLAKE2b-256 |
95c2bee72d8770c8012d06b9fd55226e592c3b88a433aa04b53d24cb29bbf370
|
Provenance
The following attestation bundles were made for newrelic_as_code-0.2.0.tar.gz:
Publisher:
ci.yaml on ipeterov/newrelic-as-code
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
newrelic_as_code-0.2.0.tar.gz -
Subject digest:
b5fda2d2cb176e15d712b6e0ff753e1ed824b5bcea3c526631bde16d7ccd580f - Sigstore transparency entry: 2080966791
- Sigstore integration time:
-
Permalink:
ipeterov/newrelic-as-code@e79b5e5438e2d79b316b7f1f30fb76a5ac3b306f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ipeterov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yaml@e79b5e5438e2d79b316b7f1f30fb76a5ac3b306f -
Trigger Event:
push
-
Statement type:
File details
Details for the file newrelic_as_code-0.2.0-py3-none-any.whl.
File metadata
- Download URL: newrelic_as_code-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e038a6a582f6fc8d24f3458785915f7232386cd928ce766f6568b0d55212533f
|
|
| MD5 |
815c5978ffc5a97174b4163fdddd5dc7
|
|
| BLAKE2b-256 |
c662c6d2aa5902a1f92f48f353a9cb9925eeff176e22f546b831eb3787790556
|
Provenance
The following attestation bundles were made for newrelic_as_code-0.2.0-py3-none-any.whl:
Publisher:
ci.yaml on ipeterov/newrelic-as-code
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
newrelic_as_code-0.2.0-py3-none-any.whl -
Subject digest:
e038a6a582f6fc8d24f3458785915f7232386cd928ce766f6568b0d55212533f - Sigstore transparency entry: 2080966972
- Sigstore integration time:
-
Permalink:
ipeterov/newrelic-as-code@e79b5e5438e2d79b316b7f1f30fb76a5ac3b306f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ipeterov
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yaml@e79b5e5438e2d79b316b7f1f30fb76a5ac3b306f -
Trigger Event:
push
-
Statement type: