]> granicus.if.org Git - icinga2/blob - lib/perfdata/graphitewriter.hpp
Merge pull request #7124 from Icinga/bugfix/namespace-thread-safe
[icinga2] / lib / perfdata / graphitewriter.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef GRAPHITEWRITER_H
4 #define GRAPHITEWRITER_H
5
6 #include "perfdata/graphitewriter-ti.hpp"
7 #include "icinga/service.hpp"
8 #include "base/configobject.hpp"
9 #include "base/tcpsocket.hpp"
10 #include "base/timer.hpp"
11 #include "base/workqueue.hpp"
12 #include <fstream>
13 #include <boost/thread/mutex.hpp>
14
15 namespace icinga
16 {
17
18 /**
19  * An Icinga graphite writer.
20  *
21  * @ingroup perfdata
22  */
23 class GraphiteWriter final : public ObjectImpl<GraphiteWriter>
24 {
25 public:
26         DECLARE_OBJECT(GraphiteWriter);
27         DECLARE_OBJECTNAME(GraphiteWriter);
28
29         static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
30
31         void ValidateHostNameTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
32         void ValidateServiceNameTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
33
34 protected:
35         void OnConfigLoaded() override;
36         void Resume() override;
37         void Pause() override;
38
39 private:
40         Stream::Ptr m_Stream;
41         boost::mutex m_StreamMutex;
42         WorkQueue m_WorkQueue{10000000, 1};
43
44         Timer::Ptr m_ReconnectTimer;
45
46         void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
47         void CheckResultHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
48         void SendMetric(const Checkable::Ptr& checkable, const String& prefix, const String& name, double value, double ts);
49         void SendPerfdata(const Checkable::Ptr& checkable, const String& prefix, const CheckResult::Ptr& cr, double ts);
50         static String EscapeMetric(const String& str);
51         static String EscapeMetricLabel(const String& str);
52         static Value EscapeMacroMetric(const Value& value);
53
54         void ReconnectTimerHandler();
55
56         void Disconnect();
57         void DisconnectInternal();
58         void Reconnect();
59         void ReconnectInternal();
60
61         void AssertOnWorkQueue();
62
63         void ExceptionHandler(boost::exception_ptr exp);
64 };
65
66 }
67
68 #endif /* GRAPHITEWRITER_H */