카테고리 없음

aws grafana, prometheus 구성_8_B계정 모니터링_2

plli 2025. 5. 30. 16:20

이번엔 B계정의 RDS, Elasticache 모니터링을 한다.

 

RDS 

cp -r a_acount_rds/ b_acount_rds
vi b_acount_rds/config.yml

이전에 생성한 b_acount_ec2의 config.yml 에서 role 을 복붙한다.
아래 매트릭 말고 다른 매트릭도 수집 가능하다.

region: us-west-2
role_arn: arn:aws:iam::B 계정 acount_id:role/A-B_Assume_Role
metrics:
- aws_dimensions:
  - DBInstanceIdentifier
  aws_metric_name: FreeStorageSpace
  aws_namespace: AWS/RDS
  aws_statistics:
  - Average
- aws_dimensions:
  - DBInstanceIdentifier
  aws_metric_name: FreeableMemory
  aws_namespace: AWS/RDS
  aws_statistics:
  - Average
- aws_dimensions:
  - DBInstanceIdentifier
  aws_metric_name: CPUUtilization
  aws_namespace: AWS/RDS
  aws_statistics:
  - Average
cd b_acount_rds
docker build -t b_acount_rds:v1 .
docker run -d -p 9010:9106 --name b_acount_rds b_acount_rds:v1
docker inspect b_acount_rds | grep IPAddress

 

Cache

cp -r a_acount_cache/ b_acount_cache
vi b_acount_cache/config.yml

이전에 생성한 b_acount_ec2의 config.yml 에서 role 을 복붙한다.
아래 매트릭 말고 다른 매트릭도 수집 가능하다.

region: us-west-2
role_arn: arn:aws:iam::B 계정 acount_id :role/A-B_Assume_Role

metrics:
- aws_dimensions:
  - CacheNodeId
  - CacheClusterId
  aws_metric_name: CPUUtilization
  aws_namespace: AWS/ElastiCache
  aws_statistics:
  - Average
- aws_dimensions:
  - CacheNodeId
  - CacheClusterId
  aws_metric_name: FreeableMemory
  aws_namespace: AWS/ElastiCache
  aws_statistics:
  - Average

 

cd b_acount_rds
docker build -t b_acount_cache:v1 .
docker run -d -p 9011:9106 --name b_acount_cache b_acount_cache:v1
docker inspect b_acount_cache | grep IPAddress

 

Prometheus 수정

global:
  scrape_interval: 1m
  evaluation_interval: 1m

scrape_configs:
  - job_name: 'a_acount_ec2'
    static_configs:
      - targets: ['172.17.0.2:9106']
    metric_relabel_configs:
      - source_labels: [tag_Name]
        target_label: instance_name

  - job_name: 'a_acount_rds'
    static_configs:
      - targets: ['172.17.0.5:9106']

  - job_name: 'a_acount_cache'
    static_configs:
      - targets: ['172.17.0.6:9106']

  - job_name: 'b_acount_ec2'
    static_configs:
      - targets: ['172.17.0.7:9106']
    metric_relabel_configs:
      - source_labels: [tag_Name]
        target_label: instance_name
        
#### rds, cache 추가        
  - job_name: 'b_acount_rds'
    static_configs:
      - targets: ['172.17.0.8:9106']

  - job_name: 'b_acount_cache'
    static_configs:
      - targets: ['172.17.0.9:9106']

 

 

그라파나

a_count_rds, a_count_cache 를 각각 복사한 후 패널의 code 값을 수정한다.

# rds cpu / 이름에 test 가 들어간 rds 의 cpu 모니터링
aws_rds_cpuutilization_average{dbinstance_identifier=~"(test).*"}

# rds mem
cwagent_mem_used_percent_average * on(instance_id) group_left(instance_name, tag_Name) (
  max by (instance_id, instance_name, tag_Name) (aws_resource_info{instance_name=~"(test).*"})
)

# rds free storage
cwagent_disk_used_percent_average * on(instance_id) group_left(instance_name, tag_Name) (
  max by (instance_id, instance_name, tag_Name) (aws_resource_info{instance_name=~"(test).*"})
)

########################################################################

# cache cpu / 이름에 test 가 들어간 cache 의 cpu 모니터링
aws_elasticache_cpuutilization_average{job="test"}

# cache mem
aws_elasticache_freeable_memory_average{job="mobi_fb_cache"}