From 392ac363129279991be3f494a493c0b6d55a6ebb Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Sun, 9 May 2021 14:39:21 +0200 Subject: [PATCH] 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. --- .gitignore | 5 ++ config.ru | 8 ++- config.yml => config.yml.example | 3 +- dnsbl_exporter.rb | 88 ++++++++++++++++++++------------ 4 files changed, 68 insertions(+), 36 deletions(-) create mode 100644 .gitignore rename config.yml => config.yml.example (96%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6e8bbf4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.sw[pomnqrst] +*.gem + +config.yml +Gemfile.lock diff --git a/config.ru b/config.ru index 13d7500..1b244c3 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,9 @@ +# vim: set noet sw=2 ts=2 sts=2: require 'rack' -require './dnsbl_exporter' +require_relative 'dnsbl_exporter' +require 'yaml' +DnsblCollector.load_config './config.yml' run lambda {|env| begin @@ -16,7 +19,8 @@ run lambda {|env| end collector.collect target [200, {"Content-Type" => "text/plain"}, [ - Prometheus::Client::Formats::Text.marshal( collector.prometheus) + 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"]] diff --git a/config.yml b/config.yml.example similarity index 96% rename from config.yml rename to config.yml.example index 6be99f2..0c7b31a 100644 --- a/config.yml +++ b/config.yml.example @@ -1,7 +1,7 @@ # vim: set et sw=2 ts=2 sts=2: --- resolver: - nameservers: 8.8.8.8 + nameservers: '::1' blacklists: - all.s5h.net - b.barracudacentral.org @@ -17,7 +17,6 @@ blacklists: - dnsbl-1.uceprotect.net - dnsbl-2.uceprotect.net - dnsbl-3.uceprotect.net -- dnsbl.anticaptcha.net - dnsbl.dronebl.org - dnsbl.inps.de - dnsbl.sorbs.net diff --git a/dnsbl_exporter.rb b/dnsbl_exporter.rb index fba6bf5..31a7cf8 100644 --- a/dnsbl_exporter.rb +++ b/dnsbl_exporter.rb @@ -1,52 +1,76 @@ +# vim: set noet sw=2 ts=2 sts=2: require 'prometheus/client' require 'prometheus/client/formats/text' require 'net/dns' -require 'yaml' +require 'ostruct' -class DnsblCollector - attr_reader :lists, :prometheus, :configfile, :resolver, :metrics +class DnsblCollector + class <