Class: Fluent::Plugin::PrometheusPullInput

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

Overview

input / source pull prometheus http endpoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#labeled_urlsObject (readonly)

Returns the value of attribute labeled_urls.



32
33
34
# File 'lib/fluent/plugin/in_prometheus_pull.rb', line 32

def labeled_urls
  @labeled_urls
end

Instance Method Details

#configure(conf) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/fluent/plugin/in_prometheus_pull.rb', line 75

def configure(conf)
  compat_parameters_convert(conf, :parser)

  parser_config = conf.elements('parse').first
  # raise Fluent::ConfigError, '<parse> section is required.' unless parser_config
  unless parser_config
    parser_config ||= Fluent::Config::Element.new('parse', '', { '@type' => 'prometheus_text' }, [])
    conf.elements.append(parser_config)
  end

  super

  @labeled_urls = urls.map { |url| parse_url(url) }

  @parser = parser_create(conf: parser_config)
end

#pullObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/fluent/plugin/in_prometheus_pull.rb', line 98

def pull
  labeled_urls.each do |url|
    pull_time = Fluent::EventTime.now
    raw_metrics = fetch(url.url)
    parser.parse(raw_metrics) do |time, record|
      begin
        time ||= pull_time
        record[event_url_key] = url.url if event_url_key
        record[event_url_label_key] = url.label if event_url_label_key && url.label

        router.emit(tag, time, record)
      rescue StandardError => e
        error("error #{e}, while emitting #{record}")
      end
    end
  end
end

#startObject



92
93
94
95
96
# File 'lib/fluent/plugin/in_prometheus_pull.rb', line 92

def start
  super

  timer_execute(:in_prometheus_pull_timer, @interval, &method(:pull))
end