Class: Fluent::Plugin::JfrogMetricsInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_jfrog_metrics.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

‘configure` is called before `start`. ’conf’ is a ‘Hash` that includes the configuration parameters. If the configuration is invalid, raise `Fluent::ConfigError`.

Raises:

  • (Fluent::ConfigError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fluent/plugin/in_jfrog_metrics.rb', line 50

def configure(conf)
  super
  raise Fluent::ConfigError, 'Must define the tag for metrics data.' if @tag == ''

  raise Fluent::ConfigError, 'Must define the jpd_url to scrape metrics.' if @jpd_url == ''

  raise Fluent::ConfigError, 'Must define the username for authentication.' if @username == ''

  raise Fluent::ConfigError, 'Must define the apikey or token for authentication.' if @token == '' &&  @apikey == ''

  raise Fluent::ConfigError, 'Must define the metric_prefix to use for getting the metrics.' if @metric_prefix == ''

  raise Fluent::ConfigError, 'Must define the vendor to use for getting the metrics.' if @target_platform == ''
end

#do_executeObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fluent/plugin/in_jfrog_metrics.rb', line 88

def do_execute
  puts('Metrics collection started')
  metrics_helper = MetricsHelper.new(@metric_prefix, @jpd_url, @username, @apikey, @token, @common_jpd, @verify_ssl)
  platform_metrics = metrics_helper.get_metrics

  additional_metrics = metrics_helper.get_additional_metrics
  if !additional_metrics.nil? && additional_metrics != ''
    platform_metrics += additional_metrics.to_s
  end
  if @target_platform == 'SPLUNK'
    parser = SplunkMetricsParser.new(@metric_prefix, router, @tag)
  elsif @target_platform == 'NEWRELIC'
    parser = NewRelicMetricsParser.new(@metric_prefix, router, @tag)
  elsif @target_platform == 'DATADOG'
    parser = DatadogMetricsParser.new(@metric_prefix, router, @tag)
  else
    raise 'Parser Type is not valid.Should be SPLUNK or NEWRELIC or DATADOG'
  end
  parser.emit_parsed_metrics(platform_metrics)
  puts('Metrics collection finished')
end

#runObject



78
79
80
81
82
83
84
85
86
# File 'lib/fluent/plugin/in_jfrog_metrics.rb', line 78

def run
  puts('Preparing metrics collection, creating timer task')
  timer_task = Concurrent::TimerTask.new(execution_interval: @execution_interval, timeout_interval: @timeout_interval, run_now: true) do
    puts('Timer task execution')
    do_execute
  end
  timer_task.execute
  sleep 100
end

#shutdownObject



72
73
74
75
76
# File 'lib/fluent/plugin/in_jfrog_metrics.rb', line 72

def shutdown
  @running = false
  @thread.join
  super
end

#startObject

‘start` is called when starting and after `configure` is successfully completed.



66
67
68
69
70
# File 'lib/fluent/plugin/in_jfrog_metrics.rb', line 66

def start
  super
  @running = true
  @thread = Thread.new(&method(:run))
end