{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ElasticBeanstalk.Types.ApplicationMetrics
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.ElasticBeanstalk.Types.ApplicationMetrics where

import qualified Amazonka.Core as Core
import Amazonka.ElasticBeanstalk.Types.Latency
import Amazonka.ElasticBeanstalk.Types.StatusCodes
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Application request metrics for an AWS Elastic Beanstalk environment.
--
-- /See:/ 'newApplicationMetrics' smart constructor.
data ApplicationMetrics = ApplicationMetrics'
  { -- | Average number of requests handled by the web server per second over the
    -- last 10 seconds.
    ApplicationMetrics -> Maybe Int
requestCount :: Prelude.Maybe Prelude.Int,
    -- | Represents the average latency for the slowest X percent of requests
    -- over the last 10 seconds. Latencies are in seconds with one millisecond
    -- resolution.
    ApplicationMetrics -> Maybe Latency
latency :: Prelude.Maybe Latency,
    -- | Represents the percentage of requests over the last 10 seconds that
    -- resulted in each type of status code response.
    ApplicationMetrics -> Maybe StatusCodes
statusCodes :: Prelude.Maybe StatusCodes,
    -- | The amount of time that the metrics cover (usually 10 seconds). For
    -- example, you might have 5 requests (@request_count@) within the most
    -- recent time slice of 10 seconds (@duration@).
    ApplicationMetrics -> Maybe Int
duration :: Prelude.Maybe Prelude.Int
  }
  deriving (ApplicationMetrics -> ApplicationMetrics -> Bool
(ApplicationMetrics -> ApplicationMetrics -> Bool)
-> (ApplicationMetrics -> ApplicationMetrics -> Bool)
-> Eq ApplicationMetrics
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApplicationMetrics -> ApplicationMetrics -> Bool
$c/= :: ApplicationMetrics -> ApplicationMetrics -> Bool
== :: ApplicationMetrics -> ApplicationMetrics -> Bool
$c== :: ApplicationMetrics -> ApplicationMetrics -> Bool
Prelude.Eq, ReadPrec [ApplicationMetrics]
ReadPrec ApplicationMetrics
Int -> ReadS ApplicationMetrics
ReadS [ApplicationMetrics]
(Int -> ReadS ApplicationMetrics)
-> ReadS [ApplicationMetrics]
-> ReadPrec ApplicationMetrics
-> ReadPrec [ApplicationMetrics]
-> Read ApplicationMetrics
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ApplicationMetrics]
$creadListPrec :: ReadPrec [ApplicationMetrics]
readPrec :: ReadPrec ApplicationMetrics
$creadPrec :: ReadPrec ApplicationMetrics
readList :: ReadS [ApplicationMetrics]
$creadList :: ReadS [ApplicationMetrics]
readsPrec :: Int -> ReadS ApplicationMetrics
$creadsPrec :: Int -> ReadS ApplicationMetrics
Prelude.Read, Int -> ApplicationMetrics -> ShowS
[ApplicationMetrics] -> ShowS
ApplicationMetrics -> String
(Int -> ApplicationMetrics -> ShowS)
-> (ApplicationMetrics -> String)
-> ([ApplicationMetrics] -> ShowS)
-> Show ApplicationMetrics
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApplicationMetrics] -> ShowS
$cshowList :: [ApplicationMetrics] -> ShowS
show :: ApplicationMetrics -> String
$cshow :: ApplicationMetrics -> String
showsPrec :: Int -> ApplicationMetrics -> ShowS
$cshowsPrec :: Int -> ApplicationMetrics -> ShowS
Prelude.Show, (forall x. ApplicationMetrics -> Rep ApplicationMetrics x)
-> (forall x. Rep ApplicationMetrics x -> ApplicationMetrics)
-> Generic ApplicationMetrics
forall x. Rep ApplicationMetrics x -> ApplicationMetrics
forall x. ApplicationMetrics -> Rep ApplicationMetrics x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ApplicationMetrics x -> ApplicationMetrics
$cfrom :: forall x. ApplicationMetrics -> Rep ApplicationMetrics x
Prelude.Generic)

