Spring boot Actuator란?

  • spring boot application의 상태 모니터링을 도와주는 도구
  • endpoint를 통한 상태 정보 수집 및 각종 metrics 수집 지원
  • JMX 기반의 각종 metrics 수집 지원
  • 각종 모니터링 시스템(CloudWatch, DataDog, Prometheus, Stackdriver...)으로의 Metrics 수집 지원
  • Metric 수집 엔진으로 micrometer를 사용함

적용 배경

  • Spring boot 기반의 API서버 운영중 ELB에서 504(Gateway timeout) 발생
  • Cloudwatch를 통하여 API서버의 로그중 Couchbase와의 쿼리시 Timeout이 발생하는 현상 발견
  • Couchbase의 Connection Pool이 충분하지 않거나 Couchbase Java Client와 Couchbase 서버간의 Connection이 잘 정리 되지 않고 FD를 소모하고 있는것으로 예상
  • API 서버의 Couchbase Client설정에서 Query Connection Pool 설정 및 keepalive, connectiontimeout, querytimeout등의 Connection의 timeout설정을 함으로써 잘못된 프로세스 수행시(timeout이 걸릴 정도면 잘못된 쿼리 or 로직으로 판단) 해당 로직을 중단 하도록 함
  • 위 긴급 조치후 API서버의 fd, jvm, heap, latency등을 모니터링 하기로 함

설정

  • 현재 기본 모니터링 도구로 CloudWatch를 사용중 이므로 모니터링 도구로 CloudWatch Metric을 사용하기로 결정함(구축의 간결함~)
  • spring-cloud-aws + spring-boot-actuator사용시 application.properties 설정만으로 각종 Metrics을 Cloudwatch Metric으로 전송하도록 설정함
  • 아래는 로컬 설정이고 상용 적용시에는 aws credentials설정을 삭제하고 Role기반 설정 필요

application.properties
cloud-aws 설정

spring.cloud.config.enabled=true
cloud.aws.credentials.accessKey=xxxxx
cloud.aws.credentials.secretKey=xxxx
cloud.aws.region.static=xxxx
cloud.aws.region.auto=false
cloud.aws.stack.auto=false

acturtor 설정

management.server.port=8081
management.server.address=localhost
management.endpoints.enabled-by-default=true
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
management.metrics.use-global-registry=false
management.metrics.export.defaults.enabled=false
management.metrics.export.cloudwatch.enabled=true
management.metrics.export.cloudwatch.namespace=local-m5-metrics
management.metrics.export.cloudwatch.batchSize=20
management.metrics.distribution.percentiles-histogram.http.server.requests=true
management.metrics.distribution.sla.http.server.requests=1ms,5ms
management.metrics.web.server.request.autotime.enabled=true
  • CloudWatch Metric의 local-m5-metrics namespace 확인

Metric 모니터링

  • File Descriptor

  • Heap Memory

Endpoint 종류

{
    "_links": {
        "self": {
            "href": "http://localhost:8081/actuator",
            "templated": false
        },
        "beans": {
            "href": "http://localhost:8081/actuator/beans",
            "templated": false
        },
        "caches-cache": {
            "href": "http://localhost:8081/actuator/caches/{cache}",
            "templated": true
        },
        "caches": {
            "href": "http://localhost:8081/actuator/caches",
            "templated": false
        },
        "health-path": {
            "href": "http://localhost:8081/actuator/health/{*path}",
            "templated": true
        },
        "health": {
            "href": "http://localhost:8081/actuator/health",
            "templated": false
        },
        "info": {
            "href": "http://localhost:8081/actuator/info",
            "templated": false
        },
        "conditions": {
            "href": "http://localhost:8081/actuator/conditions",
            "templated": false
        },
        "shutdown": {
            "href": "http://localhost:8081/actuator/shutdown",
            "templated": false
        },
        "configprops": {
            "href": "http://localhost:8081/actuator/configprops",
            "templated": false
        },
        "env": {
            "href": "http://localhost:8081/actuator/env",
            "templated": false
        },
        "env-toMatch": {
            "href": "http://localhost:8081/actuator/env/{toMatch}",
            "templated": true
        },
        "loggers-name": {
            "href": "http://localhost:8081/actuator/loggers/{name}",
            "templated": true
        },
        "loggers": {
            "href": "http://localhost:8081/actuator/loggers",
            "templated": false
        },
        "heapdump": {
            "href": "http://localhost:8081/actuator/heapdump",
            "templated": false
        },
        "threaddump": {
            "href": "http://localhost:8081/actuator/threaddump",
            "templated": false
        },
        "metrics-requiredMetricName": {
            "href": "http://localhost:8081/actuator/metrics/{requiredMetricName}",
            "templated": true
        },
        "metrics": {
            "href": "http://localhost:8081/actuator/metrics",
            "templated": false
        },
        "scheduledtasks": {
            "href": "http://localhost:8081/actuator/scheduledtasks",
            "templated": false
        },
        "mappings": {
            "href": "http://localhost:8081/actuator/mappings",
            "templated": false
        }
    }
}
{
    "status": "UP",
    "components": {
        "couchbase": {
            "status": "UP",
            "details": {
                "sdk": "couchbase-java-client/2.7.16 (git: 2.7.16, core: 1.7.16) (Mac OS X/11.2 x86_64; OpenJDK 64-Bit Server VM 11.0.11+9-LTS)",
                "endpoints": [
                    {
                        "lastActivity": 0,
                        "id": "0x3158541a",
                        "state": "CONNECTED",
                        "remote": "localhost/127.0.0.1:8093",
                        "type": "QUERY",
                        "local": "/127.0.0.1:52905"
                    },
                    
                    ...
                ]
            }
        },
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 499963174912,
                "free": 252911628288,
                "threshold": 10485760
            }
        },
        "ping": {
            "status": "UP"
        }
    }
}

Ref..

profile
안녕

0개의 댓글