UniSet 2.41.2
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 // -----------------------------------------------------------------------------
102 // -----------------------------------------------------------------------------
104 class BackendOpenTSDB:
105 private USingleProcess,
106 public UObject_SK
107 {
108 public:
109 BackendOpenTSDB( uniset::ObjectId objId, xmlNode* cnode, uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
110 const std::string& prefix = "opentsdb" );
111 virtual ~BackendOpenTSDB();
112
114 static std::shared_ptr<BackendOpenTSDB> init_opendtsdb( int argc, const char* const* argv,
115 uniset::ObjectId shmID, const std::shared_ptr<SharedMemory>& ic = nullptr,
116 const std::string& prefix = "opentsdb" );
117
119 static void help_print( int argc, const char* const* argv );
120
121 inline std::shared_ptr<LogAgregator> getLogAggregator()
122 {
123 return loga;
124 }
125 inline std::shared_ptr<DebugStream> log()
126 {
127 return mylog;
128 }
129
130 enum Timers
131 {
132 tmFlushBuffer,
133 tmReconnect,
134 tmLastNumberOfTimer
135 };
136
137 protected:
138 BackendOpenTSDB();
139
140 // переопределяем callback, чтобы оптимизировать
141 // обработку большого количества сообщений
142 // и убрать не нужную в данном процессе обработку (включая sleep_msec)
143 virtual void callback() noexcept override;
144
145 virtual void askSensors( UniversalIO::UIOCommand cmd ) override;
146 virtual void sensorInfo( const uniset::SensorMessage* sm ) override;
147 virtual void timerInfo( const uniset::TimerMessage* tm ) override;
148 virtual void sysCommand( const uniset::SystemMessage* sm ) override;
149 virtual std::string getMonitInfo() const override;
150
151 void init( xmlNode* cnode );
152 bool flushBuffer();
153 bool reconnect();
154
155 std::shared_ptr<SMInterface> shm;
156
157 struct ParamInfo
158 {
159 const std::string name;
160 const std::string tags;
161
162 ParamInfo( const std::string& _name, const std::string& _tags ):
163 name(_name), tags(_tags) {}
164 };
165
166 std::string tsdbPrefix;
167 std::string tsdbTags; // теги в виде строки TAG=VAL TAG2=VAL2 ...
168 std::unordered_map<uniset::ObjectId, ParamInfo> tsdbParams;
169
170 timeout_t bufSyncTime = { 5000 };
171 size_t bufSize = { 500 };
172 size_t bufMaxSize = { 5000 }; // drop messages
173 bool timerIsOn = { false };
174 timeout_t reconnectTime = { 5000 };
175 std::string lastError;
176
177 // буфер mutex-ом можно не защищать
178 // т.к. к нему идёт обращение только из основного потока обработки
179 // (sensorInfo, timerInfo)
180 std::deque<std::string> buf;
181
182 // работа с OpenTSDB
183 std::shared_ptr<UTCPStream> tcp;
184 std::string host = { "localhost" };
185 int port = { 4242 };
186
187 private:
188
189 std::string prefix;
190 };
191 // --------------------------------------------------------------------------
192} // end of namespace uniset
193// -----------------------------------------------------------------------------
194#endif // _BackendOpenTSDB_H_
195// -----------------------------------------------------------------------------
virtual std::string getMonitInfo() const override
Определения BackendOpenTSDB.cc:433
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")
Определения BackendOpenTSDB.cc:182
virtual void callback() noexcept override
Определения BackendOpenTSDB.cc:216
static void help_print(int argc, const char *const *argv)
Определения BackendOpenTSDB.cc:146
Определения MessageType.h:127
Определения MessageType.h:171
Определения MessageType.h:214
Определения Calibration.h:27
long ObjectId
Определения UniSetTypes_i.idl:30