Code Monkey home page Code Monkey logo

prometheus-exporter's Introduction

Prometheus Exporter

Implementing a Prometheus exporter with Python. Prometheus follows an HTTP pull model, It scrapes Prometheus metrics from endpoints routinely. Typically the abstraction layer between the application and Prometheus is an exporter, which takes application-formatted metrics and converts them to Prometheus metrics for consumption.

Why exporter?

You might need to write your own exporter if:

  • You are using 3rd party software that does not have an existing exporter already
  • You want to generate Prometheus metrics from software that you have written

Schema

Example

Let's create a simple http service by the following command:

cd app
uvicorn main:app --reload

Now we have a http server that returns the following stats on localhost:8000/status:

{
    "current_requests": 10,
    "pending_requests": 2,
    "total_uptime": 25.99274135,
    "health": "healthy"
}

Now run the exporter by python exporter/exporter.py and you can see the response on localhost:9877.

ENV

Name Description Default
POLLING_INTERVAL_SECONDS Interval time of polling metrics in exporter 5
EXPORTER_PORT HTTP port of exporter 9877
TARGET_HOST Address of target localhost
TARGET_PORT HTTP port of target 8000
TARGET_METRICS Path of metrics status

Response

Exporter provides the following output, which are prometheus metrics.

# HELP python_gc_objects_collected_total Objects collected during gc
# TYPE python_gc_objects_collected_total counter
python_gc_objects_collected_total{generation="0"} 626.0
python_gc_objects_collected_total{generation="1"} 33.0
python_gc_objects_collected_total{generation="2"} 0.0
# HELP python_gc_objects_uncollectable_total Uncollectable object found during GC
# TYPE python_gc_objects_uncollectable_total counter
python_gc_objects_uncollectable_total{generation="0"} 0.0
python_gc_objects_uncollectable_total{generation="1"} 0.0
python_gc_objects_uncollectable_total{generation="2"} 0.0
# HELP python_gc_collections_total Number of times this generation was collected
# TYPE python_gc_collections_total counter
python_gc_collections_total{generation="0"} 54.0
python_gc_collections_total{generation="1"} 4.0
python_gc_collections_total{generation="2"} 0.0
# HELP python_info Python platform information
# TYPE python_info gauge
python_info{implementation="CPython",major="3",minor="10",patchlevel="0",version="3.10.0"} 1.0
# HELP app_requests_current Current requests
# TYPE app_requests_current gauge
app_requests_current 4.0
# HELP app_requests_pending Pending requests
# TYPE app_requests_pending gauge
app_requests_pending 0.0
# HELP app_uptime Uptime
# TYPE app_uptime gauge
app_uptime 104.914734
# HELP app_health Health
# TYPE app_health gauge
app_health{app_health="healthy"} 1.0
app_health{app_health="unhealthy"} 0.0

Docker

Use the following command to execute the project in Docker:

docker compose up -d

Now go to localhost:9090 to get the app metrics.

Resources

prometheus-exporter's People

Contributors

amirhnajafiz avatar

Stargazers

 avatar  avatar

prometheus-exporter's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.