추가 사용자 지정 heath 검사를 제공하여 Karaf 서버가 요청을 처리할 준비가 되기 전에 사용자 트래픽을 수신하지 못하도록 할 수 있습니다. 사용자 정의 상태 점검을 활성화하려면 io.fabric8.karaf.checks.HealthChecker 또는 io.fabric8.karaf.checks.ReadinessChecker 인터페이스를 구현하고 해당 오브젝트를 OSGi 레지스트리에 등록해야 합니다.
Copy to ClipboardCopied!Toggle word wrapToggle overflow
참고
OSGi 레지스트리에서 오브젝트를 생성하고 등록하는 가장 간단한 방법은 SCR을 사용하는 것입니다.
예제
다음과 같이 상태 점검을 수행하여 사용 가능한 디스크 공간이 있는지 확인하는 예는 다음과 같습니다.
import io.fabric8.karaf.checks.*;
import org.apache.felix.scr.annotations.*;
import org.apache.commons.io.FileSystemUtils;
import java.util.Collections;
import java.util.List;
@Component(
name = "example.DiskChecker",
immediate = true,
enabled = true,
policy = ConfigurationPolicy.IGNORE,
createPid = false
)
@Service({HealthChecker.class, ReadinessChecker.class})
public class DiskChecker implements HealthChecker, ReadinessChecker {
public List<Check> getFailingReadinessChecks() {
// lets just use the same checks for both readiness and health
return getFailingHeathChecks();
}
public List<Check> getFailingHealthChecks() {
long free = FileSystemUtils.freeSpaceKb("/");
if (free < 1024 * 500) {
return Collections.singletonList(new Check("disk-space-low", "Only " + free + "kb of disk space left."));
}
return Collections.emptyList();
}
}
import io.fabric8.karaf.checks.*;
import org.apache.felix.scr.annotations.*;
import org.apache.commons.io.FileSystemUtils;
import java.util.Collections;
import java.util.List;
@Component(
name = "example.DiskChecker",
immediate = true,
enabled = true,
policy = ConfigurationPolicy.IGNORE,
createPid = false
)
@Service({HealthChecker.class, ReadinessChecker.class})
public class DiskChecker implements HealthChecker, ReadinessChecker {
public List<Check> getFailingReadinessChecks() {
// lets just use the same checks for both readiness and health
return getFailingHeathChecks();
}
public List<Check> getFailingHealthChecks() {
long free = FileSystemUtils.freeSpaceKb("/");
if (free < 1024 * 500) {
return Collections.singletonList(new Check("disk-space-low", "Only " + free + "kb of disk space left."));
}
return Collections.emptyList();
}
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow