prometheus-cpp
prometheus-cpp copied to clipboard
Feature request: allow passing base URL instead of host + port for Gateway constructor
Recently, I found myself wanting to use prometheus-cpp in push mode. As I already had VictoriaMetrics running, which exposes a Pushgateway-compatible API at /api/v1/import/prometheus
, it seemed unnecessary to install an extra Pushgateway component.
However, prometheus-cpp does not support setting a base URL for the Gateway
class constructor: it only takes a host and port as connection information.
In the end, I succesfully macgyvered a solution that puts the path after the port number. More specifically: my program takes a base URL as a configuration parameter, this URL gets chopped into two parts: scheme + host and port + path. It is currently possible to pass the scheme combined with the host in the host
parameter of the Gateway
constructor, as it does not handle IPv6 addresses correctly. (Or at least, for an IPv6 address, the user would have to add square brackets around the address themselves. Should I file an issue for this too?)
Of course, what I made here is not exactly a clean solution. It would be nice if it would be possible to pass a base URL to the Gateway constructor instead.