Prometheus configuration as code

Keep prometheus.yml, alert rules and Alertmanager configuration in Git, validated by promtool in CI and applied with controlled reloads. DeployOpen plans and builds the workflow in your infrastructure.

On this page

Why teams manage Prometheus configuration as code

Configuration as code matters once a team runs several Prometheus servers and the prometheus.yml file on each host has drifted apart. In that state, an alert threshold may have been loosened on one server during an incident and never reviewed, a scrape job may exist in staging but not production, and nobody can say who changed what or when. Configuration as code means keeping prometheus.yml, rule files and the Alertmanager configuration in a Git repository, validating every change before it ships, and applying it through a repeatable process. The scope covers three artifacts: the scrape and service discovery settings in prometheus.yml, the recording and alerting rule files it references, and the routing and receiver settings in Alertmanager's configuration. Each has its own validation step, and all three should move together so a new service never ships with scrapes but no alerts.

Prometheus is licensed under Apache-2.0, so the workflow carries no license fee. The costs are the people who write and review the changes, the CI runners that run validation, and the infrastructure for a repository and deployment pipeline. Those costs recur, while the initial design of the repository layout, templating and review rules is largely one-time work. Teams usually need this setup when more than one person edits monitoring, when several environments must differ only in targets and thresholds, or when an audit asks who approved a change to an alert. A single server maintained by one engineer may not justify the overhead yet. Before committing, confirm who will own the repository, who may approve alert changes, and how often configuration must reach production.

Applying changes without restarting the server depends on Prometheus's reload options. The lifecycle endpoint and SIGHUP both make the server reread its configuration, but the lifecycle endpoint is only available when the server is started with --web.enable-lifecycle, and that flag also exposes shutdown. Teams should decide which reload method their deployment pipeline will use, check whether the flag is acceptable under their access policy, and test a reload with a deliberately broken file to confirm the server keeps its last good configuration. The Prometheus overview describes the core model that these files feed, which helps reviewers understand what a change will affect.

How a configuration change moves from Git to a running Prometheus

A change starts as a commit on a branch and passes through a pull request review before anything is tested. CI runs promtool check config and promtool check rules against the proposed files, and only a merged change is deployed to each Prometheus and Alertmanager host. The reload uses either the lifecycle endpoint or SIGHUP, and a verification step confirms that targets are up and rules loaded. The trust boundary sits between the Git platform and the production network, so the deploy path should be a narrow, authenticated pull or push, not open inbound access.

Configuration flow from Git review through promtool checks to reload and verification.

Which configuration layout and reload method fits your estate

This table compares the common ways to lay out Prometheus configuration in Git and the two main ways to apply changes to a running server. Read each row against the number of environments you run and how much your team wants to change at runtime. The main takeaway is that the layout choice and the reload choice are independent, and the reload method sets a security requirement that the layout does not.

OptionWhat it looks likeFits whenWhat it requires
One repository per environmentSeparate Git repos for dev, staging and production, each holding a full prometheus.yml and rules directoryEnvironments have different owners, approval paths or access rights and must stay isolatedDuplicate changes across repos, so a review step or script to keep shared rules aligned
One repository with overlaysA shared base configuration plus per-environment override files applied at deploy timeMost scrape jobs and alert rules are common and only labels, targets or thresholds differA documented merge order and a CI check that renders every environment before merge
Per-environment files kept as-isEach environment has its own complete prometheus.yml and rules checked into Git with no generation stepFew environments and few changes, where a reviewer can read the full file for each environmentDiscipline to edit every copy together, since drift is usually found only during an incident
Templates rendered before deploymentSource templates with variables are rendered in CI into final files, which are then validated and shippedMany environments or targets generated from inventory, and the rendered output is reviewed or archivedA templating tool in the pipeline, plus storing the rendered artifact so reviewers see what actually ships
Reload through the lifecycle endpointAn HTTP POST to the reload endpoint applies the new configuration to the running serverDeployment tooling runs on the same network path to Prometheus and you want a standard API callStarting Prometheus with --web.enable-lifecycle, which also exposes shutdown, so the endpoint must sit behind network limits or authentication
Reload with SIGHUPSending the hangup signal to the Prometheus process makes it reread its configurationDeployment runs on the host or in a container where the orchestrator can signal the process, and you do not want an HTTP control surfaceShell or orchestrator access to the process and a check that the reload succeeded, since the signal gives no response body
Validation before any reloadpromtool checks configuration and rule files in CI before the file reaches the serverEvery layout and reload method, because a bad file can stop a reload from taking effectpromtool available in the pipeline image and a failing job that blocks merge or deploy

How to set up the Git workflow and CI validation

This sequence moves Prometheus configuration from hand-edited files on a server into a Git repository where every change is validated, reviewed and deployed the same way. The result is a pipeline that rejects broken rules before they reach production and confirms the running server loaded what was merged.

  1. Define the repository layout

    Decide how the repository separates the main Prometheus configuration, rule files, Alertmanager configuration, and per-environment values. A common approach is one directory for shared content and one overlay per environment, with file names that match the paths used in prometheus.yml. The platform team usually owns this layout, and the people who will review changes should agree to it before any file is moved. Done means every file that the server reads has a single home in Git, and nothing is edited directly on the host.

  2. Write rule files and Alertmanager configuration

    Move the existing rule_files entries and the alerting section of prometheus.yml into version control, then add the Alertmanager configuration file with its receivers, routes and inhibition rules. Keep secrets such as webhook URLs and passwords out of the files and reference them through the mechanism your secret store provides. Confirm each file parses locally by running promtool against it, and confirm that Alertmanager accepts its own configuration file before the pipeline depends on it.

  3. Add promtool validation to CI

    Create a pipeline job that runs promtool check config against prometheus.yml on every merge request, which also checks the rule files it references, and runs promtool check rules on each rule file. Add a unit test step with promtool test rules for alert rules that matter most, so a wrong expression or label fails before merge. The job should use the same Prometheus version as production, so validation matches runtime behavior. Done means a deliberately broken rule file makes the pipeline fail and a valid change passes.

  4. Set branch protection and required reviewers

    Configure the main branch so changes arrive only through merge requests, the validation job must pass before merge, and at least one reviewer from the monitoring or platform team must approve. Restrict who can push directly or force push, and require approval from the owner of any receiver or routing change that pages people. Ask your Git platform administrator to confirm these settings in writing, since the exact options depend on the hosting product. Done means a test change without approval cannot reach the main branch.

  5. Script the deployment and reload

    Write a deployment script that copies the validated files to the Prometheus host, validates them again on that host with the same promtool version, and then reloads the service. Reload through the lifecycle endpoint only if --web.enable-lifecycle is set and the endpoint is reachable from the deployment runner only, otherwise send SIGHUP to the Prometheus process. Reload Alertmanager the same way, using its own reload mechanism. Keep the previous known good configuration so a rollback is a file copy and a reload. Done means a merged change reaches the host and the script exits with an error when validation fails.

  6. Add post-reload checks

    After each reload, query the Prometheus configuration and reload status to confirm the new configuration was applied, and check that the expected rule groups are loaded. Query the targets API to confirm that the scrape jobs you changed report as up, and compare the count against the expected number. Check that Alertmanager reports the new configuration and that a test alert follows the intended route. If any check fails, the script should restore the previous configuration and report the failure. Done means the pipeline records a pass or a rollback for every deployment.

  7. Confirm the workflow end to end

    Run one controlled change through the full path: a branch with a harmless label change, a merge request, validation, approval, merge, deployment, reload and post-reload checks. Record the time each stage takes in your own environment and review the audit trail in Git and the pipeline logs. Then repeat with a deliberately invalid change to confirm that the pipeline blocks it. Ask your team to document the rollback procedure and who can run it. Done means both test changes behave as the design says, and the runbook matches what you observed.

How to template prometheus.yml per environment without drift

Keeping one set of rules across development, staging and production is mostly a question of where you draw the line between shared content and environment content. Shared content is the scrape job structure, the recording and alerting rules, and the Alertmanager routing tree. Environment content is the target addresses, external labels such as cluster or environment, retention settings and receiver endpoints. Decide this boundary before writing any template, and record it in the repository so reviewers can reject a change that moves a rule into an environment file. The two common approaches are a templating tool that renders a complete prometheus.yml in CI from a base file and a values file per environment, and plain per-environment files that are copied in full. Rendering keeps shared logic in one place but adds a build step that reviewers must read. Plain files are easier to diff but drift quickly unless a CI job compares the shared sections. Confirm with your own team which failure you would rather catch: a bad template render or a silently divergent copy. Whichever you choose, run promtool check config against each rendered output, not only the template source, so the validated file is the one that deploys.

Credentials must never be committed to Git, in any environment layer. This includes basic authentication passwords for scrape targets, bearer tokens, TLS private keys and the URLs or API keys for Alertmanager receivers such as chat, paging or email relays. Keep these in your secret manager or in files injected at deploy time, and reference them from configuration by path. Prometheus and Alertmanager can read credentials from files (for example, a password_file or credentials_file setting or a tls_config block pointing at certificate files), which lets the rendered configuration contain only paths. Check the configuration reference for your exact Prometheus and Alertmanager versions to confirm which fields accept file references, because support differs between fields. Add a secret scanning step to CI that fails on high-entropy strings or known token patterns in any file under the configuration directory, including rendered output that a pipeline might write as an artifact.

