1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #ifndef GRAPHITEWRITER_H
4 #define GRAPHITEWRITER_H
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"
13 #include <boost/thread/mutex.hpp>
19 * An Icinga graphite writer.
23 class GraphiteWriter final : public ObjectImpl<GraphiteWriter>
26 DECLARE_OBJECT(GraphiteWriter);
27 DECLARE_OBJECTNAME(GraphiteWriter);
29 static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
31 void ValidateHostNameTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
32 void ValidateServiceNameTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
35 void OnConfigLoaded() override;
36 void Resume() override;
37 void Pause() override;
41 boost::mutex m_StreamMutex;
42 WorkQueue m_WorkQueue{10000000, 1};
44 Timer::Ptr m_ReconnectTimer;
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);
54 void ReconnectTimerHandler();
57 void DisconnectInternal();
59 void ReconnectInternal();
61 void AssertOnWorkQueue();
63 void ExceptionHandler(boost::exception_ptr exp);
68 #endif /* GRAPHITEWRITER_H */