{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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.
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'
      { $sel:dimensions:CustomizedScalingMetricSpecification' :: Maybe [MetricDimension]
dimensions =
          forall a. Maybe a
Prelude.Nothing,
        $sel:unit:CustomizedScalingMetricSpecification' :: Maybe Text
unit = 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 :: Lens'
  CustomizedScalingMetricSpecification (Maybe [MetricDimension])
customizedScalingMetricSpecification_dimensions = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 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 :: Lens' CustomizedScalingMetricSpecification (Maybe Text)
customizedScalingMetricSpecification_unit = 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 :: Lens' CustomizedScalingMetricSpecification Text
customizedScalingMetricSpecification_metricName = 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 :: Lens' CustomizedScalingMetricSpecification Text
customizedScalingMetricSpecification_namespace = 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 :: Lens' CustomizedScalingMetricSpecification MetricStatistic
customizedScalingMetricSpecification_statistic = 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
  Data.FromJSON
    CustomizedScalingMetricSpecification
  where
  parseJSON :: Value -> Parser CustomizedScalingMetricSpecification
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CustomizedScalingMetricSpecification"
      ( \Object
x ->
          Maybe [MetricDimension]
-> Maybe Text
-> Text
-> Text
-> MetricStatistic
-> CustomizedScalingMetricSpecification
CustomizedScalingMetricSpecification'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Dimensions" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Unit")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"MetricName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Namespace")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Statistic")
      )

instance
  Prelude.Hashable
    CustomizedScalingMetricSpecification
  where
  hashWithSalt :: Int -> CustomizedScalingMetricSpecification -> Int
hashWithSalt
    Int
_salt
    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]
..} =
      Int
_salt
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [MetricDimension]
dimensions
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
unit
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
metricName
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
namespace
        forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` MetricStatistic
statistic

instance
  Prelude.NFData
    CustomizedScalingMetricSpecification
  where
  rnf :: CustomizedScalingMetricSpecification -> ()
rnf 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]
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe [MetricDimension]
dimensions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
unit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
metricName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
namespace
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf MetricStatistic
statistic

instance
  Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Dimensions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [MetricDimension]
dimensions,
            (Key
"Unit" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
unit,
            forall a. a -> Maybe a
Prelude.Just (Key
"MetricName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
metricName),
            forall a. a -> Maybe a
Prelude.Just (Key
"Namespace" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
namespace),
            forall a. a -> Maybe a
Prelude.Just (Key
"Statistic" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= MetricStatistic
statistic)
          ]
      )