prometheus-ghc-stats (empty) → 0.0.0.0
raw patch · 4 files changed · hide whitespace changes · browse prometheus-ghc-stats-0.0.0.0
+117/−0 lines, 4 filesdep +basedep +containersdep +prometheussetup-changed
Dependencies added: base, containers, prometheus
Files
- CHANGELOG.md +1/−0
- Setup.hs +2/−0
- prometheus-ghc-stats.cabal +35/−0
- src/System/Metrics/Prometheus/GHC/Stats.hs +79/−0
+ CHANGELOG.md view
@@ -0,0 +1,1 @@+# Changelog
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ prometheus-ghc-stats.cabal view
@@ -0,0 +1,35 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.38.3.+--+-- see: https://github.com/sol/hpack++name: prometheus-ghc-stats+version: 0.0.0.0+description: Prometheus metrics for GHC Stats+homepage: https://github.com/NorfairKing/prometheus-ghc-stats#readme+bug-reports: https://github.com/NorfairKing/prometheus-ghc-stats/issues+author: Tom Sydney Kerckhove+maintainer: syd@cs-syd.eu+copyright: Copyright (c) 2025 Tom Sydney Kerckhove+license: MIT+build-type: Simple+extra-source-files:+ CHANGELOG.md++source-repository head+ type: git+ location: https://github.com/NorfairKing/prometheus-ghc-stats++library+ exposed-modules:+ System.Metrics.Prometheus.GHC.Stats+ other-modules:+ Paths_prometheus_ghc_stats+ hs-source-dirs:+ src+ build-depends:+ base >=4.7 && <5+ , containers+ , prometheus+ default-language: Haskell2010
+ src/System/Metrics/Prometheus/GHC/Stats.hs view
@@ -0,0 +1,79 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}++module System.Metrics.Prometheus.GHC.Stats where++import qualified Data.Map.Strict as Map+import Data.Maybe+import GHC.Stats+import qualified System.Metrics.Prometheus.Metric as Prometheus (MetricSample (..))+import qualified System.Metrics.Prometheus.Metric.Counter as Prometheus (CounterSample (..))+import qualified System.Metrics.Prometheus.Metric.Gauge as Prometheus (GaugeSample (..))+import qualified System.Metrics.Prometheus.MetricId as Prometheus (Labels, MetricId (..))+import qualified System.Metrics.Prometheus.Registry as Prometheus (RegistrySample (..))++sampleGhcStats :: Prometheus.Labels -> IO Prometheus.RegistrySample+sampleGhcStats labels = do+ enabled <- getRTSStatsEnabled+ if enabled+ then do+ RTSStats {..} <- getRTSStats+ pure $ pureRtsStatsToSamples labels RTSStats {..}+ else pure $ Prometheus.RegistrySample Map.empty++pureRtsStatsToSamples :: Prometheus.Labels -> RTSStats -> Prometheus.RegistrySample+pureRtsStatsToSamples labels RTSStats {..} =+ let GCDetails {..} = gc+ in Prometheus.RegistrySample $+ Map.fromList $+ catMaybes+ [ mkTup "ghc_gcs" (Prometheus.CounterMetricSample . Prometheus.CounterSample) gcs,+ mkTup "ghc_major_gcs" (Prometheus.CounterMetricSample . Prometheus.CounterSample) major_gcs,+ mkTup "ghc_allocated_bytes" (Prometheus.CounterMetricSample . Prometheus.CounterSample) allocated_bytes,+ mkTup "ghc_max_live_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) max_live_bytes,+ mkTup "ghc_max_large_objects_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) max_large_objects_bytes,+ mkTup "ghc_max_compact_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) max_compact_bytes,+ mkTup "ghc_max_slop_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) max_slop_bytes,+ mkTup "ghc_max_mem_in_use_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) max_mem_in_use_bytes,+ mkTup "ghc_cumulative_live_bytes" (Prometheus.CounterMetricSample . Prometheus.CounterSample) cumulative_live_bytes,+ mkTup "ghc_copied_bytes" (Prometheus.CounterMetricSample . Prometheus.CounterSample) copied_bytes,+ mkParTup "ghc_par_copied_bytes" (Prometheus.CounterMetricSample . Prometheus.CounterSample) par_copied_bytes,+ mkParTup "ghc_cumulative_par_max_copied_bytes" (Prometheus.CounterMetricSample . Prometheus.CounterSample) cumulative_par_max_copied_bytes,+ mkParTup "ghc_cumulative_par_balanced_copied_bytes" (Prometheus.CounterMetricSample . Prometheus.CounterSample) cumulative_par_balanced_copied_bytes,+ mkTup "ghc_init_cpu_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) init_cpu_ns,+ mkTup "ghc_init_elapsed_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) init_elapsed_ns,+ mkTup "ghc_mutator_cpu_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) mutator_cpu_ns,+ mkTup "ghc_mutator_elapsed_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) mutator_elapsed_ns,+ mkTup "ghc_gc_cpu_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) gc_cpu_ns,+ mkTup "ghc_gc_elapsed_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) gc_elapsed_ns,+ mkTup "ghc_cpu_ns" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) cpu_ns,+ mkTup "ghc_elapsed_ns" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) elapsed_ns,+ mkNonmovingTup "ghc_nonmoving_gc_sync_cpu_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) nonmoving_gc_sync_cpu_ns,+ mkNonmovingTup "ghc_nonmoving_gc_sync_elapsed_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) nonmoving_gc_sync_elapsed_ns,+ mkNonmovingTup "ghc_nonmoving_gc_sync_max_elapsed_ns" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) nonmoving_gc_sync_max_elapsed_ns,+ mkNonmovingTup "ghc_nonmoving_gc_cpu_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) nonmoving_gc_cpu_ns,+ mkNonmovingTup "ghc_nonmoving_gc_elapsed_ns" (Prometheus.CounterMetricSample . Prometheus.CounterSample) nonmoving_gc_elapsed_ns,+ mkNonmovingTup "ghc_nonmoving_gc_max_elapsed_ns" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) nonmoving_gc_max_elapsed_ns,+ -- -- From GCDetails+ mkTup "ghc_gcdetails_gen" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_gen,+ mkTup "ghc_gcdetails_threads" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_threads,+ mkTup "ghc_gcdetails_allocated_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_allocated_bytes,+ mkTup "ghc_gcdetails_live_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_live_bytes,+ mkTup "ghc_gcdetails_large_objects_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_large_objects_bytes,+ mkTup "ghc_gcdetails_compact_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_compact_bytes,+ mkTup "ghc_gcdetails_slop_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_slop_bytes,+ mkTup "ghc_gcdetails_mem_in_use_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_mem_in_use_bytes,+ mkTup "ghc_gcdetails_copied_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_copied_bytes,+ mkParTup "ghc_gcdetails_par_max_copied_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_par_max_copied_bytes,+ mkParTup "ghc_gcdetails_par_balanced_copied_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_par_balanced_copied_bytes,+ mkTup "ghc_gcdetails_block_fragmentation_bytes" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_block_fragmentation_bytes,+ mkTup "ghc_gcdetails_sync_elapsed_ns" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_sync_elapsed_ns,+ mkTup "ghc_gcdetails_cpu_ns" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_cpu_ns,+ mkTup "ghc_gcdetails_elapsed_ns" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_elapsed_ns,+ mkNonmovingTup "ghc_gcdetails_nonmoving_gc_sync_cpu_ns" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_nonmoving_gc_sync_cpu_ns,+ mkNonmovingTup "ghc_gcdetails_nonmoving_gc_sync_elapsed_ns" (Prometheus.GaugeMetricSample . Prometheus.GaugeSample) gcdetails_nonmoving_gc_sync_elapsed_ns+ ]+ where+ mkParTup name typ sample = if par_copied_bytes == 0 then Nothing else mkTup name typ sample+ mkNonmovingTup name typ sample = if nonmoving_gc_cpu_ns == 0 then Nothing else mkTup name typ sample+ mkTup name typ sample = Just (Prometheus.MetricId name labels, typ (fromIntegral sample))