{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $sel:unit:MetricStat' :: Maybe StandardUnit
unit = 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 :: Lens' MetricStat (Maybe StandardUnit)
metricStat_unit = 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 :: Lens' MetricStat Metric
metricStat_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 :: Lens' MetricStat Natural
metricStat_period = 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 :: Lens' MetricStat Text
metricStat_stat = 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 Data.FromXML MetricStat where
  parseXML :: [Node] -> Either String MetricStat
parseXML [Node]
x =
    Maybe StandardUnit -> Metric -> Natural -> Text -> MetricStat
MetricStat'
      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
"Unit")
      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
"Metric")
      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
"Period")
      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
"Stat")

instance Prelude.Hashable MetricStat where
  hashWithSalt :: Int -> MetricStat -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe StandardUnit
unit
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Metric
metric
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
period
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
stat

instance Prelude.NFData MetricStat where
  rnf :: MetricStat -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe StandardUnit
unit
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Metric
metric
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
period
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
stat

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Unit" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe StandardUnit
unit,
        ByteString
"Metric" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Metric
metric,
        ByteString
"Period" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Natural
period,
        ByteString
"Stat" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Text
stat
      ]