{-# 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.CustomizedLoadMetricSpecification
-- 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.CustomizedLoadMetricSpecification 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
-- predictive scaling.
--
-- For predictive scaling to work with a customized load metric
-- specification, AWS Auto Scaling needs access to the @Sum@ and @Average@
-- statistics that CloudWatch computes from metric data.
--
-- When you choose a load metric, make sure that the required @Sum@ and
-- @Average@ statistics for your metric are available in CloudWatch and
-- that they provide relevant data for predictive scaling. The @Sum@
-- statistic must represent the total load on the resource, and the
-- @Average@ statistic must represent the average load per capacity unit of
-- the resource. For example, there is a metric that counts the number of
-- requests processed by your Auto Scaling group. If the @Sum@ statistic
-- represents the total request count processed by the group, then the
-- @Average@ statistic for the specified metric must represent the average
-- request count processed by each instance of the group.
--
-- If you publish your own metrics, you can aggregate the data points at a
-- given interval and then publish the aggregated data points to
-- CloudWatch. Before AWS Auto Scaling generates the forecast, it sums up
-- all the metric data points that occurred within each hour to match the
-- granularity period that is used in the forecast (60 minutes).
--
-- 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/.
--
-- After creating your scaling plan, you can use the AWS Auto Scaling
-- console to visualize forecasts for the specified metric. For more
-- information, see
-- <https://docs.aws.amazon.com/autoscaling/plans/userguide/gs-create-scaling-plan.html#gs-view-resource View Scaling Information for a Resource>
-- in the /AWS Auto Scaling User Guide/.
--
-- /See:/ 'newCustomizedLoadMetricSpecification' smart constructor.
data CustomizedLoadMetricSpecification = CustomizedLoadMetricSpecification'
  { -- | The dimensions of the metric.
    --
    -- Conditional: If you published your metric with dimensions, you must
    -- specify the same dimensions in your customized load metric
    -- specification.
    CustomizedLoadMetricSpecification -> Maybe [MetricDimension]
dimensions :: Prelude.Maybe [MetricDimension],
    -- | The unit of the metric.
    CustomizedLoadMetricSpecification -> Maybe Text
unit :: Prelude.Maybe Prelude.Text,
    -- | The name of the metric.
    CustomizedLoadMetricSpecification -> Text
metricName :: Prelude.Text,
    -- | The namespace of the metric.
    CustomizedLoadMetricSpecification -> Text
namespace :: Prelude.Text,
    -- | The statistic of the metric. The only valid value is @Sum@.
    CustomizedLoadMetricSpecification -> MetricStatistic
statistic :: MetricStatistic
  }
  deriving (CustomizedLoadMetricSpecification
-> CustomizedLoadMetricSpecification -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CustomizedLoadMetricSpecification
-> CustomizedLoadMetricSpecification -> Bool
$c/= :: CustomizedLoadMetricSpecification
-> CustomizedLoadMetricSpecification -> Bool
== :: CustomizedLoadMetricSpecification
-> CustomizedLoadMetricSpecification -> Bool
$c== :: CustomizedLoadMetricSpecification
-> CustomizedLoadMetricSpecification -> Bool
Prelude.Eq, ReadPrec [CustomizedLoadMetricSpecification]
ReadPrec CustomizedLoadMetricSpecification
Int -> ReadS CustomizedLoadMetricSpecification
ReadS [CustomizedLoadMetricSpecification]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CustomizedLoadMetricSpecification]
$creadListPrec :: ReadPrec [CustomizedLoadMetricSpecification]
readPrec :: ReadPrec CustomizedLoadMetricSpecification
$creadPrec :: ReadPrec CustomizedLoadMetricSpecification
readList :: ReadS [CustomizedLoadMetricSpecification]
$creadList :: ReadS [CustomizedLoadMetricSpecification]
readsPrec :: Int -> ReadS CustomizedLoadMetricSpecification
$creadsPrec :: Int -> ReadS CustomizedLoadMetricSpecification
Prelude.Read, Int -> CustomizedLoadMetricSpecification -> ShowS
[CustomizedLoadMetricSpecification] -> ShowS
CustomizedLoadMetricSpecification -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CustomizedLoadMetricSpecification] -> ShowS
$cshowList :: [CustomizedLoadMetricSpecification] -> ShowS
show :: CustomizedLoadMetricSpecification -> String
$cshow :: CustomizedLoadMetricSpecification -> String
showsPrec :: Int -> CustomizedLoadMetricSpecification -> ShowS
$cshowsPrec :: Int -> CustomizedLoadMetricSpecification -> ShowS
Prelude.Show, forall x.
Rep CustomizedLoadMetricSpecification x
-> CustomizedLoadMetricSpecification
forall x.
CustomizedLoadMetricSpecification
-> Rep CustomizedLoadMetricSpecification x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CustomizedLoadMetricSpecification x
-> CustomizedLoadMetricSpecification
$cfrom :: forall x.
CustomizedLoadMetricSpecification
-> Rep CustomizedLoadMetricSpecification x
Prelude.Generic)

