You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/05/24 06:02:25 UTC
[GitHub] WillemJiang closed pull request #88: add healthcheck doc
WillemJiang closed pull request #88: add healthcheck doc
URL: https://github.com/apache/incubator-servicecomb-website/pull/88
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/_data/navigation.yml b/_data/navigation.yml
index d4b9b41..80abed9 100755
--- a/_data/navigation.yml
+++ b/_data/navigation.yml
@@ -107,6 +107,8 @@ t:
url: /users/metrics-in-1.0.0-m1/
- title: Metrics-integration-with-prometheus-in-1.0.0-m1
url: /users/metrics-integration-with-prometheus-in-1.0.0-m1/
+ - title: HealthCheck
+ url: /users/healthcheck/
- title: Deployment
children:
@@ -270,6 +272,8 @@ t:
url: /cn/users/metrics-write-file-extension-and-sample-in-1.0.0-m1/
- title: 1.0.0-m1版本中的监控如何集成普罗米修斯
url: /cn/users/metrics-integration-with-prometheus-in-1.0.0-m1/
+ - title: 健康检查
+ url: /cn/users/healthcheck/
- title: 部署
children:
diff --git a/_users/cn/healthcheck.md b/_users/cn/healthcheck.md
new file mode 100644
index 0000000..6eab081
--- /dev/null
+++ b/_users/cn/healthcheck.md
@@ -0,0 +1,84 @@
+---
+title: "健康检查"
+lang: cn
+ref: healthcheck
+permalink: /cn/users/healthcheck/
+excerpt: "健康检查"
+last_modified_at: 2017-12-30T10:01:43-04:00
+redirect_from:
+ - /theme-setup/
+---
+
+{% include toc %}
+微服务框架从1.0.0-m1版本开始支持健康检查。
+
+## 介绍
+微服务往往依赖诸多中间件例如数据库、消息队列等,也依赖其他微服务。当微服务不可用时,例如是由于数据库不可用引起的,我们需要通过日志系统或监控面板将不可用的详细原因记录下或展示出来:磁盘空间满报错?数据库访问用户名密码变更?数据库访问权限变化?而不仅仅是一个报错不可用的状态,这会对快速定位问题和解决故障大有裨益。
+
+健康检查(HealthCheck)提供了一套扩展机制,用户可以自定义检查点,探测微服务内部核心依赖是否可用,如果不可用,将详细信息暴露出来:
+
+
+
+## 如何使用
+### 实现自定义HealthCheck
+Java Chassis HealthCheck使用起来非常简单,只需要继承`org.apache.servicecomb.foundation.metrics.health.HealthChecker`接口,并实现方法:
+
+| 方法名 | 描述 |
+| :---------- | :---------- |
+| getName | 返回此健康检查的名称,请确保名称不要重复,否则从发布获取数据的时候合并覆盖 |
+| check | 具体的检查逻辑实现 |
+
+例如:
+```java
+public class MySqlHealthChecker implements HealthChecker {
+ @Override
+ public String getName() {
+ return "mysql";
+ }
+
+ @Override
+ public HealthCheckResult check() {
+ //add your health check code here
+ Connection connection = null;
+ try {
+ connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_db?useSSL=false", "root", "pwd");
+ return new HealthCheckResult(true, "local mysql health check", "");
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return new HealthCheckResult(false, "local mysql health check", e.toString());
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
+```
+
+然后使用SPI的方式加载它,具体为在`resource/META-INF/services`下创建`org.apache.servicecomb.foundation.metrics.health.HealthChecker`文件,然后写入实现的HealthCheck类名即可,例如:
+
+```text
+org.apache.servicecomb.samples.metrics.extendhealthcheck.MySqlHealthChecker
+```
+
+### 验证实现的HealthCheck
+启动微服务后,HealthCheck默认以Rest方式发布,发布地址与`servicecomb.rest.address`一致,如果在`microservice.yaml`中设置的配置为:
+
+```yaml
+servicecomb:
+ rest:
+ address: 0.0.0.0:8080
+```
+
+那么就可以通过访问http://localhost:8080/health 获取检查结果,以及访问http://localhost:8080/health/detail 获取所有的检查项结果明细。
+
+>说明:
+>1. HealthCheck的默认Rest发布实现在metrics-core中,因此需要增加此依赖;
+>2. /health为所有HealthCheck的最终结果,true或false,只要有任何一个HealthCheck的healthy结果为false,那么就会是false。
+
+## 参考示例
+我们已经提供了一个例子作为参考,代码在samples/metrics-extend-healthcheck中。
\ No newline at end of file
diff --git a/_users/healthcheck.md b/_users/healthcheck.md
new file mode 100644
index 0000000..ae25499
--- /dev/null
+++ b/_users/healthcheck.md
@@ -0,0 +1,84 @@
+---
+title: "HealthCheck"
+lang: en
+ref: healthcheck
+permalink: /users/healthcheck/
+excerpt: "HealthCheck"
+last_modified_at: 2017-12-30T10:01:43-04:00
+redirect_from:
+ - /theme-setup/
+---
+
+{% include toc %}
+Java Chassis had support HealthCheck since 1.0.0-m1.
+
+## Introduction
+Microservice always depend on many middlewares like database, message queue etc. Also depend on other microservices. When microservice is unavailable, may caused by database, we need record details into log file or show details on dashboard: database disk had full? database accress right had invalid? or database accress user and password had changed? not only a DOWN state, details can help dev ops find where is the problem and solve it faster.
+
+HealthCheck provide an extensible mechanism, user can create custom check point in order to probe whether the core dependencies are available, if any one is unavailable, report the details:
+
+
+
+## How to use
+### Implement custom HealthCheck
+It is easy to implement Java Chassis HealthCheck, implements from `org.apache.servicecomb.foundation.metrics.health.HealthChecker` interface and override these methods:
+
+| Method Name | Description |
+| :---------- | :---------- |
+| getName | Return the name of HealthChecker, please make sure do not duplicated, otherwise the results of same name will merged |
+| check | Concrete implementation of Check logic |
+
+Example:
+```java
+public class MySqlHealthChecker implements HealthChecker {
+ @Override
+ public String getName() {
+ return "mysql";
+ }
+
+ @Override
+ public HealthCheckResult check() {
+ //add your health check code here
+ Connection connection = null;
+ try {
+ connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_db?useSSL=false", "root", "pwd");
+ return new HealthCheckResult(true, "local mysql health check", "");
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return new HealthCheckResult(false, "local mysql health check", e.toString());
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
+```
+
+We use SPI to load it, create an new file named `org.apache.servicecomb.foundation.metrics.health.HealthChecker` under `esource/META-INF/services` folder, write class name of your HealthChecker into it, like:
+
+```text
+org.apache.servicecomb.samples.metrics.extendhealthcheck.MySqlHealthChecker
+```
+
+### Verify HealthCheck
+After microservice startup, HealthCheck will publish use Rest endpoint, the publish address is same as `servicecomb.rest.address`, if had configure in `microservice.yaml` like:
+
+```yaml
+servicecomb:
+ rest:
+ address: 0.0.0.0:8080
+```
+
+We can get HealthCheck final result by accress http://localhost:8080/health , also can get detail results by accress http://localhost:8080/health/detail .
+
+>NOTE:
+>1. The implementation of Rest publish is in metrics-core, so need import this dependency;
+>2. The result of /health is the final result of all HealthCheckers, true or false, if healthy result of any HealthChecker return false, then this value will false.
+
+## Other Reference
+We had provided a sample at samples/metrics-extend-healthcheck.
\ No newline at end of file
diff --git a/assets/images/HealthCheck.png b/assets/images/HealthCheck.png
new file mode 100644
index 0000000..dce7bd5
Binary files /dev/null and b/assets/images/HealthCheck.png differ
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services