pleroma_healthcheck (1828B)
- #!/usr/bin/env perl
- # Copyright © 2022 Haelwenn (lanodan) Monnier
- # SPDX-License-Identifier: MIT
- use strict;
- use utf8;
- use warnings;
- use LWP::Protocol::https;
- use LWP::UserAgent;
- use JSON::MaybeXS;
- #use Data::Dumper;
- my $instance_url = exists $ENV{'instance_url'} ? $ENV{'instance_url'} : "http://localhost/";
- my $UA = exists $ENV{'ua'} ? $ENV{'ua'} : 'PleromaHealthchecker <contact+pleroma-healthchecker@hacktivis.me>';
- my $ua = LWP::UserAgent->new(timeout => 30);
- $ua->agent($UA);
- my $munin_config = defined($ARGV[0]) ? ( $ARGV[0] eq "config" ) : 0;
- my $response = $ua->request(HTTP::Request->new('GET',"$instance_url/api/pleroma/healthcheck"));
- if ($response->is_success) {
- my $response_json = decode_json($response->content);
- if ($munin_config) {
- print "graph_title Pleroma Healthcheck / status\n";
- print "graph_category pleroma\n";
- # print "memory_used.label memory used\n";
- # print "memory_used.min 0\n";
- } else {
- # print "memory_used.value ", $response_json->{"memory_used"}, "\n";
- }
- my %queues = %{$response_json->{'job_queue_stats'}->{'queues'}};
- foreach my $queue (sort {lc $a cmp lc $b} keys %queues) {
- if ($munin_config) {
- print "job_queue_", $queue, "_success.label job queue ", $queue, " success%\n";
- print "job_queue_", $queue, "_success.min 0\n";
- print "job_queue_", $queue, "_success.max 100\n";
- } else {
- print "job_queue_", $queue, "_success.value ", ($queues{$queue}->{'success'}/$queues{$queue}->{'processed_jobs'})*100, "\n";
- }
- #print "job_queue_", $k, "_failed.label job queue ", $k, " failure%\n";
- #print "job_queue_", $k, "_failed.min 0\n";
- #print "job_queue_", $k, "_failed.max 100\n";
- #print "job_queue_", $k, "_failed.value ", ($v->{'failure'}/$v->{'processed_jobs'})*100, "\n";
- }
- } else {
- print "Error: ", $response->status_line, "\n";
- exit 1;
- }