Skip to content

hayk96/prometheus-api

Repository files navigation

prometheus-api

Extended HTTP API service for Prometheus

Build Release Github stars Github forks Github issues Docker Stars Docker Pulls Docker Image Size

Table of Contents
  1. About The Project
  2. Architecture Overview
  3. Getting Started
  4. Examples
  5. API model
  6. Configuration
  7. Grafana dashboard
  8. Web UI
  9. Roadmap
  10. Author and Maintainer
  11. License

About The Project

This project enhances the native Prometheus HTTP API by providing additional features and addressing its limitations. Running as a sidecar alongside the Prometheus server enables users to extend the capabilities of the API.

One notable limitation of the native Prometheus HTTP API is the inability to programmatically create/delete rules. This project addresses this limitation by offering a solution for rule creation/deletion via the API. By leveraging prometheus-api, users can overcome the native constraints, gaining the ability to create rules programmatically. This enhances flexibility and automation in monitoring and alerting workflows.

ⓘ The decision to exclude a rule creation feature in the Prometheus API, as discussed in this GitHub issue, prioritizes stability and integrity within the Prometheus ecosystem. prometheus-api serves as an external solution, seamlessly integrating with existing Prometheus deployments while providing the sought-after rule-creation capability.

Architecture Overview

Getting Started

Prerequisites

The following prerequisites are required to get up and running with this tool:

  • The Prometheus server's rules directory must be shared and accessible
  • The Prometheus lifecycle API must be enabled to allow requesting the /reload API

Quick Start

Get prometheus-api up and running in minutes.
In this quick-start guide, you will run Prometheus and prometheus-api services using Docker Compose and send requests to the API service. Please refer to this example guide to get started.

Examples

A simple example of recording rules created using an API would be:

Request

curl -i -XPUT 'http://localhost:5000/api/v1/rules/example-record.yml' \
--header 'Content-Type: application/json' \
--data '{
  "data": {
    "groups": [
      {
        "name": "ExampleRecordingRule",
        "rules": [
          {
            "record": "code:prometheus_http_requests_total:sum",
            "expr": "sum by (code) (prometheus_http_requests_total)"
          }
        ]
      }
    ]
  }
}'

Response

HTTP/1.1 201 Created
content-length: 66
content-type: application/json

{"status":"success","message":"The rule was created successfully"}

API Model

The prometheus-api, built upon REST API design principles, provides a seamless and efficient way to interact with native Prometheus HTTP API. If you would like to explore its capabilities and learn more about its endpoints, request formats, and response structures, please refer to the comprehensive documentation available here.

Configuration

Flags

usage: python3 main.py [option]

Extended HTTP API service for Prometheus

optional arguments:
  -h, --help            show this help message and exit
  --web.listen-address WEB.LISTEN_ADDRESS
                        address to listen on for API
  --file.prefix FILE.PREFIX
                        a prefix of filenames generated by the server
  --file.extension FILE.EXTENSION
                        rule files will be created with this suffix
  --log.level {debug,info,warning,error}
                        only log messages with the given severity or above. One of: [debug, info, warning, error]
  --web.enable-ui {true,false}
                        enable web management UI

required parameters:
  --rule.path RULE.PATH
                        path to Prometheus rules directory
  --prom.addr PROM.ADDR
                        URL of Prometheus server, e.g. http://localhost:9090

Grafana dashboard

Grafana dashboard JSON model is available here.

Web UI

The web user interface is disabled by default. As the prometheus-api project is specifically designed to extend the APIs available to Prometheus, the UI serves as an optional add-on feature. It offers a convenient and flexible way to manage Prometheus rules. To enable the web UI, the --web.enable-ui=true flag must be passed at the startup of the application.

Roadmap

  • Add Prometheus instrumentation to expose metrics.
  • Add a Bulk API to allow the creation of multiple rules via a single API call.
  • Implement a way to update existing rules through the API.

Author and Maintainer

Hayk Davtyan:

License

MIT License, see LICENSE.