{-# 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.CloudWatch.Types.MetricStat
-- 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.CloudWatch.Types.MetricStat where

import Amazonka.CloudWatch.Types.Metric
import Amazonka.CloudWatch.Types.StandardUnit
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | This structure defines the metric to be returned, along with the
-- statistics, period, and units.
--
-- /See:/ 'newMetricStat' smart constructor.
data MetricStat = MetricStat'
  { -- | When you are using a @Put@ operation, this defines what unit you want to
    -- use when storing the metric.
    --
    -- In a @Get@ operation, if you omit @Unit@ then all data that was
    -- collected with any unit is returned, along with the corresponding units
    -- that were specified when the data was reported to CloudWatch. If you
    -- specify a unit, the operation returns only data that was collected with
    -- that unit specified. If you specify a unit that does not match the data
    -- collected, the results of the operation are null. CloudWatch does not
    -- perform unit conversions.
    MetricStat -> Maybe StandardUnit
unit :: Prelude.Maybe StandardUnit,
    -- | The metric to return, including the metric name, namespace, and
    -- dimensions.
    MetricStat -> Metric
metric :: Metric,
    -- | The granularity, in seconds, of the returned data points. For metrics
    -- with regular resolution, a period can be as short as one minute (60
    -- seconds) and must be a multiple of 60. For high-resolution metrics that
    -- are collected at intervals of less than one minute, the period can be 1,
    -- 5, 10, 30, 60, or any multiple of 60. High-resolution metrics are those
    -- metrics stored by a @PutMetricData@ call that includes a
    -- @StorageResolution@ of 1 second.
    --
    -- If the @StartTime@ parameter specifies a time stamp that is greater than
    -- 3 hours ago, you must specify the period as follows or no data points in
    -- that time range is returned:
    --
    -- -   Start time between 3 hours and 15 days ago - Use a multiple of 60
    --     seconds (1 minute).
    --
    -- -   Start time between 15 and 63 days ago - Use a multiple of 300
    --     seconds (5 minutes).
    --
    -- -   Start time greater than 63 days ago - Use a multiple of 3600 seconds
    --     (1 hour).
    MetricStat -> Natural
period :: Prelude.Natural,
    -- | The statistic to return. It can include any CloudWatch statistic or
    -- extended statistic.
    MetricStat -> Text
stat :: Prelude.Text
  }
  deriving (MetricStat -> MetricStat -> Bool
(MetricStat -> MetricStat -> Bool)
-> (MetricStat -> MetricStat -> Bool) -> Eq MetricStat
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MetricStat -> MetricStat -> Bool
$c/= :: MetricStat -> MetricStat -> Bool
== :: MetricStat -> MetricStat -> Bool
$c== :: MetricStat -> MetricStat -> Bool
Prelude.Eq, ReadPrec [MetricStat]
ReadPrec MetricStat
Int -> ReadS MetricStat
ReadS [MetricStat]
(Int -> ReadS MetricStat)
-> ReadS [MetricStat]
-> ReadPrec MetricStat
-> ReadPrec [MetricStat]
-> Read MetricStat
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MetricStat]
$creadListPrec :: ReadPrec [MetricStat]
readPrec :: ReadPrec MetricStat
$creadPrec :: ReadPrec MetricStat
readList :: ReadS [MetricStat]
$creadList :: ReadS [MetricStat]
readsPrec :: Int -> ReadS MetricStat
$creadsPrec :: Int -> ReadS MetricStat
Prelude.Read, Int -> MetricStat -> ShowS
[MetricStat] -> ShowS
MetricStat -> String
(Int -> MetricStat -> ShowS)
-> (MetricStat -> String)
-> ([MetricStat] -> ShowS)
-> Show MetricStat
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetricStat] -> ShowS
$cshowList :: [MetricStat] -> ShowS
show :: MetricStat -> String
$cshow :: MetricStat -> String
showsPrec :: Int -> MetricStat -> ShowS
$cshowsPrec :: Int -> MetricStat -> ShowS
Prelude.Show, (forall x. MetricStat -> Rep MetricStat x)
-> (forall x. Rep MetricStat x -> MetricStat) -> Generic MetricStat
forall x. Rep MetricStat x -> MetricStat
forall x. MetricStat -> Rep MetricStat x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MetricStat x -> MetricStat
$cfrom :: forall x. MetricStat -> Rep MetricStat x
Prelude.Generic)

