From 0b4fbc9d712ebd1a6b2e83cab8cce00d63fd1048 Mon Sep 17 00:00:00 2001
From: Dominik Hebeler <dominik@suma-ev.de>
Date: Fri, 28 Aug 2020 10:32:21 +0200
Subject: [PATCH] added prometheus exporter to count successfull
 humanverifications

---
 app/Http/Middleware/HumanVerification.php |  7 ++++++-
 app/PrometheusExporter.php                | 20 +++++++++++++++-----
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/app/Http/Middleware/HumanVerification.php b/app/Http/Middleware/HumanVerification.php
index 1e5f4f73d..730a25c88 100644
--- a/app/Http/Middleware/HumanVerification.php
+++ b/app/Http/Middleware/HumanVerification.php
@@ -139,7 +139,12 @@ class HumanVerification
                 } else {
                     $user["expiration"] = now()->addHours(72);
                 }
-                $this->setUser($prefix, $user);
+                try {
+                    $this->setUser($prefix, $user);
+                    \App\PrometheusExporter::HumanVerificationSuccessfull();
+                } catch (\Exception $e) {
+                    Log::error($e->getMessage());
+                }
             }
         }
 
diff --git a/app/PrometheusExporter.php b/app/PrometheusExporter.php
index 1332e1cf2..8d55c0344 100644
--- a/app/PrometheusExporter.php
+++ b/app/PrometheusExporter.php
@@ -2,24 +2,34 @@
 
 namespace App;
 
-class PrometheusExporter {
+class PrometheusExporter
+{
 
-    public static function CaptchaShown() {
+    public static function CaptchaShown()
+    {
         $registry = \Prometheus\CollectorRegistry::getDefault();
         $counter = $registry->getOrRegisterCounter('metager', 'captcha_shown', 'counts how often the captcha was shown', []);
         $counter->inc();
     }
 
-    public static function CaptchaCorrect() {
+    public static function CaptchaCorrect()
+    {
         $registry = \Prometheus\CollectorRegistry::getDefault();
         $counter = $registry->getOrRegisterCounter('metager', 'captcha_correct', 'counts how often the captcha was solved correctly', []);
         $counter->inc();
     }
 
-    public static function CaptchaAnswered() {
+    public static function CaptchaAnswered()
+    {
         $registry = \Prometheus\CollectorRegistry::getDefault();
         $counter = $registry->getOrRegisterCounter('metager', 'captcha_answered', 'counts how often the captcha was answered', []);
         $counter->inc();
     }
 
-}
\ No newline at end of file
+    public static function HumanVerificationSuccessfull()
+    {
+        $registry = \Prometheus\CollectorRegistry::getDefault();
+        $counter = $registry->getOrRegisterCounter('metager', 'humanverification', 'counts how often humanverification middleware was successfull', []);
+        $counter->inc();
+    }
+}
-- 
GitLab