UniSet 2.32.1
BackendOpenTSDB.h
1/*
2 * Copyright (c) 2015 Pavel Vainerman.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation, version 2.1.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Lesser Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16// -----------------------------------------------------------------------------
17#ifndef _BackendOpenTSDB_H_
18#define _BackendOpenTSDB_H_
19// -----------------------------------------------------------------------------
20#include <deque>
21#include <memory>
22#include <unordered_map>
23#include <chrono>
24#include "UObject_SK.h"
25#include "SMInterface.h"
26#include "SharedMemory.h"
27#include "extensions/Extensions.h"
28#include "UTCPStream.h"
29// --------------------------------------------------------------------------
30namespace uniset
31{
32 // -----------------------------------------------------------------------------
101 // -----------------------------------------------------------------------------
104 public UObject_SK
105 {
106 public:
107 BackendOpenTSDB( uniset::ObjectId objId, xmlNode* cnode, uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
108 const std::string& prefix = "opentsdb" );
109 virtual ~BackendOpenTSDB();
110
112 static std::shared_ptr<BackendOpenTSDB> init_opendtsdb( int argc, const char* const* argv,
113 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
114 const std::string& prefix = "opentsdb" );
115
117 static void help_print( int argc, const char* const* argv );
118
119 inline std::shared_ptr<LogAgregator> getLogAggregator()
120 {
121 return loga;
122 }
123 inline std::shared_ptr<DebugStream> log()
124 {
125 return mylog;
126 }
127
128 enum Timers
129 {
130 tmFlushBuffer,
131 tmReconnect,
132 tmLastNumberOfTimer
133 };
134
135 protected:
137
138 // переопределяем callback, чтобы оптимизировать
139 // обработку большого количества сообщений
140 // и убрать не нужную в данном процессе обработку (включая sleep_msec)
141 virtual void callback() noexcept override;
142
143 virtual void askSensors( UniversalIO::UIOCommand cmd ) override;
144 virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
145 virtual void timerInfo( const uniset::TimerMessage* tm ) override;
146 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
147 virtual std::string getMonitInfo() const override;
148
149 void init( xmlNode* cnode );
150 bool flushBuffer();
151 bool reconnect();
152
153 std::shared_ptr<SMInterface> shm;
154
156 {
157 const std::string name;
158 const std::string tags;
159
160 ParamInfo( const std::string& _name, const std::string& _tags ):
161 name(_name), tags(_tags) {}
162 };
163
164 std::string tsdbPrefix;
165 std::string tsdbTags; // теги в виде строки TAG=VAL TAG2=VAL2 ...
166 std::unordered_map<uniset::ObjectId, ParamInfo> tsdbParams;
167
168 timeout_t bufSyncTime = { 5000 };
169 size_t bufSize = { 500 };
170 size_t bufMaxSize = { 5000 }; // drop messages
171 bool timerIsOn = { false };
172 timeout_t reconnectTime = { 5000 };
173 std::string lastError;
174
175 // буфер mutex-ом можно не защищать
176 // т.к. к нему идёт обращение только из основного потока обработки
177 // (sensorInfo, timerInfo)
178 std::deque<std::string> buf;
179
180 // работа с OpenTSDB
181 std::shared_ptr<UTCPStream> tcp;
182 std::string host = { "localhost" };
183 int port = { 4242 };
184
185 private:
186
187 std::string prefix;
188 };
189 // --------------------------------------------------------------------------
190} // end of namespace uniset
191// -----------------------------------------------------------------------------
192#endif // _BackendOpenTSDB_H_
193// -----------------------------------------------------------------------------
Definition UObject_SK.h:30
Definition BackendOpenTSDB.h:105
virtual std::string getMonitInfo() const override
Definition BackendOpenTSDB.cc:431
static std::shared_ptr< BackendOpenTSDB > init_opendtsdb(int argc, const char *const *argv, uniset::ObjectId shmID, const std::shared_ptr< SharedMemory > &ic=nullptr, const std::string &prefix="opentsdb")
Definition BackendOpenTSDB.cc:180
virtual void callback() noexcept override
Definition BackendOpenTSDB.cc:214
static void help_print(int argc, const char *const *argv)
Definition BackendOpenTSDB.cc:145
Definition MessageType.h:127
Definition MessageType.h:171
Definition MessageType.h:214
Definition Calibration.h:27
long ObjectId
Definition UniSetTypes_i.idl:30
Definition BackendOpenTSDB.h:156