-- |
-- Create a value of 'CustomizedLoadMetricSpecification' 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', 'customizedLoadMetricSpecification_dimensions' - The dimensions of the metric.
--
-- Conditional: If you published your metric with dimensions, you must
-- specify the same dimensions in your customized load metric
-- specification.
--
-- 'unit', 'customizedLoadMetricSpecification_unit' - The unit of the metric.
--
-- 'metricName', 'customizedLoadMetricSpecification_metricName' - The name of the metric.
--
-- 'namespace', 'customizedLoadMetricSpecification_namespace' - The namespace of the metric.
--
-- 'statistic', 'customizedLoadMetricSpecification_statistic' - The statistic of the metric. The only valid value is @Sum@.
newCustomizedLoadMetricSpecification ::
  -- | 'metricName'
  Prelude.Text ->
  -- | 'namespace'
  Prelude.Text ->
  -- | 'statistic'
  MetricStatistic ->
  CustomizedLoadMetricSpecification
newCustomizedLoadMetricSpecification :: Text
-> Text -> MetricStatistic -> CustomizedLoadMetricSpecification
newCustomizedLoadMetricSpecification
  Text
pMetricName_
  Text
pNamespace_
  MetricStatistic
pStatistic_ =
    CustomizedLoadMetricSpecification'
      { $sel:dimensions:CustomizedLoadMetricSpecification' :: Maybe [MetricDimension]
dimensions =
          forall a. Maybe a
Prelude.Nothing,
        $sel:unit:CustomizedLoadMetricSpecification' :: Maybe Text
unit = forall a. Maybe a
Prelude.Nothing,
        $sel:metricName:CustomizedLoadMetricSpecification' :: Text
metricName = Text
pMetricName_,
        $sel:namespace:CustomizedLoadMetricSpecification' :: Text
namespace = Text
pNamespace_,
        $sel:statistic:CustomizedLoadMetricSpecification' :: 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 load metric
-- specification.
customizedLoadMetricSpecification_dimensions :: Lens.Lens' CustomizedLoadMetricSpecification (Prelude.Maybe [MetricDimension])
customizedLoadMetricSpecification_dimensions :: Lens' CustomizedLoadMetricSpecification (Maybe [MetricDimension])
customizedLoadMetricSpecification_dimensions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedLoadMetricSpecification' {Maybe [MetricDimension]
dimensions :: Maybe [MetricDimension]
$sel:dimensions:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Maybe [MetricDimension]
dimensions} -> Maybe [MetricDimension]
dimensions) (\s :: CustomizedLoadMetricSpecification
s@CustomizedLoadMetricSpecification' {} Maybe [MetricDimension]
a -> CustomizedLoadMetricSpecification
s {$sel:dimensions:CustomizedLoadMetricSpecification' :: Maybe [MetricDimension]
dimensions = Maybe [MetricDimension]
a} :: CustomizedLoadMetricSpecification) 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.
customizedLoadMetricSpecification_unit :: Lens.Lens' CustomizedLoadMetricSpecification (Prelude.Maybe Prelude.Text)
customizedLoadMetricSpecification_unit :: Lens' CustomizedLoadMetricSpecification (Maybe Text)
customizedLoadMetricSpecification_unit = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedLoadMetricSpecification' {Maybe Text
unit :: Maybe Text
$sel:unit:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Maybe Text
unit} -> Maybe Text
unit) (\s :: CustomizedLoadMetricSpecification
s@CustomizedLoadMetricSpecification' {} Maybe Text
a -> CustomizedLoadMetricSpecification
s {$sel:unit:CustomizedLoadMetricSpecification' :: Maybe Text
unit = Maybe Text
a} :: CustomizedLoadMetricSpecification)

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

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

