]> git.proxmox.com Git - ceph.git/blame - ceph/src/exporter/DaemonMetricCollector.h
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / exporter / DaemonMetricCollector.h
CommitLineData
2a845540
TL
1#pragma once
2
3#include "common/admin_socket_client.h"
4#include <map>
5#include <string>
6#include <vector>
7
8#include <boost/asio.hpp>
9#include <boost/json/object.hpp>
10#include <filesystem>
11#include <map>
12#include <string>
13#include <vector>
14
15struct pstat {
16 unsigned long utime;
17 unsigned long stime;
18 unsigned long minflt;
19 unsigned long majflt;
20 unsigned long start_time;
21 int num_threads;
22 unsigned long vm_size;
23 int resident_size;
24};
25
26class MetricsBuilder;
27class OrderedMetricsBuilder;
28class UnorderedMetricsBuilder;
29class Metric;
30
31typedef std::map<std::string, std::string> labels_t;
32
33class DaemonMetricCollector {
34public:
35 void main();
36 std::string get_metrics();
aee94f69 37 labels_t get_extra_labels(std::string daemon_name);
2a845540
TL
38
39private:
40 std::map<std::string, AdminSocketClient> clients;
41 std::string metrics;
42 std::mutex metrics_mutex;
43 std::unique_ptr<MetricsBuilder> builder;
44 void update_sockets();
45 void request_loop(boost::asio::steady_timer &timer);
46
47 void dump_asok_metrics();
48 void dump_asok_metric(boost::json::object perf_info,
49 boost::json::value perf_values, std::string name,
50 labels_t labels);
1e59de90 51 std::pair<labels_t, std::string> add_fixed_name_metrics(std::string metric_name);
2a845540
TL
52 void get_process_metrics(std::vector<std::pair<std::string, int>> daemon_pids);
53 std::string asok_request(AdminSocketClient &asok, std::string command, std::string daemon_name);
54};
55
56class Metric {
57private:
58 struct metric_entry {
59 labels_t labels;
60 std::string value;
61 };
62 std::string name;
63 std::string mtype;
64 std::string description;
65 std::vector<metric_entry> entries;
66
67public:
68 Metric(std::string name, std::string mtype, std::string description)
69 : name(name), mtype(mtype), description(description) {}
70 Metric(const Metric &) = default;
71 Metric() = default;
72 void add(labels_t labels, std::string value);
73 std::string dump();
74};
75
76class MetricsBuilder {
77public:
78 virtual ~MetricsBuilder() = default;
79 virtual std::string dump() = 0;
80 virtual void add(std::string value, std::string name, std::string description,
81 std::string mtype, labels_t labels) = 0;
82
83protected:
84 std::string out;
85};
86
87class OrderedMetricsBuilder : public MetricsBuilder {
88private:
89 std::map<std::string, Metric> metrics;
90
91public:
92 std::string dump();
93 void add(std::string value, std::string name, std::string description,
94 std::string mtype, labels_t labels);
95};
96
97class UnorderedMetricsBuilder : public MetricsBuilder {
98public:
99 std::string dump();
100 void add(std::string value, std::string name, std::string description,
101 std::string mtype, labels_t labels);
102};
103
104DaemonMetricCollector &collector_instance();