Shared rules should live in one directory that every environment pulls in unchanged, with a version pin in the deployment manifest so staging and production load the same commit or tag. Do not copy rule files into each environment, because the copies diverge the first time someone patches one of them. Environment differences belong in the environment layer only: a threshold that depends on capacity, a label value, or a target list. If a rule genuinely needs a different threshold per environment, express that as a variable passed into the shared rule template, not as a forked file. Add a CI check that renders the configuration for every environment and compares the rule files byte for byte, and require a reviewer from the owning team for any change to a shared rule. Illustrative example: a staging pipeline that renders the same rule group as production but with a different threshold variable should produce identical rule names and labels, and the check should fail if they differ.

Security risks in a configuration pipeline

A Git-managed Prometheus pipeline moves configuration, reloads and notification settings through several hands, and each step can widen access or leak secrets. The cards below cover the risks we see most often, each paired with the control that addresses it. Check them in order when you review an existing pipeline or design a new one.

Lifecycle endpoint left open

The --web.enable-lifecycle flag exposes reload and shutdown endpoints over HTTP. Anyone who can reach the listener can stop the server or trigger reloads at will. Restrict the listen address to the pipeline runner or a local sidecar, put the endpoint behind the reverse proxy's authentication, and confirm with a request from an unauthorized network segment that it is refused. Reloading with SIGHUP from the host avoids exposing the endpoint at all.

Security model

Admin APIs enabled by default

Admin HTTP APIs are disabled by default, and --web.enable-admin-api enables destructive operations such as deleting series. Enabling it in a shared template because a backfill or cleanup job once needed it leaves that power on for every environment. Keep the flag out of the base configuration, set it only in the specific job that needs it, and flag any pull request that adds it.

Credentials committed to Git

Alertmanager receiver tokens, SMTP passwords and basic auth hashes often end up in alertmanager.yml or templated prometheus.yml files. Anything committed becomes part of history and is copied to every clone and backup. Keep secret values in your secrets manager or CI variables, reference them from the rendered file at deploy time, and run a secret scanner on every push so a leak blocks the merge.

Basic auth without TLS

Prometheus supports HTTP basic authentication with bcrypt-hashed passwords, but without TLS the credentials cross the network in cleartext. This matters most when the pipeline or a remote reader authenticates over a segment you do not fully control. Enable TLS, require TLS 1.2 as the minimum, and check that the web.config.file contains no plaintext passwords. Confirm which TLS versions your proxy and clients negotiate.

Security model

Unreviewed changes reaching production

A direct push to the main branch can change scrape targets, alert thresholds or routing without anyone else reading the diff. Protect the production branch, require a reviewer who is not the author, and run promtool check config and promtool test rules as required checks. Keep the approval rule for changes that affect routing or silence behavior, since those changes can hide real alerts.

Receivers pointing outside the network

An Alertmanager receiver with an external webhook URL sends alert payloads, which can include hostnames, labels and job names, outside your boundary. A typo or a copied example can redirect production alerts to an unknown endpoint. Allow-list receiver destinations in review, keep notification channels inside the network where your environment requires it, and confirm each receiver's endpoint with the team that owns it.

Questions buyers ask about configuration as code for Prometheus

What does configuration as code for Prometheus cost in effort?

Effort comes mainly from the amount of configuration, the number of environments, and how much pipeline work is needed before the first change ships. The main work items are the repository layout for prometheus.yml, rule files and Alertmanager configuration, promtool checks in CI, a reload path, and a review workflow. Prometheus itself is licensed under Apache-2.0, so there is no license fee for the project; the cost is labor plus the Git hosting, CI runners and hosts you already run. Ask any quote to itemize each of these work items separately, with the environments and targets in scope listed, so you can compare it with your own team's estimate.

What drives the cost of a Prometheus configuration as code setup up?

The cost rises with the number of Prometheus servers, Alertmanager instances, environments (development, staging, production), and teams that edit configuration. Templating per environment is more work when targets come from several sources, such as static lists, file-based discovery and Kubernetes discovery. Alert rules that must be tested against historical behavior, and approval rules that differ between teams, add review and design time. Work also grows when existing hand-edited servers must be reconciled with the repository before the first automated reload. A written quote should state how many servers, rule groups, receivers and environments are covered.

How long does a typical rollout take, and what sets the duration?

The duration depends on how much existing configuration must be moved into Git and how many environments must be built before production. A single Prometheus server with one environment and a small rule set is a much shorter job than several servers with separate Alertmanager routing for each team. Typical blockers are waiting for CI runner access, agreeing on the approval workflow, and reconciling drifted configuration on live hosts. Ask the provider to show the planned sequence, which items depend on client access, and which milestones need sign-off before the next stage starts.

What does the work need from our team?

