56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
//
|
|
// Created by test on 2022/11/3.
|
|
//
|
|
|
|
#ifndef OPCUA_EXPORTER_DBPCOLLECTOR_H
|
|
#define OPCUA_EXPORTER_DBPCOLLECTOR_H
|
|
|
|
#include <prometheus/collectable.h>
|
|
#include <prometheus/family.h>
|
|
#include <prometheus/labels.h>
|
|
#include <prometheus/metric_family.h>
|
|
#include <prometheus/registry.h>
|
|
#include <prometheus/gauge.h>
|
|
#include <yaml-cpp/yaml.h>
|
|
#include <DBPclient/DBPclient.h>
|
|
#include <json.hpp>
|
|
#include <spdlog/spdlog.h>
|
|
|
|
class DBPcollector : public prometheus::Collectable {
|
|
public:
|
|
explicit DBPcollector(YAML::Node const &config, std::shared_ptr<DBPclient> dbp_client);
|
|
|
|
~DBPcollector() override = default;
|
|
|
|
std::vector<prometheus::MetricFamily> Collect() const override;
|
|
|
|
nlohmann::json const &getMetricsJson();
|
|
|
|
private:
|
|
void buildMetrics(YAML::Node const &config);
|
|
|
|
bool updateMetrics();
|
|
|
|
void clearMetrics();
|
|
|
|
prometheus::Labels getNodeLabels(YAML::Node const &labels);
|
|
|
|
private:
|
|
std::shared_ptr<prometheus::Registry> registry_;
|
|
std::shared_ptr<DBPclient> dbp_client_;
|
|
std::vector<std::string> dbp_read_node_ids;
|
|
|
|
struct st_node {
|
|
std::string name;
|
|
prometheus::Family<prometheus::Gauge> *family{nullptr};
|
|
prometheus::Gauge *data{nullptr};
|
|
void setValue(double val);
|
|
};
|
|
|
|
std::map<std::string, st_node> nodes;
|
|
nlohmann::json metrics_json_;
|
|
};
|
|
|
|
|
|
#endif //OPCUA_EXPORTER_DBPCOLLECTOR_H
|