packages feed

prometheus-ghc-stats-0.0.0.0 / src / System / Metrics / Prometheus / GHC / Stats.hs

{-# LANGUAGE OverloadedStrings #-}{-# LANGUAGE RecordWildCards #-}module System.Metrics.Prometheus.GHC.Stats whereimport qualified Data.Map.Strict as Mapimport Data.Maybeimport GHC.Statsimport 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.RegistrySamplesampleGhcStats labels = do  enabled <- getRTSStatsEnabled  if enabled    then do      RTSStats {..} <- getRTSStats      pure $ pureRtsStatsToSamples labels RTSStats {..}    else pure $ Prometheus.RegistrySample Map.emptypureRtsStatsToSamples :: Prometheus.Labels -> RTSStats -> Prometheus.RegistrySamplepureRtsStatsToSamples 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))