/src/ntopng/src/RRDTimeseriesExporter.cpp
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * (C) 2018-26 - ntop.org |
4 | | * |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software Foundation, |
18 | | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | | * |
20 | | */ |
21 | | |
22 | | #include "ntop_includes.h" |
23 | | |
24 | | /* ******************************************************* */ |
25 | | |
26 | | RRDTimeseriesExporter::RRDTimeseriesExporter(NetworkInterface* _if) |
27 | 0 | : TimeseriesExporter(_if) { |
28 | 0 | if (trace_new_delete) |
29 | 0 | ntop->getTrace()->traceEvent(TRACE_NORMAL, "[new] %s", __FILE__); |
30 | 0 | ts_queue = new (std::nothrow) StringFifoQueue(MAX_RRD_QUEUE_LEN); |
31 | 0 | } |
32 | | |
33 | | /* ******************************************************* */ |
34 | | |
35 | 0 | RRDTimeseriesExporter::~RRDTimeseriesExporter() { delete ts_queue; } |
36 | | |
37 | | /* ******************************************************* */ |
38 | | |
39 | 0 | bool RRDTimeseriesExporter::enqueueData(lua_State* vm, bool do_lock) { |
40 | 0 | char data[LINE_PROTOCOL_MAX_LINE]; |
41 | 0 | bool rv = false; |
42 | |
|
43 | 0 | if (line_protocol_write_line(vm, data, sizeof(data), |
44 | 0 | NULL /* No need to escape here */) < 0) |
45 | 0 | return false; |
46 | | |
47 | 0 | rv = ts_queue->enqueue(data); |
48 | 0 | if(!rv) qdrops++; |
49 | |
|
50 | | #ifdef DEBUG_QUEUE |
51 | | if(rv == false) |
52 | | ntop->getTrace()->traceEvent(TRACE_WARNING, "RRD queue too long: %u [%.1f %%]", |
53 | | ts_queue->getLength(), ts_queue->fillPct()); |
54 | | #endif |
55 | | |
56 | 0 | return rv; |
57 | 0 | } |
58 | | |
59 | | /* ******************************************************* */ |
60 | | |
61 | 0 | char* RRDTimeseriesExporter::dequeueData() { |
62 | 0 | if (ts_queue->empty()) |
63 | 0 | return (NULL); |
64 | 0 | else |
65 | 0 | return (ts_queue->dequeue()); |
66 | 0 | } |
67 | | |
68 | | /* ******************************************************* */ |
69 | | |
70 | 0 | u_int64_t RRDTimeseriesExporter::queueLength() const { |
71 | 0 | return ts_queue->getLength(); |
72 | 0 | } |
73 | | |
74 | | /* ******************************************************* */ |
75 | | |
76 | 0 | void RRDTimeseriesExporter::flush() {} |