diff --git a/Dockerfile b/Dockerfile index 703c96c3..6ad0bfc7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,6 +32,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ libmailtools-perl \ libmouse-perl \ libnet-prometheus-perl \ + libplack-perl \ libreadonly-perl \ libreadonly-xs-perl \ libroman-perl \ diff --git a/bin/metrics_exporter.pl b/bin/metrics_exporter.pl new file mode 100644 index 00000000..3cbdffd6 --- /dev/null +++ b/bin/metrics_exporter.pl @@ -0,0 +1,30 @@ +use strict; +use warnings; + +use HTFeed::JobMetrics; +use Plack::Response; + +# Metrics exporter for prometheus statistics gathered via ingest. +# Usage: plackup -p 9090 ./bin/metrics_exporter.pl + +my $metrics = HTFeed::JobMetrics->get_instance(); + +my $app = sub { + my $env = shift; + + my $rendered = $metrics->pretty(); + + my $response = Plack::Response->new(); + $response->content_type('text/plain'); + + if ($rendered) { + $response->status(200); + $response->body($rendered); + } else { + $response->status(500); + $response->body("# metrics rendering failed"); + } + + return $response->finalize; + +}; diff --git a/docker-compose.yml b/docker-compose.yml index d294c715..b587bdb2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -76,6 +76,7 @@ services: - HTFEED_CONFIG=/usr/local/feed/etc/config_ingest_docker.yml - FEED_HOME=/usr/local/feed - VERSION=feed-development + - HTFEED_JOBMETRICS_DATA_DIR=/usr/local/feed/jobmetrics depends_on: mariadb: *healthy @@ -86,12 +87,27 @@ services: - ./volumes_to_test:/tmp/stage/toingest/test environment: - HTFEED_CONFIG=/usr/local/feed/etc/config_prevalidate.yml + - HTFEED_JOBMETRICS_DATA_DIR=/usr/local/feed/jobmetrics - FEED_HOME=/usr/local/feed - VERSION=feed-development command: bash -c "/bin/ls /tmp/stage/toingest/test/*.zip | xargs -n 1 basename | sed s/.zip// | perl -w /usr/local/feed/bin/validate_volume.pl -p simple -n test --no-clean" depends_on: mariadb: *healthy + prometheus-exporter: + build: . + volumes: + - .:/usr/local/feed + ports: + - "9090:9090" + environment: + - HTFEED_CONFIG=/usr/local/feed/etc/config_prevalidate.yml + - HTFEED_JOBMETRICS_DATA_DIR=/usr/local/feed/jobmetrics + - FEED_HOME=/usr/local/feed + - VERSION=feed-development + command: plackup -p 9090 ./bin/metrics_exporter.pl + + mariadb: image: ghcr.io/hathitrust/db-image:latest volumes: @@ -125,6 +141,7 @@ services: <<: *healthcheck-defaults test: [ "CMD", "wget", "--quiet", "--tries=1", "-O", "/dev/null", "pushgateway:9091/-/healthy" ] + rabbitmq: image: rabbitmq healthcheck: