{-# 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.AutoScalingPlans.Types.CustomizedScalingMetricSpecification
-- 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.AutoScalingPlans.Types.CustomizedScalingMetricSpecification where

import Amazonka.AutoScalingPlans.Types.MetricDimension
import Amazonka.AutoScalingPlans.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 that can be used for
-- dynamic scaling as part of a target tracking scaling policy.
--
-- To create your customized scaling 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 information about terminology, available metrics, or how to publish
-- new metrics, see
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html Amazon CloudWatch Concepts>
-- in the /Amazon CloudWatch User Guide/.
--
-- /See:/ 'newCustomizedScalingMetricSpecification' smart constructor.
data CustomizedScalingMetricSpecification = CustomizedScalingMetricSpecification'
  { -- | The dimensions of the metric.
    --
    -- Conditional: If you published your metric with dimensions, you must
    -- specify the same dimensions in your customized scaling metric
    -- specification.
    CustomizedScalingMetricSpecification -> Maybe [MetricDimension]
dimensions :: Prelude.Maybe [MetricDimension],
    -- | The unit of the metric.
    CustomizedScalingMetricSpecification -> Maybe Text
unit :: Prelude.Maybe Prelude.Text,
    -- | The name of the metric.
    CustomizedScalingMetricSpecification -> Text
metricName :: Prelude.Text,
    -- | The namespace of the metric.
    CustomizedScalingMetricSpecification -> Text
namespace :: Prelude.Text,
    -- | The statistic of the metric.
    CustomizedScalingMetricSpecification -> MetricStatistic
statistic :: MetricStatistic
  }
  deriving (CustomizedScalingMetricSpecification
-> CustomizedScalingMetricSpecification -> Bool
(CustomizedScalingMetricSpecification
 -> CustomizedScalingMetricSpecification -> Bool)
-> (CustomizedScalingMetricSpecification
    -> CustomizedScalingMetricSpecification -> Bool)
-> Eq CustomizedScalingMetricSpecification
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomizedScalingMetricSpecification
-> CustomizedScalingMetricSpecification -> Bool
$c/= :: CustomizedScalingMetricSpecification
-> CustomizedScalingMetricSpecification -> Bool
== :: CustomizedScalingMetricSpecification
-> CustomizedScalingMetricSpecification -> Bool
$c== :: CustomizedScalingMetricSpecification
-> CustomizedScalingMetricSpecification -> Bool
Prelude.Eq, ReadPrec [CustomizedScalingMetricSpecification]
ReadPrec CustomizedScalingMetricSpecification
Int -> ReadS CustomizedScalingMetricSpecification
ReadS [CustomizedScalingMetricSpecification]
(Int -> ReadS CustomizedScalingMetricSpecification)
-> ReadS [CustomizedScalingMetricSpecification]
-> ReadPrec CustomizedScalingMetricSpecification
-> ReadPrec [CustomizedScalingMetricSpecification]
-> Read CustomizedScalingMetricSpecification
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomizedScalingMetricSpecification]
$creadListPrec :: ReadPrec [CustomizedScalingMetricSpecification]
readPrec :: ReadPrec CustomizedScalingMetricSpecification
$creadPrec :: ReadPrec CustomizedScalingMetricSpecification
readList :: ReadS [CustomizedScalingMetricSpecification]
$creadList :: ReadS [CustomizedScalingMetricSpecification]
readsPrec :: Int -> ReadS CustomizedScalingMetricSpecification
$creadsPrec :: Int -> ReadS CustomizedScalingMetricSpecification
Prelude.Read, Int -> CustomizedScalingMetricSpecification -> ShowS
[CustomizedScalingMetricSpecification] -> ShowS
CustomizedScalingMetricSpecification -> String
(Int -> CustomizedScalingMetricSpecification -> ShowS)
-> (CustomizedScalingMetricSpecification -> String)
-> ([CustomizedScalingMetricSpecification] -> ShowS)
-> Show CustomizedScalingMetricSpecification
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomizedScalingMetricSpecification] -> ShowS
$cshowList :: [CustomizedScalingMetricSpecification] -> ShowS
show :: CustomizedScalingMetricSpecification -> String
$cshow :: CustomizedScalingMetricSpecification -> String
showsPrec :: Int -> CustomizedScalingMetricSpecification -> ShowS
$cshowsPrec :: Int -> CustomizedScalingMetricSpecification -> ShowS
Prelude.Show, (forall x.
 CustomizedScalingMetricSpecification
 -> Rep CustomizedScalingMetricSpecification x)
-> (forall x.
    Rep CustomizedScalingMetricSpecification x
    -> CustomizedScalingMetricSpecification)