-- |
-- Create a value of 'MetricStat' 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:
--
-- 'unit', 'metricStat_unit' - When you are using a @Put@ operation, this defines what unit you want to
-- use when storing the metric.
--
-- In a @Get@ operation, if you omit @Unit@ then all data that was
-- collected with any unit is returned, along with the corresponding units
-- that were specified when the data was reported to CloudWatch. If you
-- specify a unit, the operation returns only data that was collected with
-- that unit specified. If you specify a unit that does not match the data
-- collected, the results of the operation are null. CloudWatch does not
-- perform unit conversions.
--
-- 'metric', 'metricStat_metric' - The metric to return, including the metric name, namespace, and
-- dimensions.
--
-- 'period', 'metricStat_period' - The granularity, in seconds, of the returned data points. For metrics
-- with regular resolution, a period can be as short as one minute (60
-- seconds) and must be a multiple of 60. For high-resolution metrics that
-- are collected at intervals of less than one minute, the period can be 1,
-- 5, 10, 30, 60, or any multiple of 60. High-resolution metrics are those
-- metrics stored by a @PutMetricData@ call that includes a
-- @StorageResolution@ of 1 second.
--
-- If the @StartTime@ parameter specifies a time stamp that is greater than
-- 3 hours ago, you must specify the period as follows or no data points in
-- that time range is returned:
--
-- -   Start time between 3 hours and 15 days ago - Use a multiple of 60
--     seconds (1 minute).
--
-- -   Start time between 15 and 63 days ago - Use a multiple of 300
--     seconds (5 minutes).
--
-- -   Start time greater than 63 days ago - Use a multiple of 3600 seconds
--     (1 hour).
--
-- 'stat', 'metricStat_stat' - The statistic to return. It can include any CloudWatch statistic or
-- extended statistic.
newMetricStat ::
  -- | 'metric'
  Metric ->
  -- | 'period'
  Prelude.Natural ->
  -- | 'stat'
  Prelude.Text ->
  MetricStat
newMetricStat :: Metric -> Natural -> Text -> MetricStat
newMetricStat Metric
pMetric_ Natural
pPeriod_ Text
pStat_ =
  MetricStat' :: Maybe StandardUnit -> Metric -> Natural -> Text -> MetricStat
MetricStat'
    { $sel:unit:MetricStat' :: Maybe StandardUnit
unit = Maybe StandardUnit
forall a. Maybe a
Prelude.Nothing,
      $sel:metric:MetricStat' :: Metric
metric = Metric
pMetric_,
      $sel:period:MetricStat' :: Natural
period = Natural
pPeriod_,
      $sel:stat:MetricStat' :: Text
stat = Text
pStat_
    }

-- | When you are using a @Put@ operation, this defines what unit you want to
-- use when storing the metric.
--
-- In a @Get@ operation, if you omit @Unit@ then all data that was
-- collected with any unit is returned, along with the corresponding units
-- that were specified when the data was reported to CloudWatch. If you
-- specify a unit, the operation returns only data that was collected with
-- that unit specified. If you specify a unit that does not match the data
-- collected, the results of the operation are null. CloudWatch does not
-- perform unit conversions.
metricStat_unit :: Lens.Lens' MetricStat (Prelude.Maybe StandardUnit)
metricStat_unit :: (Maybe StandardUnit -> f (Maybe StandardUnit))
-> MetricStat -> f MetricStat
metricStat_unit = (MetricStat -> Maybe StandardUnit)
-> (MetricStat -> Maybe StandardUnit -> MetricStat)
-> Lens
     MetricStat MetricStat (Maybe StandardUnit) (Maybe StandardUnit)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricStat' {Maybe StandardUnit
unit :: Maybe StandardUnit
$sel:unit:MetricStat' :: MetricStat -> Maybe StandardUnit
unit} -> Maybe StandardUnit
unit) (\s :: MetricStat
s@MetricStat' {} Maybe StandardUnit
a -> MetricStat
s {$sel:unit:MetricStat' :: Maybe StandardUnit
unit = Maybe StandardUnit
a} :: MetricStat)

-- | The metric to return, including the metric name, namespace, and
-- dimensions.
metricStat_metric :: Lens.Lens' MetricStat Metric
metricStat_metric :: (Metric -> f Metric) -> MetricStat -> f MetricStat
metricStat_metric = (MetricStat -> Metric)
-> (MetricStat -> Metric -> MetricStat)
-> Lens MetricStat MetricStat Metric Metric
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricStat' {Metric
metric :: Metric
$sel:metric:MetricStat' :: MetricStat -> Metric
metric} -> Metric
metric) (\s :: MetricStat
s@MetricStat' {} Metric
a -> MetricStat
s {$sel:metric:MetricStat' :: Metric
metric = Metric
a} :: MetricStat)

