dnsbl_exporter/config.ru
Denis Knauf 392ac36312 Splitting Registry for action and process-statistics and clean up repositry.
config.yml was only an example, so name it as config.yml.example and
ignore any config.yml, that checkout could be used as local
project-directory without conflicts.

DnsblCollector will have singleton-behaviour like process configs and an
own Registry.  Config was loaded every request, yet.
There was one Registry, which was reused for every request.  Now every
request will use his own Registry.

Requests will get the content of both Registries.
2021-05-09 14:39:21 +02:00

33 lines
983 B
Ruby

# vim: set noet sw=2 ts=2 sts=2:
require 'rack'
require_relative 'dnsbl_exporter'
require 'yaml'
DnsblCollector.load_config './config.yml'
run lambda {|env|
begin
req = Rack::Request.new env
case req.path
when '/metrics'
collector = DnsblCollector.new
target =
begin
target = IPAddr.new req.params['target']
rescue IPAddr::AddressFamilyError
return [400, {"Content-Type" => "text/plain"}, ["Valid target-IP-Address expected.\n"]]
end
collector.collect target
[200, {"Content-Type" => "text/plain"}, [
Prometheus::Client::Formats::Text.marshal( collector.registry),
Prometheus::Client::Formats::Text.marshal( DnsblCollector.registry),
]]
else
[404, {"Content-Type" => "text/plain"}, ["Not found.\nYou want to try /metrics?\n"]]
end
rescue
STDERR.puts "#$! (#{$!.class})", $!.backtrace
[500, {"Content-Type" => "text/plain"}, ["Server-error.\n"]]
end
}