logo

munin-plugins

Collection of my custom munin pluginsgit clone https://hacktivis.me/git/munin-plugins.git
commit: cbdd9591690dbb6c96c795e8fcde17c84d2dab02
parent f8703718e7b7c128e6590cca3cc9eb3cd0e8bca5
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  4 Nov 2024 21:17:00 +0100

pleroma_{healthcheck,oban}: add plugins I wrote back in 2022

Diffstat:

Apleroma_healthcheck55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apleroma_oban17+++++++++++++++++
2 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/pleroma_healthcheck b/pleroma_healthcheck @@ -0,0 +1,55 @@ +#!/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; +} diff --git a/pleroma_oban b/pleroma_oban @@ -0,0 +1,17 @@ +#!/bin/sh +# Copyright © 2022 Haelwenn (lanodan) Monnier +# SPDX-License-Identifier: MIT + +DB="pleroma_prod2" + +if [[ "$@" = *config* ]]; then + echo 'graph_title Pleroma Oban status' + echo 'graph_category pleroma' + + for state in $(psql -U pleroma "${DB}" --csv -c 'SELECT state FROM oban_jobs GROUP BY state;' | sed -n '2,$p' | sort); do + echo "state_${state}.label ${state} jobs" + echo "state_${state}.min 0" + done +else + psql -U pleroma "${DB}" --csv -c 'SELECT count(id), state FROM oban_jobs GROUP BY state;' | sed -n -E -e 's;^([0-9]*),(\w*)$;state_\2.value \1;' -e '2,$p' | sort +fi