File: influxdb_export_api.lua

package info (click to toggle)
ntopng 5.2.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 121,832 kB
  • sloc: javascript: 143,431; cpp: 71,175; ansic: 11,108; sh: 4,687; makefile: 911; python: 587; sql: 512; pascal: 234; perl: 118; ruby: 52; exp: 4
file content (81 lines) | stat: -rw-r--r-- 2,248 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--
-- (C) 2019-22 - ntop.org
--

local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/timeseries/?.lua;" .. package.path

local ts_utils_core = require("ts_utils_core")

local influxdb_export_api = {}

-- ##############################################

function influxdb_export_api.isInfluxdbEnabled()
   return ts_utils_core.getDriverName() == "influxdb"
end

-- ##############################################

function influxdb_export_api.isInfluxdbChecksEnabled()
   return true -- TODO: Check if influxdb checks are enabled
end

-- ##############################################

function influxdb_export_api.getExportStats()
   local points_exported
   local points_dropped
   local exports
   local ifnames = interface.getIfNames()

   local influxdb = ts_utils_core.getQueryDriver()

   points_exported = influxdb:get_exported_points()
   exports = influxdb:get_exports()

   local res = {
      health = influxdb:get_health(),
      points_exported = points_exported,
      exports = exports,
   }

   return(res)
end

-- ##############################################

function influxdb_export_api.measureRtt(when, influxdb)
   local start_ms = ntop.gettimemsec()
   local res = influxdb:getInfluxdbVersion()
   local ifid = getSystemInterfaceId()

   if res ~= nil then
      local end_ms = ntop.gettimemsec()

      ts_utils_core.append("influxdb:rtt", { ifid = ifid, millis_rtt = ((end_ms-start_ms)*1000) }, when)
   end
end

-- ##############################################

function influxdb_export_api.exportStats(when, influxdb)
   local stats = influxdb_export_api.getExportStats()
   local ifid = getSystemInterfaceId()

   ts_utils_core.append("influxdb:exported_points", { ifid = ifid, points = stats.points_exported }, when)
   ts_utils_core.append("influxdb:exports", { ifid = ifid, num_exports = stats.exports }, when)
end

-- ##############################################

function influxdb_export_api.exportStorageSize(when, influxdb)
   local disk_bytes = influxdb:getDiskUsage()
   local ifid = getSystemInterfaceId()

   if(disk_bytes ~= nil) then
      ts_utils_core.append("influxdb:storage_size", { ifid = ifid, disk_bytes = disk_bytes }, when)
   end
end

return influxdb_export_api