-- |
-- Create a value of 'ApplicationMetrics' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'requestCount', 'applicationMetrics_requestCount' - Average number of requests handled by the web server per second over the
-- last 10 seconds.
--
-- 'latency', 'applicationMetrics_latency' - Represents the average latency for the slowest X percent of requests
-- over the last 10 seconds. Latencies are in seconds with one millisecond
-- resolution.
--
-- 'statusCodes', 'applicationMetrics_statusCodes' - Represents the percentage of requests over the last 10 seconds that
-- resulted in each type of status code response.
--
-- 'duration', 'applicationMetrics_duration' - The amount of time that the metrics cover (usually 10 seconds). For
-- example, you might have 5 requests (@request_count@) within the most
-- recent time slice of 10 seconds (@duration@).
newApplicationMetrics ::
  ApplicationMetrics
newApplicationMetrics :: ApplicationMetrics
newApplicationMetrics =
  ApplicationMetrics' :: Maybe Int
-> Maybe Latency
-> Maybe StatusCodes
-> Maybe Int
-> ApplicationMetrics
ApplicationMetrics'
    { $sel:requestCount:ApplicationMetrics' :: Maybe Int
requestCount = Maybe Int
forall a. Maybe a
Prelude.Nothing,
      $sel:latency:ApplicationMetrics' :: Maybe Latency
latency = Maybe Latency
forall a. Maybe a
Prelude.Nothing,
      $sel:statusCodes:ApplicationMetrics' :: Maybe StatusCodes
statusCodes = Maybe StatusCodes
forall a. Maybe a
Prelude.Nothing,
      $sel:duration:ApplicationMetrics' :: Maybe Int
duration = Maybe Int
forall a. Maybe a
Prelude.Nothing
    }

-- | Average number of requests handled by the web server per second over the
-- last 10 seconds.
applicationMetrics_requestCount :: Lens.Lens' ApplicationMetrics (Prelude.Maybe Prelude.Int)
applicationMetrics_requestCount :: (Maybe Int -> f (Maybe Int))
-> ApplicationMetrics -> f ApplicationMetrics
applicationMetrics_requestCount = (ApplicationMetrics -> Maybe Int)
-> (ApplicationMetrics -> Maybe Int -> ApplicationMetrics)
-> Lens
     ApplicationMetrics ApplicationMetrics (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationMetrics' {Maybe Int
requestCount :: Maybe Int
$sel:requestCount:ApplicationMetrics' :: ApplicationMetrics -> Maybe Int
requestCount} -> Maybe Int
requestCount) (\s :: ApplicationMetrics
s@ApplicationMetrics' {} Maybe Int
a -> ApplicationMetrics
s {$sel:requestCount:ApplicationMetrics' :: Maybe Int
requestCount = Maybe Int
a} :: ApplicationMetrics)

-- | Represents the average latency for the slowest X percent of requests
-- over the last 10 seconds. Latencies are in seconds with one millisecond
-- resolution.
applicationMetrics_latency :: Lens.Lens' ApplicationMetrics (Prelude.Maybe Latency)
applicationMetrics_latency :: (Maybe Latency -> f (Maybe Latency))
-> ApplicationMetrics -> f ApplicationMetrics
applicationMetrics_latency = (ApplicationMetrics -> Maybe Latency)
-> (ApplicationMetrics -> Maybe Latency -> ApplicationMetrics)
-> Lens
     ApplicationMetrics
     ApplicationMetrics
     (Maybe Latency)
     (Maybe Latency)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationMetrics' {Maybe Latency
latency :: Maybe Latency
$sel:latency:ApplicationMetrics' :: ApplicationMetrics -> Maybe Latency
latency} -> Maybe Latency
latency) (\s :: ApplicationMetrics
s@ApplicationMetrics' {} Maybe Latency
a -> ApplicationMetrics
s {$sel:latency:ApplicationMetrics' :: Maybe Latency
latency = Maybe Latency
a} :: ApplicationMetrics)

