{-# 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.AutoScaling.Types.CustomizedMetricSpecification
-- 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.AutoScaling.Types.CustomizedMetricSpecification where

import Amazonka.AutoScaling.Types.MetricDimension
import Amazonka.AutoScaling.Types.MetricStatistic
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a CloudWatch metric of your choosing for a target tracking
-- scaling policy to use with Amazon EC2 Auto Scaling.
--
-- To create your customized metric specification:
--
-- -   Add values for each required parameter from CloudWatch. You can use
--     an existing metric, or a new metric that you create. To use your own
--     metric, you must first publish the metric to CloudWatch. For more
--     information, see
--     <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html Publish Custom Metrics>
--     in the /Amazon CloudWatch User Guide/.
--
-- -   Choose a metric that changes proportionally with capacity. The value
--     of the metric should increase or decrease in inverse proportion to
--     the number of capacity units. That is, the value of the metric
--     should decrease when capacity increases.
--
-- For more information about CloudWatch, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html Amazon CloudWatch Concepts>.
--
-- /See:/ 'newCustomizedMetricSpecification' smart constructor.
data CustomizedMetricSpecification = CustomizedMetricSpecification'
  { -- | The dimensions of the metric.
    --
    -- Conditional: If you published your metric with dimensions, you must
    -- specify the same dimensions in your scaling policy.
    CustomizedMetricSpecification -> Maybe [MetricDimension]
dimensions :: Prelude.Maybe [MetricDimension],
    -- | The unit of the metric.
    CustomizedMetricSpecification -> Maybe Text
unit :: Prelude.Maybe Prelude.Text,
    -- | The name of the metric.
    CustomizedMetricSpecification -> Text
metricName :: Prelude.Text,
    -- | The namespace of the metric.
    CustomizedMetricSpecification -> Text
namespace :: Prelude.Text,
    -- | The statistic of the metric.
    CustomizedMetricSpecification -> MetricStatistic
statistic :: MetricStatistic
  }
  deriving (CustomizedMetricSpecification
-> CustomizedMetricSpecification -> Bool
(CustomizedMetricSpecification
 -> CustomizedMetricSpecification -> Bool)
-> (CustomizedMetricSpecification
    -> CustomizedMetricSpecification -> Bool)
-> Eq CustomizedMetricSpecification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomizedMetricSpecification
-> CustomizedMetricSpecification -> Bool
$c/= :: CustomizedMetricSpecification
-> CustomizedMetricSpecification -> Bool
== :: CustomizedMetricSpecification
-> CustomizedMetricSpecification -> Bool
$c== :: CustomizedMetricSpecification
-> CustomizedMetricSpecification -> Bool
Prelude.Eq, ReadPrec [CustomizedMetricSpecification]
ReadPrec CustomizedMetricSpecification
Int -> ReadS CustomizedMetricSpecification
ReadS [CustomizedMetricSpecification]
(Int -> ReadS CustomizedMetricSpecification)
-> ReadS [CustomizedMetricSpecification]
-> ReadPrec CustomizedMetricSpecification
-> ReadPrec [CustomizedMetricSpecification]
-> Read CustomizedMetricSpecification
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomizedMetricSpecification]
$creadListPrec :: ReadPrec [CustomizedMetricSpecification]
readPrec :: ReadPrec CustomizedMetricSpecification
$creadPrec :: ReadPrec CustomizedMetricSpecification
readList :: ReadS [CustomizedMetricSpecification]
$creadList :: ReadS [CustomizedMetricSpecification]
readsPrec :: Int -> ReadS CustomizedMetricSpecification
$creadsPrec :: Int -> ReadS CustomizedMetricSpecification
Prelude.Read, Int -> CustomizedMetricSpecification -> ShowS
[CustomizedMetricSpecification] -> ShowS
CustomizedMetricSpecification -> String
(Int -> CustomizedMetricSpecification -> ShowS)
-> (CustomizedMetricSpecification -> String)
-> ([CustomizedMetricSpecification] -> ShowS)
-> Show CustomizedMetricSpecification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomizedMetricSpecification] -> ShowS
$cshowList :: [CustomizedMetricSpecification] -> ShowS
show :: CustomizedMetricSpecification -> String
$cshow :: CustomizedMetricSpecification -> String
showsPrec :: Int -> CustomizedMetricSpecification -> ShowS
$cshowsPrec :: Int -> CustomizedMetricSpecification -> ShowS
Prelude.Show, (forall x.
 CustomizedMetricSpecification
 -> Rep CustomizedMetricSpecification x)
