UniSet @VERSION@
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#include "USingleProcess.h"
30// --------------------------------------------------------------------------
31namespace uniset
32{
33 // -----------------------------------------------------------------------------
145 // -----------------------------------------------------------------------------
148 private USingleProcess,
149 public UObject_SK
150 {
151 public:
152 BackendOpenTSDB( uniset::ObjectId objId, xmlNode* cnode, uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
153 const std::string& prefix = "opentsdb" );
154 virtual ~BackendOpenTSDB();
155
157 static std::shared_ptr<BackendOpenTSDB> init_opendtsdb( int argc, const char* const* argv,
158 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
159 const std::string& prefix = "opentsdb" );
160
162 static void help_print( int argc, const char* const* argv );
163
164 inline std::shared_ptr<LogAgregator> getLogAggregator()
165 {
166 return loga;
167 }
168 inline std::shared_ptr<DebugStream> log()
169 {
170 return mylog;
171 }
172
173 enum Timers
174 {
175 tmFlushBuffer,
176 tmReconnect,
177 tmLastNumberOfTimer
178 };
179
180 protected:
182
183 // переопределяем callback, чтобы оптимизировать
184 // обработку большого количества сообщений
185 // и убрать не нужную в данном процессе обработку (включая sleep_msec)
186 virtual void callback() noexcept override;
187
188 virtual void askSensors( UniversalIO::UIOCommand cmd ) override;
189 virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
190 virtual void timerInfo( const uniset::TimerMessage* tm ) override;
191 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
192 virtual std::string getMonitInfo() const override;
193
194 void init( xmlNode* cnode );
195 bool flushBuffer();
196 bool reconnect();
197
198 std::shared_ptr<SMInterface> shm;
199
201 {
202 const std::string name;
203 const std::string tags;
204
205 ParamInfo( const std::string& _name, const std::string& _tags ):
206 name(_name), tags(_tags) {}
207 };
208
209 std::string tsdbMeasurement = { "sensors" }; // measurement name for InfluxDB
210 std::string tsdbProject; // project tag value (e.g. "theatre")
211 std::string tsdbTags; // additional tags: TAG=VAL TAG2=VAL2 ...
212 std::unordered_map<uniset::ObjectId, ParamInfo> tsdbParams;
213
214 timeout_t bufSyncTime = { 5000 };
215 size_t bufSize = { 500 };
216 size_t bufMaxSize = { 5000 }; // drop messages
217 bool timerIsOn = { false };
218 timeout_t reconnectTime = { 5000 };
219 std::string lastError;
220
221 // буфер mutex-ом можно не защищать
222 // т.к. к нему идёт обращение только из основного потока обработки
223 // (sensorInfo, timerInfo)
224 std::deque<std::string> buf;
225
226 // работа с OpenTSDB
227 std::shared_ptr<UTCPStream> tcp;
228 std::string host = { "localhost" };
229 int port = { 4242 };
230
231 private:
232
233 std::string prefix;
234 };
235 // --------------------------------------------------------------------------
236} // end of namespace uniset
237// -----------------------------------------------------------------------------
238#endif // _BackendOpenTSDB_H_
239// -----------------------------------------------------------------------------
Definition UObject_SK.h:30
Definition BackendOpenTSDB.h:150
virtual std::string getMonitInfo() const override
Definition BackendOpenTSDB.cc:442
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:185
virtual void callback() noexcept override
Definition BackendOpenTSDB.cc:219
static void help_print(int argc, const char *const *argv)
Definition BackendOpenTSDB.cc:148
Definition MessageType.h:127
Definition MessageType.h:171
Definition MessageType.h:214
Definition USingleProcess.h:28
Definition AccessConfig.h:30
long ObjectId
Definition UniSetTypes_i.idl:30
Definition BackendOpenTSDB.h:201