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

import Amazonka.AutoScaling.Types.MetricDimension
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 specific metric.
--
-- /See:/ 'newMetric' smart constructor.
data Metric = Metric'
  { -- | The dimensions for the metric. For the list of available dimensions, see
    -- the Amazon Web Services documentation available from the table in
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-services-cloudwatch-metrics.html Amazon Web Services services that publish CloudWatch metrics>
    -- in the /Amazon CloudWatch User Guide/.
    --
    -- Conditional: If you published your metric with dimensions, you must
    -- specify the same dimensions in your scaling policy.
    Metric -> Maybe [MetricDimension]
dimensions :: Prelude.Maybe [MetricDimension],
    -- | The namespace of the metric. For more information, see the table in
    -- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-services-cloudwatch-metrics.html Amazon Web Services services that publish CloudWatch metrics>
    -- in the /Amazon CloudWatch User Guide/.
    Metric -> Text
namespace :: Prelude.Text,
    -- | The name of the metric.
    Metric -> Text
metricName :: Prelude.Text
  }
  deriving (Metric -> Metric -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Metric -> Metric -> Bool
$c/= :: Metric -> Metric -> Bool
== :: Metric -> Metric -> Bool
$c== :: Metric -> Metric -> Bool
Prelude.Eq, ReadPrec [Metric]
ReadPrec Metric
Int -> ReadS Metric
ReadS [Metric]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Metric]
$creadListPrec :: ReadPrec [Metric]
readPrec :: ReadPrec Metric
$creadPrec :: ReadPrec Metric
readList :: ReadS [Metric]
$creadList :: ReadS [Metric]
readsPrec :: Int -> ReadS Metric
$creadsPrec :: Int -> ReadS Metric
Prelude.Read, Int -> Metric -> ShowS
[Metric] -> ShowS
Metric -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Metric] -> ShowS
$cshowList :: [Metric] -> ShowS
show :: Metric -> String
$cshow :: Metric -> String
showsPrec :: Int -> Metric -> ShowS
$cshowsPrec :: Int -> Metric -> ShowS
Prelude.Show, forall x. Rep Metric x -> Metric
forall x. Metric -> Rep Metric x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Metric x -> Metric
$cfrom :: forall x. Metric -> Rep Metric x
Prelude.Generic)

-- |
-- Create a value of 'Metric' 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', 'metric_dimensions' - The dimensions for the metric. For the list of available dimensions, see
-- the Amazon Web Services documentation available from the table in
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-services-cloudwatch-metrics.html Amazon Web Services services that publish CloudWatch metrics>
-- in the /Amazon CloudWatch User Guide/.
--
-- Conditional: If you published your metric with dimensions, you must
-- specify the same dimensions in your scaling policy.
--
-- 'namespace', 'metric_namespace' - The namespace of the metric. For more information, see the table in
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-services-cloudwatch-metrics.html Amazon Web Services services that publish CloudWatch metrics>
-- in the /Amazon CloudWatch User Guide/.
--
-- 'metricName', 'metric_metricName' - The name of the metric.
newMetric ::
  -- | 'namespace'
  Prelude.Text ->
  -- | 'metricName'
  Prelude.Text ->
  Metric
newMetric :: Text -> Text -> Metric
newMetric Text
pNamespace_ Text
pMetricName_ =
  Metric'
    { $sel:dimensions:Metric' :: Maybe [MetricDimension]
dimensions = forall a. Maybe a
Prelude.Nothing,
      $sel:namespace:Metric' :: Text
namespace = Text
pNamespace_,
      $sel:metricName:Metric' :: Text
metricName = Text
pMetricName_
    }

-- | The dimensions for the metric. For the list of available dimensions, see
-- the Amazon Web Services documentation available from the table in
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-services-cloudwatch-metrics.html Amazon Web Services services that publish CloudWatch metrics>
-- in the /Amazon CloudWatch User Guide/.
--
-- Conditional: If you published your metric with dimensions, you must
-- specify the same dimensions in your scaling policy.
metric_dimensions :: Lens.Lens' Metric (Prelude.Maybe [MetricDimension])
metric_dimensions :: Lens' Metric (Maybe [MetricDimension])
metric_dimensions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {Maybe [MetricDimension]
dimensions :: Maybe [MetricDimension]
$sel:dimensions:Metric' :: Metric -> Maybe [MetricDimension]
dimensions} -> Maybe [MetricDimension]
dimensions) (\s :: Metric
s@Metric' {} Maybe [MetricDimension]
a -> Metric
s {$sel:dimensions:Metric' :: Maybe [MetricDimension]
dimensions = Maybe [MetricDimension]
a} :: Metric) 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 namespace of the metric. For more information, see the table in
-- <https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/aws-services-cloudwatch-metrics.html Amazon Web Services services that publish CloudWatch metrics>
-- in the /Amazon CloudWatch User Guide/.
metric_namespace :: Lens.Lens' Metric Prelude.Text
metric_namespace :: Lens' Metric Text
metric_namespace = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metric' {Text
namespace :: Text
$sel:namespace:Metric' :: Metric -> Text
namespace} -> Text
namespace) (\s :: Metric
s@Metric' {} Text
a -> Metric
s {$sel:namespace:Metric' :: Text
namespace = Text
a} :: Metric)

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

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

instance Prelude.Hashable Metric where
  hashWithSalt :: Int -> Metric -> Int
hashWithSalt Int
_salt Metric' {Maybe [MetricDimension]
Text
metricName :: Text
namespace :: Text
dimensions :: Maybe [MetricDimension]
$sel:metricName:Metric' :: Metric -> Text
$sel:namespace:Metric' :: Metric -> Text
$sel:dimensions:Metric' :: Metric -> 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` Text
namespace
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
metricName

instance Prelude.NFData Metric where
  rnf :: Metric -> ()
rnf Metric' {Maybe [MetricDimension]
Text
metricName :: Text
namespace :: Text
dimensions :: Maybe [MetricDimension]
$sel:metricName:Metric' :: Metric -> Text
$sel:namespace:Metric' :: Metric -> Text
$sel:dimensions:Metric' :: Metric -> 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 Text
namespace
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
metricName

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