Fawkes API Fawkes Development Version
metrics_thread.h
1/***************************************************************************
2 * metrics_thread.h - Metrics exporter for Prometheus plugin
3 *
4 * Created: Sat May 06 19:43:10 2017 (German Open 2017)
5 * Copyright 2017 Tim Niemueller [www.niemueller.de]
6 ****************************************************************************/
7
8/* This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Library General Public License for more details.
17 *
18 * Read the full text in the LICENSE.GPL file in the doc directory.
19 */
20
21#ifndef _PLUGINS_METRICS_METRICS_THREAD_H_
22#define _PLUGINS_METRICS_METRICS_THREAD_H_
23
24#include "aspect/metrics_inifin.h"
25#include "aspect/metrics_supplier.h"
26
27#include <aspect/aspect_provider.h>
28#include <aspect/blackboard.h>
29#include <aspect/blocked_timing.h>
30#include <aspect/configurable.h>
31#include <aspect/logging.h>
32#include <aspect/webview.h>
33#include <blackboard/interface_listener.h>
34#include <blackboard/interface_observer.h>
35#include <core/threading/thread.h>
36#include <core/utils/lock_map.h>
37#include <interfaces/MetricFamilyInterface.h>
38
39#include <memory>
40
42
43namespace fawkes {
44class MetricCounterInterface;
45class MetricGaugeInterface;
46class MetricUntypedInterface;
47class MetricHistogramInterface;
48//MetricSummaryInterface;
49} // namespace fawkes
50
51namespace io {
52namespace prometheus {
53namespace client {
54class MetricFamily;
55}
56} // namespace prometheus
57} // namespace io
58
70{
71public:
73 virtual ~MetricsThread();
74
75 virtual void init();
76 virtual void loop();
77 virtual void finalize();
78
79 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
80protected:
81 virtual void
83 {
84 Thread::run();
85 }
86
87private:
88 typedef union {
89 fawkes::MetricCounterInterface * counter;
90 fawkes::MetricGaugeInterface * gauge;
91 fawkes::MetricUntypedInterface * untyped;
92 fawkes::MetricHistogramInterface *histogram;
93 //fawkes::MetricSummaryInterface * summary;
94 } MetricFamilyData;
95
96 typedef struct
97 {
98 fawkes::MetricFamilyInterface * metric_family;
99 fawkes::MetricFamilyInterface::MetricType metric_type;
100 std::list<MetricFamilyData> data;
101 } MetricFamilyBB;
102
103private:
104 // for BlackBoardInterfaceObserver
105 virtual void bb_interface_created(const char *type, const char *id) noexcept;
106
107 // for BlackBoardInterfaceListener
108 virtual void bb_interface_writer_removed(fawkes::Interface *interface,
109 unsigned int instance_serial) noexcept;
110 virtual void bb_interface_reader_removed(fawkes::Interface *interface,
111 unsigned int instance_serial) noexcept;
112 virtual void bb_interface_data_refreshed(fawkes::Interface *interface) noexcept;
113
114 // for MetricsSupplier
115 virtual std::list<io::prometheus::client::MetricFamily> metrics();
116
117 // for MetricsManager
118 virtual std::list<io::prometheus::client::MetricFamily> all_metrics();
119
120 virtual void add_supplier(MetricsSupplier *supplier);
121 virtual void remove_supplier(MetricsSupplier *supplier);
122
123 virtual const fawkes::LockList<MetricsSupplier *> &metrics_suppliers() const;
124
125 bool conditional_open(const std::string &id, MetricFamilyBB &mfbb);
126 void conditional_close(fawkes::Interface *interface) noexcept;
127 void parse_labels(const std::string &labels, io::prometheus::client::Metric *m);
128
129private:
130 MetricsRequestProcessor * req_proc_;
132
133 fawkes::MetricsAspectIniFin metrics_aspect_inifin_;
134
135 // Internal metric families
136 std::shared_ptr<io::prometheus::client::MetricFamily> imf_loop_count_;
137 std::shared_ptr<io::prometheus::client::MetricFamily> imf_metrics_requests_;
138 std::shared_ptr<io::prometheus::client::MetricFamily> imf_metrics_proctime_;
139
140 std::vector<std::shared_ptr<io::prometheus::client::MetricFamily>> internal_metrics_;
141
142 fawkes::LockList<MetricsSupplier *> metrics_suppliers_;
143};
144
145#endif
Metrics web request processor.
Thread to export metrics for Prometheus.
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual ~MetricsThread()
Destructor.
MetricsThread()
Constructor.
virtual void finalize()
Finalize the thread.
virtual void loop()
Code to execute in the thread.
virtual void init()
Initialize the thread.
Thread aspect provide a new aspect.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
BlackBoard interface listener.
BlackBoard interface observer.
Thread aspect to use blocked timing.
Thread aspect to access configuration data.
Definition: configurable.h:33
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
Thread aspect to log output.
Definition: logging.h:33
MetricsAspect initializer/finalizer.
Base class for metrics managers.
Metrics supplier class.
Thread class encapsulation of pthreads.
Definition: thread.h:46
Thread aspect to provide web pages via Webview.
Definition: webview.h:37
Fawkes library namespace.