

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Prometheus 지표 쿼리
<a name="AMP-query"></a>

이제 지표가 워크스페이스에 수집되었으므로 쿼리할 수 있습니다.

지표를 시각적으로 표현한 대시보드를 생성하려면 Amazon Managed Grafana와 같은 서비스를 사용할 수 있습니다. Amazon Managed Grafana(또는 독립형 Grafana 인스턴스)는 다양한 디스플레이 프레젠테이션 스타일의 지표를 보여주는 그래픽 인터페이스를 구축할 수 있습니다. Amazon Managed Grafana에 대한 자세한 내용은 [Amazon Managed Grafana 사용 설명서](https://docs.aws.amazon.com/grafana/latest/userguide/)를 참조하세요.

또한 직접 쿼리를 사용하여 일회성 쿼리를 생성하거나, 데이터를 탐색하거나, 지표를 사용하는 자체 애플리케이션을 작성할 수 있습니다. 직접 쿼리는 Amazon Managed Service for Prometheus API와 표준 Prometheus 쿼리 언어인 PromQL을 사용하여 Prometheus 워크스페이스에서 데이터를 가져옵니다. PromQL 및 해당 구문에 대한 자세한 내용은 Prometheus 설명서의 [Prometheus 쿼리](https://prometheus.io/docs/prometheus/latest/querying/basics/)를 참조하세요.

**Topics**
+ [PromQL 치트 시트](#promql-cheat-sheet)
+ [기본 선택기](#promql-basic-selectors)
+ [범위 벡터 선택기](#promql-range-selectors)
+ [집계 연산자](#promql-aggregation-operators)
+ [일반 함수](#promql-functions)
+ [이항 연산자](#promql-operators)
+ [실제 쿼리 예제](#promql-practical-examples)
+ [지표 쿼리 보호](AMP-secure-querying.md)
+ [Amazon Managed Grafana를 Amazon Managed Service for Prometheus와 함께 사용하도록 설정](AMP-amg.md)
+ [Amazon Managed Service for Prometheus와 함께 사용할 Grafana 오픈 소스 또는 Grafana Enterprise를 설정하세요.](AMP-onboard-query-standalone-grafana.md)
+ [Amazon EKS 클러스터에서 실행 중인 Grafana를 사용한 쿼리](AMP-onboard-query-grafana-7.3.md)
+ [Prometheus 호환 API를 사용한 쿼리](AMP-onboard-query-APIs.md)
+ [각 쿼리의 쿼리 사용량에 대한 통계 가져오기](AMP-stats.md)

## PromQL 치트 시트
<a name="promql-cheat-sheet"></a>

Amazon Managed Service for Prometheus 워크스페이스에서 지표를 쿼리할 때 이 PromQL(Prometheus 쿼리 언어) 치트 시트를 빠른 참조 자료로 활용하세요. PromQL을 사용하면 기능적 쿼리 언어를 통해 실시간으로 시계열 데이터를 선택하고 집계할 수 있습니다.

PromQL에 대한 자세한 내용은 PromLabs 웹 사이트에서 [PromQL Cheat Sheet](https://promlabs.com/promql-cheat-sheet/)를 참조하세요.**

## 기본 선택기
<a name="promql-basic-selectors"></a>

지표 이름 및 레이블 매처를 기준으로 시계열을 선택합니다.

```
# Select all time series with the metric name http_requests_total
http_requests_total

# Select time series with specific label values
http_requests_total{job="prometheus", method="GET"}

# Use label matchers
http_requests_total{status_code!="200"}          # Not equal
http_requests_total{status_code=~"2.."}          # Regex match
http_requests_total{status_code!~"4.."}          # Negative regex match
```

## 범위 벡터 선택기
<a name="promql-range-selectors"></a>

시간 경과에 따른 샘플 범위를 선택합니다.

```
# Select 5 minutes of data
http_requests_total[5m]

# Time units: s (seconds), m (minutes), h (hours), d (days), w (weeks), y (years)
cpu_usage[1h]
memory_usage[30s]
```

## 집계 연산자
<a name="promql-aggregation-operators"></a>

여러 시계열에 걸쳐 데이터를 집계합니다.

```
# Sum all values
sum(http_requests_total)

# Sum by specific labels
sum by (job) (http_requests_total)
sum without (instance) (http_requests_total)

# Other aggregation operators
avg(cpu_usage)                    # Average
min(response_time)               # Minimum
max(response_time)               # Maximum
count(up)                        # Count of series
stddev(cpu_usage)               # Standard deviation
```

## 일반 함수
<a name="promql-functions"></a>

함수를 적용하여 데이터를 변환합니다.

```
# Rate of increase per second (for counters)
rate(http_requests_total[5m])

# Increase over time range
increase(http_requests_total[1h])

# Derivative (for gauges)
deriv(cpu_temperature[5m])

# Mathematical functions
abs(cpu_usage - 50)              # Absolute value
round(cpu_usage, 0.1)           # Round to nearest 0.1
sqrt(memory_usage)              # Square root

# Time functions
time()                          # Current Unix timestamp
hour()                          # Hour of day (0-23)
day_of_week()                   # Day of week (0-6, Sunday=0)
```

## 이항 연산자
<a name="promql-operators"></a>

산술 및 논리 연산을 수행합니다.

```
# Arithmetic operators
cpu_usage + 10
memory_total - memory_available
disk_usage / disk_total * 100

# Comparison operators (return 0 or 1)
cpu_usage > 80
memory_usage < 1000
response_time >= 0.5

# Logical operators
(cpu_usage > 80) and (memory_usage > 1000)
(status_code == 200) or (status_code == 201)
```

## 실제 쿼리 예제
<a name="promql-practical-examples"></a>

Amazon Managed Service for Prometheus 워크스페이스에서 사용할 수 있는 일반적인 모니터링 쿼리입니다.

```
# CPU usage percentage
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

# Memory usage percentage
(1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) * 100

# Request rate per second
sum(rate(http_requests_total[5m])) by (job)

# Error rate percentage
sum(rate(http_requests_total{status_code=~"5.."}[5m])) / 
sum(rate(http_requests_total[5m])) * 100

# 95th percentile response time
histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))

# Top 5 instances by CPU usage
topk(5, avg by (instance) (cpu_usage))
```