{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE RecordWildCards    #-}
{-# LANGUAGE TypeFamilies       #-}

{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-binds   #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Network.AWS.Lightsail.GetLoadBalancerMetricData
-- Copyright   : (c) 2013-2018 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)
--
-- Returns information about health metrics for your Lightsail load balancer.
--
--
module Network.AWS.Lightsail.GetLoadBalancerMetricData
    (
    -- * Creating a Request
      getLoadBalancerMetricData
    , GetLoadBalancerMetricData
    -- * Request Lenses
    , glbmdLoadBalancerName
    , glbmdMetricName
    , glbmdPeriod
    , glbmdStartTime
    , glbmdEndTime
    , glbmdUnit
    , glbmdStatistics

    -- * Destructuring the Response
    , getLoadBalancerMetricDataResponse
    , GetLoadBalancerMetricDataResponse
    -- * Response Lenses
    , glbmdrsMetricName
    , glbmdrsMetricData
    , glbmdrsResponseStatus
    ) where

import Network.AWS.Lens
import Network.AWS.Lightsail.Types
import Network.AWS.Lightsail.Types.Product
import Network.AWS.Prelude
import Network.AWS.Request
import Network.AWS.Response

-- | /See:/ 'getLoadBalancerMetricData' smart constructor.
data GetLoadBalancerMetricData = GetLoadBalancerMetricData'
  { _glbmdLoadBalancerName :: !Text
  , _glbmdMetricName       :: !LoadBalancerMetricName
  , _glbmdPeriod           :: !Nat
  , _glbmdStartTime        :: !POSIX
  , _glbmdEndTime          :: !POSIX
  , _glbmdUnit             :: !MetricUnit
  , _glbmdStatistics       :: ![MetricStatistic]
  } deriving (Eq, Read, Show, Data, Typeable, Generic)


-- | Creates a value of 'GetLoadBalancerMetricData' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'glbmdLoadBalancerName' - The name of the load balancer.
--
-- * 'glbmdMetricName' - The metric about which you want to return information. Valid values are listed below, along with the most useful @statistics@ to include in your request.     * __@ClientTLSNegotiationErrorCount@ __ - The number of TLS connections initiated by the client that did not establish a session with the load balancer. Possible causes include a mismatch of ciphers or protocols. @Statistics@ : The most useful statistic is @Sum@ .     * __@HealthyHostCount@ __ - The number of target instances that are considered healthy. @Statistics@ : The most useful statistic are @Average@ , @Minimum@ , and @Maximum@ .     * __@UnhealthyHostCount@ __ - The number of target instances that are considered unhealthy. @Statistics@ : The most useful statistic are @Average@ , @Minimum@ , and @Maximum@ .     * __@HTTPCode_LB_4XX_Count@ __ - The number of HTTP 4XX client error codes that originate from the load balancer. Client errors are generated when requests are malformed or incomplete. These requests have not been received by the target instance. This count does not include any response codes generated by the target instances. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_LB_5XX_Count@ __ - The number of HTTP 5XX server error codes that originate from the load balancer. This count does not include any response codes generated by the target instances. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_2XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_3XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer.  @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_4XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_5XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@InstanceResponseTime@ __ - The time elapsed, in seconds, after the request leaves the load balancer until a response from the target instance is received. @Statistics@ : The most useful statistic is @Average@ .     * __@RejectedConnectionCount@ __ - The number of connections that were rejected because the load balancer had reached its maximum number of connections. @Statistics@ : The most useful statistic is @Sum@ .     * __@RequestCount@ __ - The number of requests processed over IPv4. This count includes only the requests with a response generated by a target instance of the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .
--
-- * 'glbmdPeriod' - The time period duration for your health data request.
--
-- * 'glbmdStartTime' - The start time of the period.
--
-- * 'glbmdEndTime' - The end time of the period.
--
-- * 'glbmdUnit' - The unit for the time period request. Valid values are listed below.
--
-- * 'glbmdStatistics' - An array of statistics that you want to request metrics for. Valid values are listed below.     * __@SampleCount@ __ - The count (number) of data points used for the statistical calculation.     * __@Average@ __ - The value of Sum / SampleCount during the specified period. By comparing this statistic with the Minimum and Maximum, you can determine the full scope of a metric and how close the average use is to the Minimum and Maximum. This comparison helps you to know when to increase or decrease your resources as needed.     * __@Sum@ __ - All values submitted for the matching metric added together. This statistic can be useful for determining the total volume of a metric.     * __@Minimum@ __ - The lowest value observed during the specified period. You can use this value to determine low volumes of activity for your application.     * __@Maximum@ __ - The highest value observed during the specified period. You can use this value to determine high volumes of activity for your application.
getLoadBalancerMetricData
    :: Text -- ^ 'glbmdLoadBalancerName'
    -> LoadBalancerMetricName -- ^ 'glbmdMetricName'
    -> Natural -- ^ 'glbmdPeriod'
    -> UTCTime -- ^ 'glbmdStartTime'
    -> UTCTime -- ^ 'glbmdEndTime'
    -> MetricUnit -- ^ 'glbmdUnit'
    -> GetLoadBalancerMetricData
getLoadBalancerMetricData pLoadBalancerName_ pMetricName_ pPeriod_ pStartTime_ pEndTime_ pUnit_ =
  GetLoadBalancerMetricData'
    { _glbmdLoadBalancerName = pLoadBalancerName_
    , _glbmdMetricName = pMetricName_
    , _glbmdPeriod = _Nat # pPeriod_
    , _glbmdStartTime = _Time # pStartTime_
    , _glbmdEndTime = _Time # pEndTime_
    , _glbmdUnit = pUnit_
    , _glbmdStatistics = mempty
    }


-- | The name of the load balancer.
glbmdLoadBalancerName :: Lens' GetLoadBalancerMetricData Text
glbmdLoadBalancerName = lens _glbmdLoadBalancerName (\ s a -> s{_glbmdLoadBalancerName = a})

-- | The metric about which you want to return information. Valid values are listed below, along with the most useful @statistics@ to include in your request.     * __@ClientTLSNegotiationErrorCount@ __ - The number of TLS connections initiated by the client that did not establish a session with the load balancer. Possible causes include a mismatch of ciphers or protocols. @Statistics@ : The most useful statistic is @Sum@ .     * __@HealthyHostCount@ __ - The number of target instances that are considered healthy. @Statistics@ : The most useful statistic are @Average@ , @Minimum@ , and @Maximum@ .     * __@UnhealthyHostCount@ __ - The number of target instances that are considered unhealthy. @Statistics@ : The most useful statistic are @Average@ , @Minimum@ , and @Maximum@ .     * __@HTTPCode_LB_4XX_Count@ __ - The number of HTTP 4XX client error codes that originate from the load balancer. Client errors are generated when requests are malformed or incomplete. These requests have not been received by the target instance. This count does not include any response codes generated by the target instances. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_LB_5XX_Count@ __ - The number of HTTP 5XX server error codes that originate from the load balancer. This count does not include any response codes generated by the target instances. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_2XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_3XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer.  @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_4XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_5XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@InstanceResponseTime@ __ - The time elapsed, in seconds, after the request leaves the load balancer until a response from the target instance is received. @Statistics@ : The most useful statistic is @Average@ .     * __@RejectedConnectionCount@ __ - The number of connections that were rejected because the load balancer had reached its maximum number of connections. @Statistics@ : The most useful statistic is @Sum@ .     * __@RequestCount@ __ - The number of requests processed over IPv4. This count includes only the requests with a response generated by a target instance of the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .
glbmdMetricName :: Lens' GetLoadBalancerMetricData LoadBalancerMetricName
glbmdMetricName = lens _glbmdMetricName (\ s a -> s{_glbmdMetricName = a})

-- | The time period duration for your health data request.
glbmdPeriod :: Lens' GetLoadBalancerMetricData Natural
glbmdPeriod = lens _glbmdPeriod (\ s a -> s{_glbmdPeriod = a}) . _Nat

-- | The start time of the period.
glbmdStartTime :: Lens' GetLoadBalancerMetricData UTCTime
glbmdStartTime = lens _glbmdStartTime (\ s a -> s{_glbmdStartTime = a}) . _Time

-- | The end time of the period.
glbmdEndTime :: Lens' GetLoadBalancerMetricData UTCTime
glbmdEndTime = lens _glbmdEndTime (\ s a -> s{_glbmdEndTime = a}) . _Time

-- | The unit for the time period request. Valid values are listed below.
glbmdUnit :: Lens' GetLoadBalancerMetricData MetricUnit
glbmdUnit = lens _glbmdUnit (\ s a -> s{_glbmdUnit = a})

-- | An array of statistics that you want to request metrics for. Valid values are listed below.     * __@SampleCount@ __ - The count (number) of data points used for the statistical calculation.     * __@Average@ __ - The value of Sum / SampleCount during the specified period. By comparing this statistic with the Minimum and Maximum, you can determine the full scope of a metric and how close the average use is to the Minimum and Maximum. This comparison helps you to know when to increase or decrease your resources as needed.     * __@Sum@ __ - All values submitted for the matching metric added together. This statistic can be useful for determining the total volume of a metric.     * __@Minimum@ __ - The lowest value observed during the specified period. You can use this value to determine low volumes of activity for your application.     * __@Maximum@ __ - The highest value observed during the specified period. You can use this value to determine high volumes of activity for your application.
glbmdStatistics :: Lens' GetLoadBalancerMetricData [MetricStatistic]
glbmdStatistics = lens _glbmdStatistics (\ s a -> s{_glbmdStatistics = a}) . _Coerce

instance AWSRequest GetLoadBalancerMetricData where
        type Rs GetLoadBalancerMetricData =
             GetLoadBalancerMetricDataResponse
        request = postJSON lightsail
        response
          = receiveJSON
              (\ s h x ->
                 GetLoadBalancerMetricDataResponse' <$>
                   (x .?> "metricName") <*>
                     (x .?> "metricData" .!@ mempty)
                     <*> (pure (fromEnum s)))

instance Hashable GetLoadBalancerMetricData where

instance NFData GetLoadBalancerMetricData where

instance ToHeaders GetLoadBalancerMetricData where
        toHeaders
          = const
              (mconcat
                 ["X-Amz-Target" =#
                    ("Lightsail_20161128.GetLoadBalancerMetricData" ::
                       ByteString),
                  "Content-Type" =#
                    ("application/x-amz-json-1.1" :: ByteString)])

instance ToJSON GetLoadBalancerMetricData where
        toJSON GetLoadBalancerMetricData'{..}
          = object
              (catMaybes
                 [Just ("loadBalancerName" .= _glbmdLoadBalancerName),
                  Just ("metricName" .= _glbmdMetricName),
                  Just ("period" .= _glbmdPeriod),
                  Just ("startTime" .= _glbmdStartTime),
                  Just ("endTime" .= _glbmdEndTime),
                  Just ("unit" .= _glbmdUnit),
                  Just ("statistics" .= _glbmdStatistics)])

instance ToPath GetLoadBalancerMetricData where
        toPath = const "/"

instance ToQuery GetLoadBalancerMetricData where
        toQuery = const mempty

-- | /See:/ 'getLoadBalancerMetricDataResponse' smart constructor.
data GetLoadBalancerMetricDataResponse = GetLoadBalancerMetricDataResponse'
  { _glbmdrsMetricName     :: !(Maybe LoadBalancerMetricName)
  , _glbmdrsMetricData     :: !(Maybe [MetricDatapoint])
  , _glbmdrsResponseStatus :: !Int
  } deriving (Eq, Read, Show, Data, Typeable, Generic)


-- | Creates a value of 'GetLoadBalancerMetricDataResponse' with the minimum fields required to make a request.
--
-- Use one of the following lenses to modify other fields as desired:
--
-- * 'glbmdrsMetricName' - The metric about which you are receiving information. Valid values are listed below, along with the most useful @statistics@ to include in your request.     * __@ClientTLSNegotiationErrorCount@ __ - The number of TLS connections initiated by the client that did not establish a session with the load balancer. Possible causes include a mismatch of ciphers or protocols. @Statistics@ : The most useful statistic is @Sum@ .     * __@HealthyHostCount@ __ - The number of target instances that are considered healthy. @Statistics@ : The most useful statistic are @Average@ , @Minimum@ , and @Maximum@ .     * __@UnhealthyHostCount@ __ - The number of target instances that are considered unhealthy. @Statistics@ : The most useful statistic are @Average@ , @Minimum@ , and @Maximum@ .     * __@HTTPCode_LB_4XX_Count@ __ - The number of HTTP 4XX client error codes that originate from the load balancer. Client errors are generated when requests are malformed or incomplete. These requests have not been received by the target instance. This count does not include any response codes generated by the target instances. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_LB_5XX_Count@ __ - The number of HTTP 5XX server error codes that originate from the load balancer. This count does not include any response codes generated by the target instances. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_2XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_3XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer.  @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_4XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_5XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@InstanceResponseTime@ __ - The time elapsed, in seconds, after the request leaves the load balancer until a response from the target instance is received. @Statistics@ : The most useful statistic is @Average@ .     * __@RejectedConnectionCount@ __ - The number of connections that were rejected because the load balancer had reached its maximum number of connections. @Statistics@ : The most useful statistic is @Sum@ .     * __@RequestCount@ __ - The number of requests processed over IPv4. This count includes only the requests with a response generated by a target instance of the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .
--
-- * 'glbmdrsMetricData' - An array of metric datapoint objects.
--
-- * 'glbmdrsResponseStatus' - -- | The response status code.
getLoadBalancerMetricDataResponse
    :: Int -- ^ 'glbmdrsResponseStatus'
    -> GetLoadBalancerMetricDataResponse
getLoadBalancerMetricDataResponse pResponseStatus_ =
  GetLoadBalancerMetricDataResponse'
    { _glbmdrsMetricName = Nothing
    , _glbmdrsMetricData = Nothing
    , _glbmdrsResponseStatus = pResponseStatus_
    }


-- | The metric about which you are receiving information. Valid values are listed below, along with the most useful @statistics@ to include in your request.     * __@ClientTLSNegotiationErrorCount@ __ - The number of TLS connections initiated by the client that did not establish a session with the load balancer. Possible causes include a mismatch of ciphers or protocols. @Statistics@ : The most useful statistic is @Sum@ .     * __@HealthyHostCount@ __ - The number of target instances that are considered healthy. @Statistics@ : The most useful statistic are @Average@ , @Minimum@ , and @Maximum@ .     * __@UnhealthyHostCount@ __ - The number of target instances that are considered unhealthy. @Statistics@ : The most useful statistic are @Average@ , @Minimum@ , and @Maximum@ .     * __@HTTPCode_LB_4XX_Count@ __ - The number of HTTP 4XX client error codes that originate from the load balancer. Client errors are generated when requests are malformed or incomplete. These requests have not been received by the target instance. This count does not include any response codes generated by the target instances. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_LB_5XX_Count@ __ - The number of HTTP 5XX server error codes that originate from the load balancer. This count does not include any response codes generated by the target instances. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_2XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_3XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer.  @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_4XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@HTTPCode_Instance_5XX_Count@ __ - The number of HTTP response codes generated by the target instances. This does not include any response codes generated by the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .     * __@InstanceResponseTime@ __ - The time elapsed, in seconds, after the request leaves the load balancer until a response from the target instance is received. @Statistics@ : The most useful statistic is @Average@ .     * __@RejectedConnectionCount@ __ - The number of connections that were rejected because the load balancer had reached its maximum number of connections. @Statistics@ : The most useful statistic is @Sum@ .     * __@RequestCount@ __ - The number of requests processed over IPv4. This count includes only the requests with a response generated by a target instance of the load balancer. @Statistics@ : The most useful statistic is @Sum@ . Note that @Minimum@ , @Maximum@ , and @Average@ all return @1@ .
glbmdrsMetricName :: Lens' GetLoadBalancerMetricDataResponse (Maybe LoadBalancerMetricName)
glbmdrsMetricName = lens _glbmdrsMetricName (\ s a -> s{_glbmdrsMetricName = a})

-- | An array of metric datapoint objects.
glbmdrsMetricData :: Lens' GetLoadBalancerMetricDataResponse [MetricDatapoint]
glbmdrsMetricData = lens _glbmdrsMetricData (\ s a -> s{_glbmdrsMetricData = a}) . _Default . _Coerce

-- | -- | The response status code.
glbmdrsResponseStatus :: Lens' GetLoadBalancerMetricDataResponse Int
glbmdrsResponseStatus = lens _glbmdrsResponseStatus (\ s a -> s{_glbmdrsResponseStatus = a})

instance NFData GetLoadBalancerMetricDataResponse
         where