Plan for access and decisions from several groups before work begins. You need a Git hosting platform where the team can create repositories, protected branches and merge rules; CI runners that can run promtool check config and promtool check rules; approvers who own each area of configuration; and access to the Prometheus and Alertmanager hosts to test reloads. Someone must also decide who may merge changes to alert routing, since a mistake there can silence pages. Confirm these items with your team in advance, because missing access is one of the most common causes of delay.

Can our internal team run configuration as code without outside help?

Yes, if the team already operates Prometheus and has someone comfortable with YAML, Git and CI. The tooling is open source and the reload options are documented: the lifecycle endpoint is available only when --web.enable-lifecycle is set, and Prometheus also reloads on SIGHUP. What usually takes longer for an internal team is the design work: repository layout, environment templating, rule testing and deciding who approves what. An outside partner can shorten that design phase, but the ongoing ownership of rules and receivers stays with your team after handover.

How are ongoing changes and Prometheus upgrades handled?

Changes flow through the same path every time: a merge request, automated promtool validation, review by the named approver, then a reload to the target environment. Upgrades need separate planning. Prometheus minor releases start a new six-week cycle and generally stop receiving bug fixes after those six weeks, while LTS lines receive fixes for one year, so the version you pin determines how often you must upgrade. Confirm with the provider whether upgrades, rule maintenance and pipeline changes are covered by a fixed-scope project or by an ongoing retainer, and ask how each one is tested before release.

What should we request in a written quote?

Ask for a written scope that names every Prometheus server, Alertmanager instance, environment and repository in scope, plus the exact list of deliverables: repository structure, CI validation jobs, reload procedure, review workflow and handover documentation. The quote should separate one-time build work from any recurring retainer for support or upgrades. It should state which client-side items are assumed (Git hosting, runners, approvers, host access) and what happens if those are delayed. Finally, ask how acceptance is verified, such as a test reload and a deliberately broken change that CI must reject.

Operating the workflow after go-live

Once the configuration lives in Git, the repository becomes the control point for every monitoring change, so the first decision is who owns it. Assign a named review rotation for prometheus.yml, rule files and Alertmanager routing, with at least two reviewers who can approve a change to alert severity or receiver routing. Pair the rotation with a written emergency path: a change pushed directly to production during an incident should be committed back to the repository within the same working day, and the on-call engineer should record why the normal review was skipped. Drift is the other recurring risk. Schedule a job that compares the running configuration (for example, the output of the /api/v1/status/config endpoint) against the rendered file in the default branch, and treat any mismatch as a ticket for the owning team, not a silent overwrite.

Rollback should be a tested procedure, not a guess. Keep the last known-good commit tagged, redeploy the rendered files, and reload through the lifecycle endpoint or SIGHUP, then confirm the change took effect by checking the configuration and rule status in the UI. Changes to Alertmanager and rules should be tested before merge: run promtool check rules and promtool test rules on every rule file, and use amtool to validate Alertmanager routing and to check which receivers a sample alert would reach. Confirm with your receiver owners that test alerts arrive on each channel, since a valid file can still route to a dead webhook. Plan these checks around the release cycle described in the Prometheus release cycle page. Minor releases receive bug fixes for roughly six weeks, and the current LTS line is 3.13, supported until July 31, 2027, so schedule a configuration review before each upgrade window and confirm with the vendor which configuration fields changed between your current and target versions.

How DeployOpen works on this

DeployOpen plans and implements Prometheus configuration as code inside infrastructure you control, with the configuration, rules and Alertmanager routing kept in your Git repository. Engagements are fixed-scope, and the work is agreed in writing before it starts, so your team can review each deliverable against that scope.

How we scope

  • We inventory existing prometheus.yml files, rule groups, Alertmanager routes and the environments they run in.
  • We agree in writing which repositories, environments, reload methods and CI runners the engagement covers.
  • We confirm your Git hosting, review approvers and change process before any configuration moves into version control.
  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.

How we build

  • We structure the repository so shared scrape and rule definitions are separated from per-environment values.
  • We add promtool checks for configuration and rule files to the CI pipeline, failing builds on invalid syntax.
  • We wire reloads through the lifecycle endpoint or SIGHUP, and confirm which mode your deployment allows and secures.
  • We test Alertmanager routing and receiver configuration against sample alerts before they reach production.

How we hand over

  • You receive the repository layout, branching and review rules, and a written description of each pipeline stage.
  • Runbooks cover how to add a target, change a rule, roll back a bad change and trigger a controlled reload.
  • We document which secrets stay out of Git, where they are stored, and how templating fills them in at deploy time.
  • Your team walks through a supervised change end to end so the review workflow is tested before we leave.

How we support

  • Retainers cover updates to pipelines when Prometheus or Alertmanager releases change configuration behavior you rely on.
  • We can run periodic reviews of rule quality, unused targets and drift between Git and the running servers.
  • Security testing of the Prometheus and Alertmanager setup can be scoped alongside configuration support when you need it.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.