| 1 | /* |
| 2 | * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | * You may not use this file except in compliance with the License. |
| 6 | * A copy of the License is located at |
| 7 | * |
| 8 | * http://aws.amazon.com/apache2.0 |
| 9 | * |
| 10 | * or in the "license" file accompanying this file. This file is distributed |
| 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | * express or implied. See the License for the specific language governing |
| 13 | * permissions and limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <aws/core/utils/HashingUtils.h> |
| 17 | #include <aws/core/monitoring/HttpClientMetrics.h> |
| 18 | |
| 19 | namespace Aws |
| 20 | { |
| 21 | namespace Monitoring |
| 22 | { |
| 23 | static const char HTTP_CLIENT_METRICS_DESTINATIONIP[] = "DestinationIp" ; |
| 24 | static const char HTTP_CLIENT_METRICS_ACQUIRE_CONNECTION_LATENCY[] = "AcquireConnectionLatency" ; |
| 25 | static const char HTTP_CLIENT_METRICS_CONNECTION_REUSED[] = "ConnectionReused" ; |
| 26 | static const char HTTP_CLIENT_METRICS_CONNECTION_LATENCY[] = "ConnectLatency" ; |
| 27 | static const char HTTP_CLIENT_METRICS_REQUEST_LATENCY[] = "RequestLatency" ; |
| 28 | static const char HTTP_CLIENT_METRICS_DNS_LATENCY[] = "DnsLatency" ; |
| 29 | static const char HTTP_CLIENT_METRICS_TCP_LEATENCY[] = "TcpLatency" ; |
| 30 | static const char HTTP_CLIENT_METRICS_SSL_LATENCY[] = "SslLatency" ; |
| 31 | static const char HTTP_CLIENT_METRICS_UNKNOWN[] = "Unknown" ; |
| 32 | |
| 33 | using namespace Aws::Utils; |
| 34 | HttpClientMetricsType GetHttpClientMetricTypeByName(const Aws::String& name) |
| 35 | { |
| 36 | static std::map<int, HttpClientMetricsType> metricsNameHashToType = |
| 37 | { |
| 38 | std::pair<int, HttpClientMetricsType>(HashingUtils::HashString(HTTP_CLIENT_METRICS_DESTINATIONIP), HttpClientMetricsType::DestinationIp), |
| 39 | std::pair<int, HttpClientMetricsType>(HashingUtils::HashString(HTTP_CLIENT_METRICS_ACQUIRE_CONNECTION_LATENCY), HttpClientMetricsType::AcquireConnectionLatency), |
| 40 | std::pair<int, HttpClientMetricsType>(HashingUtils::HashString(HTTP_CLIENT_METRICS_CONNECTION_REUSED), HttpClientMetricsType::ConnectionReused), |
| 41 | std::pair<int, HttpClientMetricsType>(HashingUtils::HashString(HTTP_CLIENT_METRICS_CONNECTION_LATENCY), HttpClientMetricsType::ConnectLatency), |
| 42 | std::pair<int, HttpClientMetricsType>(HashingUtils::HashString(HTTP_CLIENT_METRICS_REQUEST_LATENCY), HttpClientMetricsType::RequestLatency), |
| 43 | std::pair<int, HttpClientMetricsType>(HashingUtils::HashString(HTTP_CLIENT_METRICS_DNS_LATENCY), HttpClientMetricsType::DnsLatency), |
| 44 | std::pair<int, HttpClientMetricsType>(HashingUtils::HashString(HTTP_CLIENT_METRICS_TCP_LEATENCY), HttpClientMetricsType::TcpLatency), |
| 45 | std::pair<int, HttpClientMetricsType>(HashingUtils::HashString(HTTP_CLIENT_METRICS_SSL_LATENCY), HttpClientMetricsType::SslLatency) |
| 46 | }; |
| 47 | |
| 48 | int nameHash = HashingUtils::HashString(name.c_str()); |
| 49 | auto it = metricsNameHashToType.find(nameHash); |
| 50 | if (it == metricsNameHashToType.end()) |
| 51 | { |
| 52 | return HttpClientMetricsType::Unknown; |
| 53 | } |
| 54 | return it->second; |
| 55 | } |
| 56 | |
| 57 | Aws::String GetHttpClientMetricNameByType(HttpClientMetricsType type) |
| 58 | { |
| 59 | static std::map<int, std::string> metricsTypeToName = |
| 60 | { |
| 61 | std::pair<int, std::string>(static_cast<int>(HttpClientMetricsType::DestinationIp), HTTP_CLIENT_METRICS_DESTINATIONIP), |
| 62 | std::pair<int, std::string>(static_cast<int>(HttpClientMetricsType::AcquireConnectionLatency), HTTP_CLIENT_METRICS_ACQUIRE_CONNECTION_LATENCY), |
| 63 | std::pair<int, std::string>(static_cast<int>(HttpClientMetricsType::ConnectionReused), HTTP_CLIENT_METRICS_CONNECTION_REUSED), |
| 64 | std::pair<int, std::string>(static_cast<int>(HttpClientMetricsType::ConnectLatency), HTTP_CLIENT_METRICS_CONNECTION_LATENCY), |
| 65 | std::pair<int, std::string>(static_cast<int>(HttpClientMetricsType::RequestLatency), HTTP_CLIENT_METRICS_REQUEST_LATENCY), |
| 66 | std::pair<int, std::string>(static_cast<int>(HttpClientMetricsType::DnsLatency), HTTP_CLIENT_METRICS_DNS_LATENCY), |
| 67 | std::pair<int, std::string>(static_cast<int>(HttpClientMetricsType::TcpLatency), HTTP_CLIENT_METRICS_TCP_LEATENCY), |
| 68 | std::pair<int, std::string>(static_cast<int>(HttpClientMetricsType::SslLatency), HTTP_CLIENT_METRICS_SSL_LATENCY), |
| 69 | std::pair<int, std::string>(static_cast<int>(HttpClientMetricsType::Unknown), HTTP_CLIENT_METRICS_UNKNOWN) |
| 70 | }; |
| 71 | |
| 72 | auto it = metricsTypeToName.find(static_cast<int>(type)); |
| 73 | if (it == metricsTypeToName.end()) |
| 74 | { |
| 75 | return HTTP_CLIENT_METRICS_UNKNOWN; |
| 76 | } |
| 77 | return Aws::String(it->second.c_str()); |
| 78 | } |
| 79 | |
| 80 | } |
| 81 | } |
| 82 | |