]> granicus.if.org Git - icinga2/blob - lib/perfdata/influxdbwriter.hpp
Merge pull request #7527 from Icinga/bugfix/checkable-command-endpoint-zone
[icinga2] / lib / perfdata / influxdbwriter.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef INFLUXDBWRITER_H
4 #define INFLUXDBWRITER_H
5
6 #include "perfdata/influxdbwriter-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/tlsstream.hpp"
12 #include "base/workqueue.hpp"
13 #include <fstream>
14
15 namespace icinga
16 {
17
18 /**
19  * An Icinga InfluxDB writer.
20  *
21  * @ingroup perfdata
22  */
23 class InfluxdbWriter final : public ObjectImpl<InfluxdbWriter>
24 {
25 public:
26         DECLARE_OBJECT(InfluxdbWriter);
27         DECLARE_OBJECTNAME(InfluxdbWriter);
28
29         static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
30
31         void ValidateHostTemplate(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
32         void ValidateServiceTemplate(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
33
34 protected:
35         void OnConfigLoaded() override;
36         void Resume() override;
37         void Pause() override;
38
39 private:
40         WorkQueue m_WorkQueue{10000000, 1};
41         Timer::Ptr m_FlushTimer;
42         std::vector<String> m_DataBuffer;
43
44         void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
45         void CheckResultHandlerWQ(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
46         void SendMetric(const Checkable::Ptr& checkable, const Dictionary::Ptr& tmpl,
47                 const String& label, const Dictionary::Ptr& fields, double ts);
48         void FlushTimeout();
49         void FlushTimeoutWQ();
50         void Flush();
51
52         static String EscapeKeyOrTagValue(const String& str);
53         static String EscapeValue(const Value& value);
54
55         OptionalTlsStream Connect();
56
57         void AssertOnWorkQueue();
58
59         void ExceptionHandler(boost::exception_ptr exp);
60 };
61
62 }
63
64 #endif /* INFLUXDBWRITER_H */