-> (forall x.
    Rep CustomizedMetricSpecification x
    -> CustomizedMetricSpecification)
-> Generic CustomizedMetricSpecification
forall x.
Rep CustomizedMetricSpecification x
-> CustomizedMetricSpecification
forall x.
CustomizedMetricSpecification
-> Rep CustomizedMetricSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CustomizedMetricSpecification x
-> CustomizedMetricSpecification
$cfrom :: forall x.
CustomizedMetricSpecification
-> Rep CustomizedMetricSpecification x
Prelude.Generic)

-- |
-- Create a value of 'CustomizedMetricSpecification' 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:
--
-- 'dimensions', 'customizedMetricSpecification_dimensions' - The dimensions of the metric.
--
-- Conditional: If you published your metric with dimensions, you must
-- specify the same dimensions in your scaling policy.
--
-- 'unit', 'customizedMetricSpecification_unit' - The unit of the metric.
--
-- 'metricName', 'customizedMetricSpecification_metricName' - The name of the metric.
--
-- 'namespace', 'customizedMetricSpecification_namespace' - The namespace of the metric.
--
-- 'statistic', 'customizedMetricSpecification_statistic' - The statistic of the metric.
newCustomizedMetricSpecification ::
  -- | 'metricName'
  Prelude.Text ->
  -- | 'namespace'
  Prelude.Text ->
  -- | 'statistic'
  MetricStatistic ->
  CustomizedMetricSpecification
newCustomizedMetricSpecification :: Text -> Text -> MetricStatistic -> CustomizedMetricSpecification
newCustomizedMetricSpecification
  Text
pMetricName_
  Text
pNamespace_
  MetricStatistic
pStatistic_ =
    CustomizedMetricSpecification' :: Maybe [MetricDimension]
-> Maybe Text
-> Text
-> Text
-> MetricStatistic
-> CustomizedMetricSpecification
CustomizedMetricSpecification'
      { $sel:dimensions:CustomizedMetricSpecification' :: Maybe [MetricDimension]
dimensions =
          Maybe [MetricDimension]
forall a. Maybe a
Prelude.Nothing,
        $sel:unit:CustomizedMetricSpecification' :: Maybe Text
unit = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:metricName:CustomizedMetricSpecification' :: Text
metricName = Text
pMetricName_,
        $sel:namespace:CustomizedMetricSpecification' :: Text
namespace = Text
pNamespace_,
        $sel:statistic:CustomizedMetricSpecification' :: MetricStatistic
statistic = MetricStatistic
pStatistic_
      }

