A lightweight C library for exposing Prometheus metrics in Zephyr applications. This library allows Zephyr developers to easily integrate Prometheus metrics into their applications, enabling monitoring and observability in Zephyr-based systems.
Prometheus Exposer for Zephyr provides a simple and efficient way to expose metrics from Zephyr applications in the Prometheus format. It includes functionality to create various types of metrics such as counters, gauges, histograms, and summaries, register them with a collector, and expose them over HTTP for scraping by a Prometheus server.
To get started with Prometheus C Library, follow these steps:
- Clone the repository to your local machine.
- Navigate to the project directory.
- Build the library using the provided build system.
- Integrate the library into your C project.
To build the library and run the example applications, follow these steps:
- Ensure that you have a C compiler (e.g., GCC) installed on your system.
- Navigate to the project directory.
- Run the build command following:
mkdir build && cd build
cmake ..
make all
- After successful compilation, you can run the example applications to see the library in action.
To use Prometheus C Library in your C project, follow these steps:
- Include the necessary header files in your source files.
- Initialize a collector to store your metrics.
- Create various types of metrics (e.g., counters, gauges, histograms, summaries) and register them with the collector.
- Expose the metrics via an HTTP endpoint using the provided exposer component.
- Configure your Prometheus server to scrape the metrics from the endpoint.
#include <prometheus.h>
// Initialize a counter metric
pm_counter_t *http_requests_total = pm_counter_create("http_requests_total", "Total HTTP requests", "method", "GET");
// Increment the counter
pm_counter_inc(http_requests_total);
// Register the metric with the collector
pm_collector_register_metric(collector, (pm_metric_t *)http_requests_total);
Repository create by taking advantage of following documents:
I suggest to read following zephyr issues:
- first one add mongoose module into main manifest(west.yaml) following way:
remotes:
- name: zephyrproject-rtos
url-base: https://github.com/zephyrproject-rtos
- name: zephyrus
url-base: https://github.com/mustafaabdullahk/zephyrus
projects:
- name: zephyr
remote: zephyrproject-rtos
revision: main
import:
# By using name-allowlist we can clone only the modules that are
# strictly needed by the application.
name-allowlist:
- cmsis # required by the ARM port
- hal_nordic # required by the custom_plank board (Nordic based)
- hal_stm32 # required by the nucleo_f302r8 board (STM32 based)
- mbedtls
- name: prometheus
remote: zephyrus # referred from remotes can change other forks or main
submodules: true # prometheus add as submodule
revision: main # can select different branch
repo-path: .
path: modules/lib/prometheus
-
second one run
west update
and initialized mongoose module -
third one can add your prj.conf for using mongoose library.
CONFIG_PROMETHEUS=y
CONFIG_POSIX_API=y
CONFIG_NETWORKING=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=n
CONFIG_NET_TCP=y
CONFIG_NET_UDP=y
CONFIG_NET_DHCPV4=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POLL_MAX=32
CONFIG_POSIX_MAX_FDS=32
CONFIG_NET_MAX_CONN=10
CONFIG_NET_MAX_CONTEXTS=10
CONFIG_NET_CONFIG_SETTINGS=y
CONFIG_NET_CONNECTION_MANAGER=y
CONFIG_NET_LOG=y
CONFIG_INIT_STACKS=y
CONFIG_LOG=y
CONFIG_ISR_STACK_SIZE=2048
CONFIG_MAIN_STACK_SIZE=8192
CONFIG_IDLE_STACK_SIZE=1024
CONFIG_REQUIRES_FULL_LIBC=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8194
- add library and ready to start coding:
#include <prometheus/counter.h>
Zephyr Prometheus Example Application
# initialize my-workspace for the example-application (main branch)
west init -m https://github.com/mustafaabdullahk/zephyr-prometheus-example.git --mr main prom-workspace
# update Zephyr modules
cd my-workspace
west update
# build for stm32h747disco
west build -b stm32h747i_disco/stm32h747xx/m7 app/ -p
- Lightweight and efficient C library for instrumenting C-based applications.
- Supports various types of metrics, including counters, gauges, histograms, and summaries.
- Exposes metrics in the Prometheus exposition format via an HTTP endpoint.
- Easy to integrate into existing C projects.
- Well-documented API and example applications for reference.
Contributions to Prometheus C Library are welcome! If you would like to contribute, please follow these guidelines:
- Fork the repository and create a new branch for your feature or bug fix.
- Implement your changes and ensure that all tests pass.
- Submit a pull request with a detailed description of your changes and the problem they solve.
- Participate in code reviews and address any feedback from the maintainers.
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.