Class: Ring::SQA::InfluxDBWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/ring/sqa/influxdb.rb

Constant Summary collapse

ROOT =
"nlnog.ring_sqa.#{CFG.afi}"

Instance Method Summary collapse

Instance Method Details

#add(records) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ring/sqa/influxdb.rb', line 8

def add(records)
  host   = @hostname.split(".").first
  node   = @nodes.all
  data   = []

  records.each do |record|
    nodename = nodecc = node[record.peer][:name].split(".").first
    nodecc = node[record.peer][:cc].downcase

    point = InfluxDB2::Point.new(name: 'ring-sqa_measurements')
                            .add_tag('afi', CFG.afi)
                            .add_tag('dst_node', nodename)
                            .add_tag('dst_cc', nodecc)
                            .add_tag('src_node', host)
                            .add_tag('dst_lat', node[record.peer][:geo].split(",")[0])
                            .add_tag('dst_lon', node[record.peer][:geo].split(",")[1])
                            .add_field('latency', record.latency)
                            .add_field('state', record.result == 'no response' ? 0 : 1)

    @write_api.write(data: point)
  rescue => e
    Log.error "Failed to write metrics to InfluxDB: #{e.message}"
  end
end