-> Generic CustomizedScalingMetricSpecification
forall x.
Rep CustomizedScalingMetricSpecification x
-> CustomizedScalingMetricSpecification
forall x.
CustomizedScalingMetricSpecification
-> Rep CustomizedScalingMetricSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CustomizedScalingMetricSpecification x
-> CustomizedScalingMetricSpecification
$cfrom :: forall x.
CustomizedScalingMetricSpecification
-> Rep CustomizedScalingMetricSpecification x
Prelude.Generic)

-- |
-- Create a value of 'CustomizedScalingMetricSpecification' 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', 'customizedScalingMetricSpecification_dimensions' - The dimensions of the metric.
--
-- Conditional: If you published your metric with dimensions, you must
-- specify the same dimensions in your customized scaling metric
-- specification.
--
-- 'unit', 'customizedScalingMetricSpecification_unit' - The unit of the metric.
--
-- 'metricName', 'customizedScalingMetricSpecification_metricName' - The name of the metric.
--
-- 'namespace', 'customizedScalingMetricSpecification_namespace' - The namespace of the metric.
--
-- 'statistic', 'customizedScalingMetricSpecification_statistic' - The statistic of the metric.
newCustomizedScalingMetricSpecification ::
  -- | 'metricName'
  Prelude.Text ->
  -- | 'namespace'
  Prelude.Text ->
  -- | 'statistic'
  MetricStatistic ->
  CustomizedScalingMetricSpecification
newCustomizedScalingMetricSpecification :: Text
-> Text -> MetricStatistic -> CustomizedScalingMetricSpecification
newCustomizedScalingMetricSpecification
  Text
pMetricName_
  Text
pNamespace_
  MetricStatistic
pStatistic_ =
    CustomizedScalingMetricSpecification' :: Maybe [MetricDimension]
