Class: Vtk::Analytics
- Inherits:
-
Object
- Object
- Vtk::Analytics
- Defined in:
- lib/vtk/analytics.rb
Overview
Provides command analytics to VTK team
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #emit_point ⇒ Object
-
#initialize(name:, args: nil, hostname: nil) ⇒ Analytics
constructor
A new instance of Analytics.
- #internet? ⇒ Boolean
- #log ⇒ Object
- #point ⇒ Object
Constructor Details
#initialize(name:, args: nil, hostname: nil) ⇒ Analytics
Returns a new instance of Analytics.
13 14 15 16 17 |
# File 'lib/vtk/analytics.rb', line 13 def initialize(name:, args: nil, hostname: nil) @name = name @args = args || ARGV.join('_') @hostname = hostname || `hostname -f`.chomp end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
11 12 13 |
# File 'lib/vtk/analytics.rb', line 11 def args @args end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
11 12 13 |
# File 'lib/vtk/analytics.rb', line 11 def hostname @hostname end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/vtk/analytics.rb', line 11 def name @name end |
Instance Method Details
#emit_point ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/vtk/analytics.rb', line 31 def emit_point uri = URI.parse 'https://dev.va.gov/_vfs/vtk-analytics/record' Net::HTTP.start uri.host, uri.port, use_ssl: uri.scheme == 'https' do |http| request = Net::HTTP::Post.new uri, 'Content-Type' => 'application/json' request.body = { series: [point] }.to_json http.request request end end |
#internet? ⇒ Boolean
51 52 53 54 55 |
# File 'lib/vtk/analytics.rb', line 51 def internet? true if URI.open 'http://www.google.com/' rescue SocketError false end |
#log ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vtk/analytics.rb', line 19 def log return if ENV['CI'] || ENV['TEST'] || ENV['VTK_DISABLE_ANALYTICS'] Process.fork do exit unless internet? emit_point rescue StandardError false # Silently error end end |
#point ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/vtk/analytics.rb', line 40 def point { metric: 'vtk.command_executed', type: 'count', interval: 1, tags: ["name:#{name}", "args:#{args}"], host: hostname, points: [[Time.now.utc.to_i, '1']] } end |