logo

munin-plugins

Collection of my custom munin pluginsgit clone https://hacktivis.me/git/munin-plugins.git

pleroma_healthcheck (1828B)


  1. #!/usr/bin/env perl
  2. # Copyright © 2022 Haelwenn (lanodan) Monnier
  3. # SPDX-License-Identifier: MIT
  4. use strict;
  5. use utf8;
  6. use warnings;
  7. use LWP::Protocol::https;
  8. use LWP::UserAgent;
  9. use JSON::MaybeXS;
  10. #use Data::Dumper;
  11. my $instance_url = exists $ENV{'instance_url'} ? $ENV{'instance_url'} : "http://localhost/";
  12. my $UA = exists $ENV{'ua'} ? $ENV{'ua'} : 'PleromaHealthchecker <contact+pleroma-healthchecker@hacktivis.me>';
  13. my $ua = LWP::UserAgent->new(timeout => 30);
  14. $ua->agent($UA);
  15. my $munin_config = defined($ARGV[0]) ? ( $ARGV[0] eq "config" ) : 0;
  16. my $response = $ua->request(HTTP::Request->new('GET',"$instance_url/api/pleroma/healthcheck"));
  17. if ($response->is_success) {
  18. my $response_json = decode_json($response->content);
  19. if ($munin_config) {
  20. print "graph_title Pleroma Healthcheck / status\n";
  21. print "graph_category pleroma\n";
  22. # print "memory_used.label memory used\n";
  23. # print "memory_used.min 0\n";
  24. } else {
  25. # print "memory_used.value ", $response_json->{"memory_used"}, "\n";
  26. }
  27. my %queues = %{$response_json->{'job_queue_stats'}->{'queues'}};
  28. foreach my $queue (sort {lc $a cmp lc $b} keys %queues) {
  29. if ($munin_config) {
  30. print "job_queue_", $queue, "_success.label job queue ", $queue, " success%\n";
  31. print "job_queue_", $queue, "_success.min 0\n";
  32. print "job_queue_", $queue, "_success.max 100\n";
  33. } else {
  34. print "job_queue_", $queue, "_success.value ", ($queues{$queue}->{'success'}/$queues{$queue}->{'processed_jobs'})*100, "\n";
  35. }
  36. #print "job_queue_", $k, "_failed.label job queue ", $k, " failure%\n";
  37. #print "job_queue_", $k, "_failed.min 0\n";
  38. #print "job_queue_", $k, "_failed.max 100\n";
  39. #print "job_queue_", $k, "_failed.value ", ($v->{'failure'}/$v->{'processed_jobs'})*100, "\n";
  40. }
  41. } else {
  42. print "Error: ", $response->status_line, "\n";
  43. exit 1;
  44. }