-- | Represents the percentage of requests over the last 10 seconds that
-- resulted in each type of status code response.
applicationMetrics_statusCodes :: Lens.Lens' ApplicationMetrics (Prelude.Maybe StatusCodes)
applicationMetrics_statusCodes :: (Maybe StatusCodes -> f (Maybe StatusCodes))
-> ApplicationMetrics -> f ApplicationMetrics
applicationMetrics_statusCodes = (ApplicationMetrics -> Maybe StatusCodes)
-> (ApplicationMetrics -> Maybe StatusCodes -> ApplicationMetrics)
-> Lens
     ApplicationMetrics
     ApplicationMetrics
     (Maybe StatusCodes)
     (Maybe StatusCodes)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationMetrics' {Maybe StatusCodes
statusCodes :: Maybe StatusCodes
$sel:statusCodes:ApplicationMetrics' :: ApplicationMetrics -> Maybe StatusCodes
statusCodes} -> Maybe StatusCodes
statusCodes) (\s :: ApplicationMetrics
s@ApplicationMetrics' {} Maybe StatusCodes
a -> ApplicationMetrics
s {$sel:statusCodes:ApplicationMetrics' :: Maybe StatusCodes
statusCodes = Maybe StatusCodes
a} :: ApplicationMetrics)

-- | The amount of time that the metrics cover (usually 10 seconds). For
-- example, you might have 5 requests (@request_count@) within the most
-- recent time slice of 10 seconds (@duration@).
applicationMetrics_duration :: Lens.Lens' ApplicationMetrics (Prelude.Maybe Prelude.Int)
applicationMetrics_duration :: (Maybe Int -> f (Maybe Int))
-> ApplicationMetrics -> f ApplicationMetrics
applicationMetrics_duration = (ApplicationMetrics -> Maybe Int)
-> (ApplicationMetrics -> Maybe Int -> ApplicationMetrics)
-> Lens
     ApplicationMetrics ApplicationMetrics (Maybe Int) (Maybe Int)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ApplicationMetrics' {Maybe Int
duration :: Maybe Int
$sel:duration:ApplicationMetrics' :: ApplicationMetrics -> Maybe Int
duration} -> Maybe Int
duration) (\s :: ApplicationMetrics
s@ApplicationMetrics' {} Maybe Int
a -> ApplicationMetrics
s {$sel:duration:ApplicationMetrics' :: Maybe Int
duration = Maybe Int
a} :: ApplicationMetrics)

instance Core.FromXML ApplicationMetrics where
  parseXML :: [Node] -> Either String ApplicationMetrics
parseXML [Node]
x =
    Maybe Int
-> Maybe Latency
-> Maybe StatusCodes
-> Maybe Int
-> ApplicationMetrics
ApplicationMetrics'
      (Maybe Int
 -> Maybe Latency
 -> Maybe StatusCodes
 -> Maybe Int
 -> ApplicationMetrics)
-> Either String (Maybe Int)
-> Either
     String
     (Maybe Latency
      -> Maybe StatusCodes -> Maybe Int -> ApplicationMetrics)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Int)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"RequestCount")
      Either
  String
  (Maybe Latency
   -> Maybe StatusCodes -> Maybe Int -> ApplicationMetrics)
-> Either String (Maybe Latency)
-> Either
     String (Maybe StatusCodes -> Maybe Int -> ApplicationMetrics)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Latency)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Latency")
      Either
  String (Maybe StatusCodes -> Maybe Int -> ApplicationMetrics)
-> Either String (Maybe StatusCodes)
-> Either String (Maybe Int -> ApplicationMetrics)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe StatusCodes)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"StatusCodes")
      Either String (Maybe Int -> ApplicationMetrics)
-> Either String (Maybe Int) -> Either String ApplicationMetrics
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Int)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Duration")

instance Prelude.Hashable ApplicationMetrics

instance Prelude.NFData ApplicationMetrics