-- | The dimensions of the metric.
--
-- Conditional: If you published your metric with dimensions, you must
-- specify the same dimensions in your scaling policy.
customizedMetricSpecification_dimensions :: Lens.Lens' CustomizedMetricSpecification (Prelude.Maybe [MetricDimension])
customizedMetricSpecification_dimensions :: (Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
-> CustomizedMetricSpecification -> f CustomizedMetricSpecification
customizedMetricSpecification_dimensions = (CustomizedMetricSpecification -> Maybe [MetricDimension])
-> (CustomizedMetricSpecification
    -> Maybe [MetricDimension] -> CustomizedMetricSpecification)
-> Lens
     CustomizedMetricSpecification
     CustomizedMetricSpecification
     (Maybe [MetricDimension])
     (Maybe [MetricDimension])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedMetricSpecification' {Maybe [MetricDimension]
dimensions :: Maybe [MetricDimension]
$sel:dimensions:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> Maybe [MetricDimension]
dimensions} -> Maybe [MetricDimension]
dimensions) (\s :: CustomizedMetricSpecification
s@CustomizedMetricSpecification' {} Maybe [MetricDimension]
a -> CustomizedMetricSpecification
s {$sel:dimensions:CustomizedMetricSpecification' :: Maybe [MetricDimension]
dimensions = Maybe [MetricDimension]
a} :: CustomizedMetricSpecification) ((Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
 -> CustomizedMetricSpecification
 -> f CustomizedMetricSpecification)
-> ((Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
    -> Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
-> (Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
-> CustomizedMetricSpecification
-> f CustomizedMetricSpecification
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  [MetricDimension]
  [MetricDimension]
  [MetricDimension]
  [MetricDimension]
-> Iso
     (Maybe [MetricDimension])
     (Maybe [MetricDimension])
     (Maybe [MetricDimension])
     (Maybe [MetricDimension])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  [MetricDimension]
  [MetricDimension]
  [MetricDimension]
  [MetricDimension]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The unit of the metric.
customizedMetricSpecification_unit :: Lens.Lens' CustomizedMetricSpecification (Prelude.Maybe Prelude.Text)
customizedMetricSpecification_unit :: (Maybe Text -> f (Maybe Text))
-> CustomizedMetricSpecification -> f CustomizedMetricSpecification
customizedMetricSpecification_unit = (CustomizedMetricSpecification -> Maybe Text)
-> (CustomizedMetricSpecification
    -> Maybe Text -> CustomizedMetricSpecification)
-> Lens
     CustomizedMetricSpecification
     CustomizedMetricSpecification
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedMetricSpecification' {Maybe Text
unit :: Maybe Text
$sel:unit:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> Maybe Text
unit} -> Maybe Text
unit) (\s :: CustomizedMetricSpecification
s@CustomizedMetricSpecification' {} Maybe Text
a -> CustomizedMetricSpecification
s {$sel:unit:CustomizedMetricSpecification' :: Maybe Text
unit = Maybe Text
a} :: CustomizedMetricSpecification)

-- | The name of the metric.
customizedMetricSpecification_metricName :: Lens.Lens' CustomizedMetricSpecification Prelude.Text
customizedMetricSpecification_metricName :: (Text -> f Text)
-> CustomizedMetricSpecification -> f CustomizedMetricSpecification
customizedMetricSpecification_metricName = (CustomizedMetricSpecification -> Text)
-> (CustomizedMetricSpecification
    -> Text -> CustomizedMetricSpecification)
-> Lens
     CustomizedMetricSpecification
     CustomizedMetricSpecification
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedMetricSpecification' {Text
metricName :: Text
$sel:metricName:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> Text
metricName} -> Text
metricName) (\s :: CustomizedMetricSpecification
s@CustomizedMetricSpecification' {} Text
a -> CustomizedMetricSpecification
s {$sel:metricName:CustomizedMetricSpecification' :: Text
metricName = Text
a} :: CustomizedMetricSpecification)

-- | The namespace of the metric.
customizedMetricSpecification_namespace :: Lens.Lens' CustomizedMetricSpecification Prelude.Text
customizedMetricSpecification_namespace :: (Text -> f Text)
-> CustomizedMetricSpecification -> f CustomizedMetricSpecification
customizedMetricSpecification_namespace = (CustomizedMetricSpecification -> Text)
-> (CustomizedMetricSpecification
    -> Text -> CustomizedMetricSpecification)
-> Lens
     CustomizedMetricSpecification
     CustomizedMetricSpecification
     Text
     Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedMetricSpecification' {Text
namespace :: Text
$sel:namespace:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> Text
namespace} -> Text
namespace) (\s :: CustomizedMetricSpecification
s@CustomizedMetricSpecification' {} Text
a -> CustomizedMetricSpecification
s {$sel:namespace:CustomizedMetricSpecification' :: Text
namespace = Text
a} :: CustomizedMetricSpecification)