-- | The statistic of the metric. The only valid value is @Sum@.
customizedLoadMetricSpecification_statistic :: Lens.Lens' CustomizedLoadMetricSpecification MetricStatistic
customizedLoadMetricSpecification_statistic :: Lens' CustomizedLoadMetricSpecification MetricStatistic
customizedLoadMetricSpecification_statistic = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CustomizedLoadMetricSpecification' {MetricStatistic
statistic :: MetricStatistic
$sel:statistic:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> MetricStatistic
statistic} -> MetricStatistic
statistic) (\s :: CustomizedLoadMetricSpecification
s@CustomizedLoadMetricSpecification' {} MetricStatistic
a -> CustomizedLoadMetricSpecification
s {$sel:statistic:CustomizedLoadMetricSpecification' :: MetricStatistic
statistic = MetricStatistic
a} :: CustomizedLoadMetricSpecification)

instance
  Data.FromJSON
    CustomizedLoadMetricSpecification
  where
  parseJSON :: Value -> Parser CustomizedLoadMetricSpecification
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"CustomizedLoadMetricSpecification"
      ( \Object
x ->
          Maybe [MetricDimension]
-> Maybe Text
-> Text
-> Text
-> MetricStatistic
-> CustomizedLoadMetricSpecification
CustomizedLoadMetricSpecification'
            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
    CustomizedLoadMetricSpecification
  where
  hashWithSalt :: Int -> CustomizedLoadMetricSpecification -> Int
hashWithSalt
    Int
_salt
    CustomizedLoadMetricSpecification' {Maybe [MetricDimension]
Maybe Text
Text
MetricStatistic
statistic :: MetricStatistic
namespace :: Text
metricName :: Text
unit :: Maybe Text
dimensions :: Maybe [MetricDimension]
$sel:statistic:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> MetricStatistic
$sel:namespace:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Text
$sel:metricName:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Text
$sel:unit:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Maybe Text
$sel:dimensions:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> 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
    CustomizedLoadMetricSpecification
  where
  rnf :: CustomizedLoadMetricSpecification -> ()
rnf CustomizedLoadMetricSpecification' {Maybe [MetricDimension]
Maybe Text
Text
MetricStatistic
statistic :: MetricStatistic
namespace :: Text
metricName :: Text
unit :: Maybe Text
dimensions :: Maybe [MetricDimension]
$sel:statistic:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> MetricStatistic
$sel:namespace:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Text
$sel:metricName:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Text
$sel:unit:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Maybe Text
$sel:dimensions:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> 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
    CustomizedLoadMetricSpecification
  where
  toJSON :: CustomizedLoadMetricSpecification -> Value
toJSON CustomizedLoadMetricSpecification' {Maybe [MetricDimension]
Maybe Text
Text
MetricStatistic
statistic :: MetricStatistic
namespace :: Text
metricName :: Text
unit :: Maybe Text
dimensions :: Maybe [MetricDimension]
$sel:statistic:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> MetricStatistic
$sel:namespace:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Text
$sel:metricName:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Text
$sel:unit:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> Maybe Text
$sel:dimensions:CustomizedLoadMetricSpecification' :: CustomizedLoadMetricSpecification -> 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)
          ]
      )