Class: Zabbix::Sender::NanosecondItemData

Inherits:
ItemData
  • Object
show all
Defined in:
lib/zabbix_sender_api/api.rb

Overview

NanosecondItemData instances hold the k-v pair of a value and its timestamp along with the hostname to which the data belongs. This differs from ItemData in that it renders nanosecond fields as well.

Instance Attribute Summary

Attributes inherited from ItemData

#hostname, #key, #timestamp, #value

Instance Method Summary collapse

Methods inherited from ItemData

#initialize

Constructor Details

This class inherits a constructor from Zabbix::Sender::ItemData

Instance Method Details

#to_senderlineObject

Render the ItemData instance as a line of text that can be piped into zabbix_sender - nanosecond form



304
305
306
307
308
309
310
# File 'lib/zabbix_sender_api/api.rb', line 304

def to_senderline
  if @timestamp.to_i == 0
    puts %Q("#{@hostname}" #{@key} #{@timestamp.to_i} #{@value}\n)
    abort("Attempt was made to render a timestamp of zero.  You DO NOT want this - it can kill db performance. Fix it.")
  end
  return %Q("#{@hostname}" #{@key} #{@timestamp.to_i} #{@timestamp.nsec} #{@value}\n)
end

#to_senderstructObject

Render the ItemData instance as an object suitable for conversion to json, for socket transmission - nanosecond form



313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/zabbix_sender_api/api.rb', line 313

def to_senderstruct
  if @timestamp.to_i == 0
    puts %Q("#{@hostname}" #{@key} #{@timestamp.to_i} #{@value}\n)
    abort("Attempt was made to render a timestamp of zero.  You DO NOT want this - it can kill db performance. Fix it.")
  else
    return item = {
      host: @hostname,
      key: @key,
      value: @value,
      clock: @timestamp.to_i,
	ns: @timestamp.nsec
    }
  end
end