58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
//
|
|
// Created by 闫鹏宇 on 2022/7/29.
|
|
//
|
|
|
|
#ifndef OPCUA_EXPORTER_COLLECTOR_H
|
|
#define OPCUA_EXPORTER_COLLECTOR_H
|
|
|
|
#include <client/client.h>
|
|
#include <nlohmann/json.hpp>
|
|
#include <open62541/client.h>
|
|
#include <prometheus/collectable.h>
|
|
#include <prometheus/family.h>
|
|
#include <prometheus/gauge.h>
|
|
#include <prometheus/labels.h>
|
|
#include <prometheus/metric_family.h>
|
|
#include <prometheus/registry.h>
|
|
#include <simulation_manager.hpp>
|
|
#include <yaml-cpp/yaml.h>
|
|
|
|
class collector : public prometheus::Collectable {
|
|
public:
|
|
explicit collector(YAML::Node const &config,
|
|
std::shared_ptr<client> ua_client);
|
|
~collector() override = default;
|
|
std::vector<prometheus::MetricFamily> Collect() const override;
|
|
|
|
nlohmann::json const &getMetricsJson();
|
|
nlohmann::json simulationConfig(std::string const &name);
|
|
void setSimulationConfig(std::string const &name,
|
|
nlohmann::json const &config);
|
|
|
|
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<client> ua_client_;
|
|
std::vector<std::string> ua_read_node_ids;
|
|
|
|
struct st_node {
|
|
std::string name;
|
|
prometheus::Family<prometheus::Gauge> *family{nullptr};
|
|
prometheus::Gauge *real{nullptr};
|
|
prometheus::Gauge *simulation{nullptr};
|
|
simulation_manager *manager;
|
|
void setValue(double val);
|
|
};
|
|
|
|
std::map<std::string, st_node> nodes;
|
|
std::map<std::string, simulation_manager *> simulation_manager_;
|
|
nlohmann::json metrics_json_;
|
|
};
|
|
|
|
#endif // OPCUA_EXPORTER_COLLECTOR_H
|