Class: Fluent::Plugin::PrometheusInput::MonitorServletAll
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Fluent::Plugin::PrometheusInput::MonitorServletAll
- Defined in:
- lib/fluent/plugin/in_prometheus.rb
Instance Method Summary collapse
- #do_GET(req, res) ⇒ Object
-
#initialize(server, prometheus) ⇒ MonitorServletAll
constructor
A new instance of MonitorServletAll.
Constructor Details
#initialize(server, prometheus) ⇒ MonitorServletAll
Returns a new instance of MonitorServletAll.
135 136 137 |
# File 'lib/fluent/plugin/in_prometheus.rb', line 135 def initialize(server, prometheus) @prometheus = prometheus end |
Instance Method Details
#do_GET(req, res) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/fluent/plugin/in_prometheus.rb', line 139 def do_GET(req, res) res.status = 200 res['Content-Type'] = ::Prometheus::Client::Formats::Text::CONTENT_TYPE full_result = PromMetricsAggregator.new fluent_server_ip = @prometheus.bind == '0.0.0.0' ? '127.0.0.1' : @prometheus.bind current_worker = 0 while current_worker < @prometheus.num_workers Net::HTTP.start(fluent_server_ip, @prometheus.base_port + current_worker) do |http| req = Net::HTTP::Get.new(@prometheus.metrics_path) result = http.request(req) if result.is_a?(Net::HTTPSuccess) full_result.add_metrics(result.body) end end current_worker += 1 end res.body = full_result.get_metrics rescue res.status = 500 res['Content-Type'] = 'text/plain' res.body = $!.to_s end |