1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #ifndef GRAPHITEWRITER_H
21 #define GRAPHITEWRITER_H
23 #include "perfdata/graphitewriter-ti.hpp"
24 #include "icinga/service.hpp"
25 #include "base/configobject.hpp"
26 #include "base/tcpsocket.hpp"
27 #include "base/timer.hpp"
28 #include "base/workqueue.hpp"
30 #include <boost/thread/mutex.hpp>
36 * An Icinga graphite writer.
40 class GraphiteWriter final : public ObjectImpl<GraphiteWriter>
43 DECLARE_OBJECT(GraphiteWriter);
44 DECLARE_OBJECTNAME(GraphiteWriter);
46 static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata);
48 void ValidateHostNameTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
49 void ValidateServiceNameTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
52 void OnConfigLoaded() override;
53 void Resume() override;
54 void Pause() override;
58 boost::mutex m_StreamMutex;
59 WorkQueue m_WorkQueue{10000000, 1};
61 Timer::Ptr m_ReconnectTimer;
63 void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
64 void CheckResultHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
65 void SendMetric(const String& prefix, const String& name, double value, double ts);
66 void SendPerfdata(const String& prefix, const CheckResult::Ptr& cr, double ts);
67 static String EscapeMetric(const String& str);
68 static String EscapeMetricLabel(const String& str);
69 static Value EscapeMacroMetric(const Value& value);
71 void ReconnectTimerHandler();
76 void AssertOnWorkQueue();
78 void ExceptionHandler(boost::exception_ptr exp);
83 #endif /* GRAPHITEWRITER_H */