-> Maybe Text
-> Text
-> Text
-> MetricStatistic
-> CustomizedScalingMetricSpecification
CustomizedScalingMetricSpecification'
      { $sel:dimensions:CustomizedScalingMetricSpecification' :: Maybe [MetricDimension]
dimensions =
          Maybe [MetricDimension]
forall a. Maybe a
Prelude.Nothing,
        $sel:unit:CustomizedScalingMetricSpecification' :: Maybe Text
unit = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:metricName:CustomizedScalingMetricSpecification' :: Text
metricName = Text
pMetricName_,
        $sel:namespace:CustomizedScalingMetricSpecification' :: Text
namespace = Text
pNamespace_,
        $sel:statistic:CustomizedScalingMetricSpecification' :: 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 customized scaling metric
-- specification.
customizedScalingMetricSpecification_dimensions :: Lens.Lens' CustomizedScalingMetricSpecification (Prelude.Maybe [MetricDimension])
customizedScalingMetricSpecification_dimensions :: (Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
-> CustomizedScalingMetricSpecification
-> f CustomizedScalingMetricSpecification
customizedScalingMetricSpecification_dimensions = (CustomizedScalingMetricSpecification -> Maybe [MetricDimension])
-> (CustomizedScalingMetricSpecification
    -> Maybe [MetricDimension] -> CustomizedScalingMetricSpecification)
-> Lens
     CustomizedScalingMetricSpecification
     CustomizedScalingMetricSpecification
     (Maybe [MetricDimension])
     (Maybe [MetricDimension])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedScalingMetricSpecification' {Maybe [MetricDimension]
dimensions :: Maybe [MetricDimension]
$sel:dimensions:CustomizedScalingMetricSpecification' :: CustomizedScalingMetricSpecification -> Maybe [MetricDimension]
dimensions} -> Maybe [MetricDimension]
dimensions) (\s :: CustomizedScalingMetricSpecification
s@CustomizedScalingMetricSpecification' {} Maybe [MetricDimension]
a -> CustomizedScalingMetricSpecification
s {$sel:dimensions:CustomizedScalingMetricSpecification' :: Maybe [MetricDimension]
dimensions = Maybe [MetricDimension]
a} :: CustomizedScalingMetricSpecification) ((Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
 -> CustomizedScalingMetricSpecification
 -> f CustomizedScalingMetricSpecification)
-> ((Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
    -> Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
-> (Maybe [MetricDimension] -> f (Maybe [MetricDimension]))
-> CustomizedScalingMetricSpecification
-> f CustomizedScalingMetricSpecification
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.
customizedScalingMetricSpecification_unit :: Lens.Lens' CustomizedScalingMetricSpecification (Prelude.Maybe Prelude.Text)
customizedScalingMetricSpecification_unit :: (Maybe Text -> f (Maybe Text))
-> CustomizedScalingMetricSpecification
-> f CustomizedScalingMetricSpecification
customizedScalingMetricSpecification_unit = (CustomizedScalingMetricSpecification -> Maybe Text)
-> (CustomizedScalingMetricSpecification
    -> Maybe Text -> CustomizedScalingMetricSpecification)
-> Lens
     CustomizedScalingMetricSpecification
     CustomizedScalingMetricSpecification
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedScalingMetricSpecification' {Maybe Text
unit :: Maybe Text
$sel:unit:CustomizedScalingMetricSpecification' :: CustomizedScalingMetricSpecification -> Maybe Text
unit} -> Maybe Text
unit) (\s :: CustomizedScalingMetricSpecification
s@CustomizedScalingMetricSpecification' {} Maybe Text
a -> CustomizedScalingMetricSpecification
s {$sel:unit:CustomizedScalingMetricSpecification' :: Maybe Text
unit = Maybe Text
a} :: CustomizedScalingMetricSpecification)

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

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

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

instance
  Core.FromJSON
    CustomizedScalingMetricSpecification
  where
  parseJSON :: Value -> Parser CustomizedScalingMetricSpecification
parseJSON =
    String
-> (Object -> Parser CustomizedScalingMetricSpecification)
-> Value
-> Parser CustomizedScalingMetricSpecification
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"CustomizedScalingMetricSpecification"
      ( \Object
x ->
          Maybe [MetricDimension]
-> Maybe Text
-> Text
-> Text
-> MetricStatistic
-> CustomizedScalingMetricSpecification
CustomizedScalingMetricSpecification'
            (Maybe [MetricDimension]
 -> Maybe Text
 -> Text
 -> Text
 -> MetricStatistic
 -> CustomizedScalingMetricSpecification)
-> Parser (Maybe [MetricDimension])
-> Parser
     (Maybe Text
      -> Text
      -> Text
      -> MetricStatistic
      -> CustomizedScalingMetricSpecification)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (Maybe [MetricDimension]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Dimensions" Parser (Maybe (Maybe [MetricDimension]))
-> Maybe [MetricDimension] -> Parser (Maybe [MetricDimension])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [MetricDimension]
forall a. Monoid a => a
Prelude.mempty)
            Parser
  (Maybe Text
   -> Text
   -> Text
   -> MetricStatistic
   -> CustomizedScalingMetricSpecification)
-> Parser (Maybe Text)
-> Parser
     (Text
      -> Text -> MetricStatistic -> CustomizedScalingMetricSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Unit")
            Parser
  (Text
   -> Text -> MetricStatistic -> CustomizedScalingMetricSpecification)
-> Parser Text
-> Parser
     (Text -> MetricStatistic -> CustomizedScalingMetricSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"MetricName")
            Parser
  (Text -> MetricStatistic -> CustomizedScalingMetricSpecification)
-> Parser Text
-> Parser (MetricStatistic -> CustomizedScalingMetricSpecification)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Namespace")
            Parser (MetricStatistic -> CustomizedScalingMetricSpecification)
-> Parser MetricStatistic
-> Parser CustomizedScalingMetricSpecification
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser MetricStatistic
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Statistic")
      )

instance
  Prelude.Hashable
    CustomizedScalingMetricSpecification

instance
  Prelude.NFData
    CustomizedScalingMetricSpecification

instance
  Core.ToJSON
    CustomizedScalingMetricSpecification
  where
  toJSON :: CustomizedScalingMetricSpecification -> Value
toJSON CustomizedScalingMetricSpecification' {Maybe [MetricDimension]
Maybe Text
Text
MetricStatistic
statistic :: MetricStatistic
namespace :: Text
metricName :: Text
unit :: Maybe Text
dimensions :: Maybe [MetricDimension]
$sel:statistic:CustomizedScalingMetricSpecification' :: CustomizedScalingMetricSpecification -> MetricStatistic
$sel:namespace:CustomizedScalingMetricSpecification' :: CustomizedScalingMetricSpecification -> Text
$sel:metricName:CustomizedScalingMetricSpecification' :: CustomizedScalingMetricSpecification -> Text
$sel:unit:CustomizedScalingMetricSpecification' :: CustomizedScalingMetricSpecification -> Maybe Text
$sel:dimensions:CustomizedScalingMetricSpecification' :: CustomizedScalingMetricSpecification -> Maybe [MetricDimension]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Dimensions" Text -> [MetricDimension] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) ([MetricDimension] -> Pair)
-> Maybe [MetricDimension] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [MetricDimension]
dimensions,
            (Text
"Unit" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
unit,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"MetricName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
metricName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Namespace" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
namespace),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Statistic" Text -> MetricStatistic -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= MetricStatistic
statistic)
          ]
      )