-- | The granularity, in seconds, of the returned data points. For metrics
-- with regular resolution, a period can be as short as one minute (60
-- seconds) and must be a multiple of 60. For high-resolution metrics that
-- are collected at intervals of less than one minute, the period can be 1,
-- 5, 10, 30, 60, or any multiple of 60. High-resolution metrics are those
-- metrics stored by a @PutMetricData@ call that includes a
-- @StorageResolution@ of 1 second.
--
-- If the @StartTime@ parameter specifies a time stamp that is greater than
-- 3 hours ago, you must specify the period as follows or no data points in
-- that time range is returned:
--
-- -   Start time between 3 hours and 15 days ago - Use a multiple of 60
--     seconds (1 minute).
--
-- -   Start time between 15 and 63 days ago - Use a multiple of 300
--     seconds (5 minutes).
--
-- -   Start time greater than 63 days ago - Use a multiple of 3600 seconds
--     (1 hour).
metricStat_period :: Lens.Lens' MetricStat Prelude.Natural
metricStat_period :: (Natural -> f Natural) -> MetricStat -> f MetricStat
metricStat_period = (MetricStat -> Natural)
-> (MetricStat -> Natural -> MetricStat)
-> Lens MetricStat MetricStat Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricStat' {Natural
period :: Natural
$sel:period:MetricStat' :: MetricStat -> Natural
period} -> Natural
period) (\s :: MetricStat
s@MetricStat' {} Natural
a -> MetricStat
s {$sel:period:MetricStat' :: Natural
period = Natural
a} :: MetricStat)

-- | The statistic to return. It can include any CloudWatch statistic or
-- extended statistic.
metricStat_stat :: Lens.Lens' MetricStat Prelude.Text
metricStat_stat :: (Text -> f Text) -> MetricStat -> f MetricStat
metricStat_stat = (MetricStat -> Text)
-> (MetricStat -> Text -> MetricStat)
-> Lens MetricStat MetricStat Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MetricStat' {Text
stat :: Text
$sel:stat:MetricStat' :: MetricStat -> Text
stat} -> Text
stat) (\s :: MetricStat
s@MetricStat' {} Text
a -> MetricStat
s {$sel:stat:MetricStat' :: Text
stat = Text
a} :: MetricStat)

instance Core.FromXML MetricStat where
  parseXML :: [Node] -> Either String MetricStat
parseXML [Node]
x =
    Maybe StandardUnit -> Metric -> Natural -> Text -> MetricStat
MetricStat'
      (Maybe StandardUnit -> Metric -> Natural -> Text -> MetricStat)
-> Either String (Maybe StandardUnit)
-> Either String (Metric -> Natural -> Text -> MetricStat)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe StandardUnit)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Unit")
      Either String (Metric -> Natural -> Text -> MetricStat)
-> Either String Metric
-> Either String (Natural -> Text -> MetricStat)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Metric
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Metric")
      Either String (Natural -> Text -> MetricStat)
-> Either String Natural -> Either String (Text -> MetricStat)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Natural
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Period")
      Either String (Text -> MetricStat)
-> Either String Text -> Either String MetricStat
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
"Stat")

instance Prelude.Hashable MetricStat

instance Prelude.NFData MetricStat

instance Core.ToQuery MetricStat where
  toQuery :: MetricStat -> QueryString
toQuery MetricStat' {Natural
Maybe StandardUnit
Text
Metric
stat :: Text
period :: Natural
metric :: Metric
unit :: Maybe StandardUnit
$sel:stat:MetricStat' :: MetricStat -> Text
$sel:period:MetricStat' :: MetricStat -> Natural
$sel:metric:MetricStat' :: MetricStat -> Metric
$sel:unit:MetricStat' :: MetricStat -> Maybe StandardUnit
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Unit" ByteString -> Maybe StandardUnit -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe StandardUnit
unit,
        ByteString
"Metric" ByteString -> Metric -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Metric
metric,
        ByteString
"Period" ByteString -> Natural -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Natural
period,
        ByteString
"Stat" ByteString -> Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Text
stat
      ]