Compila Quindi Va

A blog by Marco Breveglieri, positive and confident software developer. 😉
it en

Prometheus Client per Delphi released!

2023-03-26 5 min read Marco Breveglieri

I’m happy to announce that the Prometheus client for Delphi written by myself is now available (with source code) on GitHub !

Here are all the details to download and use it to start monitoring your applications and services that are written in the Delphi language.

What is Prometheus?

Prometheus is an open source tool for monitoring and collecting system and application metrics.

This tool was created for the purpose of collecting and storing metrics on various aspects of your system, such as CPU usage, memory, network, and so on. It can also be used to monitor applications and services (including those built by you), collecting metrics on application performance, memory usage, HTTP requests handled, number of connected users and much more.

The metrics collected by the Prometheus server are associated with a timestamp, i.e. the precise date/time of the moment they were collected, and can be viewed through its graphical user interface, or exported to other tools, such as Grafana to create customized dashboards that are also understandable to business users, not just technical fellows.

Why do I need a client?

A Prometheus client is a software component that is used to send metrics collected by the system or applications to the Prometheus server, where they are collected and archived. In other words, the Prometheus client acts as a bridge between the collected metrics and the Prometheus server.

The specific task of a client is therefore twofold: to provide the classes and data structures to be able to define the metrics to be managed in a simple and immediate way, collect the instantaneous values of the metrics and export them in a format that is compliant with the Prometheus server, so that the tool can archive them and do some additional operations, such as sending alerts.

Several clients are available for various languages, some of them are “official” (managed directly by the Prometheus development team), others are mantained by third parties: you can find them all at the dedicated page on the official site.

The Prometheus client list was just missing one for the Delphi language, so I thought I’d write one. 😉

Towards integration with Delphi

The first ever release of this client, unofficial and very partial (non-optimized), was made available as an example in my talk held at Delphi Day 2022 (you can see the YouTube session replay ), where I talked about Prometheus, its use with Delphi and the integration with Grafana for data visualization.

You can safely refer to this talk to learn more and take your first steps with both Prometheus and Grafana, and also with the Delphi client for Prometheus since much of the code shown is still fully current and valid.

And here is the Prometheus Client for Delphi!

In the next few months I proceeded to strengthen the client logic and apply some refactoring on the previously written code, which now you can finally download from GitHub using GitHub Desktop or an equivalent tool, or using the Delphi compatible package manager, Boss .

On the GitHub page of the client at the address above you will find all the accompanying instructions.

Use the client in your own projects

To use the Prometheus client within your own projects, it is necessary to set up an HTTP endpoint from which it is possible to export the values of the metrics themselves in the text format supported by the tool.

In the source code available on GitHub there is a “Samples” folder in which it is possible to find several demo projects from which to take inspiration for understanding how to expose the metrics using one of the many popular web frameworks for Delphi.

At the moment, it is possible to find examples of startup projects for

If you use Horse web framework for your projects, there is a middleware available to automatically integrate metrics export into your application with very few lines of code (just enable the middleware by calling the appropriate method).

No need to say that middlewares and examples mentioned - as well as the main client - are also free and opensource.

Some notes and warnings…

Below are some notes regarding the features supported by the client and some of its current known limitations and parts that are still in the works but will be released soon.

The Prometheus Client for Delphi supports all of the minimum requirements which are required by the Prometheus team, as described in the appropriate documentation for writing clients .

The current version of the client implements the main metrics i.e. Counter and Gauge ; the other additional (but extremely useful) metric types, namely Histogram and Summary , are being implemented and will be made available soon in future releases of the client.

As for the example projects and middleware, they will soon be integrated with further starter projects and integration plugins for the most popular web development frameworks for Delphi that are still missing, i.e. (to name a few)

Finally, the so called predefined metrics are missing, i.e. those relating to the use of CPU or memory, generally supplied by default by the client, together with data relating to any runtime used (as occurs for .NET and for Java); these metrics are not yet available “out of the box” within the client, but there are various evaluations underway to include them in the list, perhaps providing a way to enable them by default getting values from APIs available on the target platform (because it is essential to try keeping the client as crossplatform/crossdevice as possible).

How to contribute?

I will configure as soon as possible the tools provided by GitHub to send feedback, pull requests and contributions on this project, in order to further consolidate the “code base” and integrate it with new features and utilities.

However, for suggestions, reports or information on the client, you can contact me directly through social networks you can find on my personal homepage .

Happy coding! :)