35 lines
937 B
Haskell
35 lines
937 B
Haskell
{-# LANGUAGE TypeOperators #-}
|
|
{-# LANGUAGE TypeApplications #-}
|
|
{-# LANGUAGE DeriveGeneric #-}
|
|
module MyLib (someFunc) where
|
|
|
|
import Network.Wai.Metrics (metrics, registerWaiMetrics)
|
|
import System.Metrics
|
|
(Store, newStore, registerGcMetrics)
|
|
import Servant.Metrics.Prometheus
|
|
import Network.Wai.Handler.Warp (runSettings, defaultSettings, setPort)
|
|
import Data.Function ((&))
|
|
import Servant
|
|
import GHC.Generics (Generic)
|
|
|
|
newtype Routes route
|
|
= Routes { _getMetrics :: route :- MetricsRoute }
|
|
deriving (Generic)
|
|
|
|
type API = NamedRoutes Routes
|
|
|
|
app :: Store -> Application
|
|
app store = serve (Proxy @API) Routes { _getMetrics = metricsServer store }
|
|
|
|
someFunc :: IO ()
|
|
someFunc = do
|
|
store <- newStore
|
|
waiMetrics <- registerWaiMetrics store
|
|
registerGcMetrics store
|
|
runSettings settings (metrics waiMetrics $ app store)
|
|
where
|
|
settings =
|
|
defaultSettings &
|
|
setPort 8099
|
|
-- setOnException onException
|