]> granicus.if.org Git - icinga2/blob - lib/perfdata/opentsdbwriter.hpp
Merge pull request #7527 from Icinga/bugfix/checkable-command-endpoint-zone
[icinga2] / lib / perfdata / opentsdbwriter.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef OPENTSDBWRITER_H
4 #define OPENTSDBWRITER_H
5
6 #include "perfdata/opentsdbwriter-ti.hpp"
7 #include "icinga/service.hpp"
8 #include "base/configobject.hpp"
9 #include "base/tcpsocket.hpp"
10 #include "base/timer.hpp"
11 #include <fstream>
12
13 namespace icinga
14 {
15
16 /**
17  * An Icinga opentsdb writer.
18  *
19  * @ingroup perfdata
20  */
21 class OpenTsdbWriter final : public ObjectImpl<OpenTsdbWriter>
22 {
23 public:
24         DECLARE_OBJECT(OpenTsdbWriter);
25         DECLARE_OBJECTNAME(OpenTsdbWriter);
26
27         static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
28
29 protected:
30         void OnConfigLoaded() override;
31         void Resume() override;
32         void Pause() override;
33
34 private:
35         std::shared_ptr<AsioTcpStream> m_Stream;
36
37         Timer::Ptr m_ReconnectTimer;
38
39         void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
40         void SendMetric(const Checkable::Ptr& checkable, const String& metric,
41                 const std::map<String, String>& tags, double value, double ts);
42         void SendPerfdata(const Checkable::Ptr& checkable, const String& metric,
43                 const std::map<String, String>& tags, const CheckResult::Ptr& cr, double ts);
44         static String EscapeTag(const String& str);
45         static String EscapeMetric(const String& str);
46
47         void ReconnectTimerHandler();
48 };
49
50 }
51
52 #endif /* OPENTSDBWRITER_H */