// // Created by 闫鹏宇 on 2022/7/29. // #ifndef OPCUA_EXPORTER_COLLECTOR_H #define OPCUA_EXPORTER_COLLECTOR_H #include #include #include #include #include #include #include #include #include #include #include class collector : public prometheus::Collectable { public: explicit collector(YAML::Node const &config, std::shared_ptr ua_client); ~collector() override = default; std::vector 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 registry_; std::shared_ptr ua_client_; std::vector ua_read_node_ids; struct st_node { std::string name; prometheus::Family *family{nullptr}; prometheus::Gauge *real{nullptr}; prometheus::Gauge *simulation{nullptr}; simulation_manager *manager; void setValue(double val); }; std::map nodes; std::map simulation_manager_; nlohmann::json metrics_json_; }; #endif // OPCUA_EXPORTER_COLLECTOR_H