Program Listing for File prometheus_writer.hpp
↰ Return to documentation for file (monitoring/prometheus_writer.hpp)
#ifndef PROMETHEUS_WRITER_HPP_
#define PROMETHEUS_WRITER_HPP_
#include <format>
#include <iostream>
#include <memory>
#include <unordered_map>
#include <ers/ers.h>
#include <prometheus/exposer.h>
#include <prometheus/registry.h>
#include <prometheus/gauge.h>
#include <prometheus/labels.h>
#include "writer.hpp"
ERS_DECLARE_ISSUE(monitoring_log, prometheus_issue, issue_message, ((const std::string&)issue_message))
class PrometheusWriter : public Writer {
public:
explicit PrometheusWriter(int port);
void write_message(const nlohmann::json& message) override;
private:
std::unique_ptr<prometheus::Exposer> exposer;
std::shared_ptr<prometheus::Registry> registry;
std::unordered_map<std::string, prometheus::Gauge*> prometheus_metrics;
void metric_to_prometheus(const std::string& app, const std::string& key, double value,
const std::string& hostname = "", const std::string& device = "",
const std::string& dma = "", const std::string& thread = "",
const std::string& fid = "");
};
#endif // PROMETHEUS_WRITER_HPP_