FEATURE: Expose metric for missing s3 uploads count.

FEATURE: Expose metric for missing s3 uploads count.

diff --git a/lib/internal_metric/custom.rb b/lib/internal_metric/custom.rb
index 19670af..56081ef 100644
--- a/lib/internal_metric/custom.rb
+++ b/lib/internal_metric/custom.rb
@@ -1,5 +1,14 @@
 module DiscoursePrometheus::InternalMetric
   class Custom < Base
     attribute :name , :labels, :description, :value, :type
+
+    def self.create_gauge_hash(name, description, value)
+      metric = DiscoursePrometheus::InternalMetric::Custom.new
+      metric.type = "Gauge"
+      metric.name = name
+      metric.description = description
+      metric.value = value
+      metric.to_h
+    end
   end
 end
diff --git a/plugin.rb b/plugin.rb
index a0a3bf9..5c49343 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -76,13 +76,21 @@ after_initialize do
     metric.duration = stat.duration_ms * 0.001
     $prometheus_client.send_json metric.to_h
 
-    if stat.name == "Jobs::EnsurePostUploadsExistence"
-      metric = DiscoursePrometheus::InternalMetric::Custom.new
-      metric.type = "Gauge"
-      metric.name = "missing_post_uploads"
-      metric.description = "Number of missing uploads in all posts"
-      metric.value = PostCustomField.where(name: Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS).count
-      $prometheus_client.send_json metric.to_h
+    case stat.name
+    when "Jobs::EnsurePostUploadsExistence"
+      count = PostCustomField.where(name: Jobs::EnsurePostUploadsExistence::MISSING_UPLOADS).count
+      $prometheus_client.send_json DiscoursePrometheus::InternalMetric::Custom.create_gauge_hash(
+        "missing_post_uploads",
+        "Number of missing uploads in all posts",
+        count
+      )
+    when "Jobs::EnsureS3UploadsExistence"
+      count = ($redis.get("missing_s3_uploads") || "-1").to_i
+      $prometheus_client.send_json DiscoursePrometheus::InternalMetric::Custom.create_gauge_hash(
+        "missing_s3_uploads",
+        "Number of missing uploads in S3",
+        count
+      )
     end
   end

GitHub sha: 5fed0e9b

Add rspect test case for 'create_gauge_hash' method