-- | The statistic of the metric.
customizedMetricSpecification_statistic :: Lens.Lens' CustomizedMetricSpecification MetricStatistic
customizedMetricSpecification_statistic :: (MetricStatistic -> f MetricStatistic)
-> CustomizedMetricSpecification -> f CustomizedMetricSpecification
customizedMetricSpecification_statistic = (CustomizedMetricSpecification -> MetricStatistic)
-> (CustomizedMetricSpecification
    -> MetricStatistic -> CustomizedMetricSpecification)
-> Lens
     CustomizedMetricSpecification
     CustomizedMetricSpecification
     MetricStatistic
     MetricStatistic
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedMetricSpecification' {MetricStatistic
statistic :: MetricStatistic
$sel:statistic:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> MetricStatistic
statistic} -> MetricStatistic
statistic) (\s :: CustomizedMetricSpecification
s@CustomizedMetricSpecification' {} MetricStatistic
a -> CustomizedMetricSpecification
s {$sel:statistic:CustomizedMetricSpecification' :: MetricStatistic
statistic = MetricStatistic
a} :: CustomizedMetricSpecification)

instance Core.FromXML CustomizedMetricSpecification where
  parseXML :: [Node] -> Either String CustomizedMetricSpecification
parseXML [Node]
x =
    Maybe [MetricDimension]
-> Maybe Text
-> Text
-> Text
-> MetricStatistic
-> CustomizedMetricSpecification
CustomizedMetricSpecification'
      (Maybe [MetricDimension]
 -> Maybe Text
 -> Text
 -> Text
 -> MetricStatistic
 -> CustomizedMetricSpecification)
-> Either String (Maybe [MetricDimension])
-> Either
     String
     (Maybe Text
      -> Text
      -> Text
      -> MetricStatistic
      -> CustomizedMetricSpecification)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Dimensions" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [MetricDimension]))
-> Either String (Maybe [MetricDimension])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [MetricDimension])
-> [Node] -> Either String (Maybe [MetricDimension])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [MetricDimension]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )
      Either
  String
  (Maybe Text
   -> Text
   -> Text
   -> MetricStatistic
   -> CustomizedMetricSpecification)
-> Either String (Maybe Text)
-> Either
     String
     (Text -> Text -> MetricStatistic -> CustomizedMetricSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String (Maybe Text)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Unit")
      Either
  String
  (Text -> Text -> MetricStatistic -> CustomizedMetricSpecification)
-> Either String Text
-> Either
     String (Text -> MetricStatistic -> CustomizedMetricSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"MetricName")
      Either
  String (Text -> MetricStatistic -> CustomizedMetricSpecification)
-> Either String Text
-> Either String (MetricStatistic -> CustomizedMetricSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Namespace")
      Either String (MetricStatistic -> CustomizedMetricSpecification)
-> Either String MetricStatistic
-> Either String CustomizedMetricSpecification
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String MetricStatistic
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Statistic")

instance
  Prelude.Hashable
    CustomizedMetricSpecification

instance Prelude.NFData CustomizedMetricSpecification

instance Core.ToQuery CustomizedMetricSpecification where
  toQuery :: CustomizedMetricSpecification -> QueryString
toQuery CustomizedMetricSpecification' {Maybe [MetricDimension]
Maybe Text
Text
MetricStatistic
statistic :: MetricStatistic
namespace :: Text
metricName :: Text
unit :: Maybe Text
dimensions :: Maybe [MetricDimension]
$sel:statistic:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> MetricStatistic
$sel:namespace:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> Text
$sel:metricName:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> Text
$sel:unit:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> Maybe Text
$sel:dimensions:CustomizedMetricSpecification' :: CustomizedMetricSpecification -> Maybe [MetricDimension]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Dimensions"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [MetricDimension] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" ([MetricDimension] -> QueryString)
-> Maybe [MetricDimension] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [MetricDimension]
dimensions),
        ByteString
"Unit" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
unit,
        ByteString
"MetricName" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
metricName,
        ByteString
"Namespace" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
namespace,
        ByteString
"Statistic" ByteString -> MetricStatistic -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: MetricStatistic
statistic
      ]