eagle-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinh...@apache.org
Subject incubator-eagle git commit: [MINOR] optimize health check: add some information
Date Thu, 24 Nov 2016 04:35:12 GMT
Repository: incubator-eagle
Updated Branches:
  refs/heads/master adeaa0f9e -> 3becca689


[MINOR] optimize health check: add some information

Author: wujinhu <wujinhu920@126.com>

Closes #679 from wujinhu/healthFix.


Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/3becca68
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/3becca68
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/3becca68

Branch: refs/heads/master
Commit: 3becca68929cd005416605da0b9be4cbdb0c0cba
Parents: adeaa0f
Author: wujinhu <wujinhu920@126.com>
Authored: Thu Nov 24 12:35:05 2016 +0800
Committer: wujinhu <wujinhu920@126.com>
Committed: Thu Nov 24 12:35:05 2016 +0800

----------------------------------------------------------------------
 .../ApplicationHealthCheckEmailPublisher.java   | 29 ++++++++++++++++++--
 .../impl/ApplicationHealthCheckServiceImpl.java |  4 +--
 .../src/main/resources/application.conf         |  1 -
 3 files changed, 29 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3becca68/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckEmailPublisher.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckEmailPublisher.java
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckEmailPublisher.java
index c7d7e0f..8374b38 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckEmailPublisher.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckEmailPublisher.java
@@ -26,6 +26,7 @@ import org.apache.velocity.VelocityContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.net.InetAddress;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -72,8 +73,15 @@ public class ApplicationHealthCheckEmailPublisher implements ApplicationHealthCh
 
                 final VelocityContext context = new VelocityContext();
                 Map<String, String> appMsgs = new HashMap<>();
+                int unhealthyCount = 0;
+                int healthyCount = 0;
                 for (String appId : results.keySet()) {
                     appMsgs.put(appId, results.get(appId).getMessage());
+                    if (!results.get(appId).isHealthy()) {
+                        unhealthyCount++;
+                    } else {
+                        healthyCount++;
+                    }
                 }
                 Map<String, Object> unHealthyContext = new HashMap<>();
                 unHealthyContext.put("appMsgs", appMsgs);
@@ -81,11 +89,28 @@ public class ApplicationHealthCheckEmailPublisher implements ApplicationHealthCh
                 unHealthyContext.put("healthCheckUrl", "http://" + config.getString(SERVICE_HOST)
+ ":" + HEALTH_CHECK_PORT + "/healthcheck");
                 context.put(UNHEALTHY_CONTEXT, unHealthyContext);
 
+                String subject = "";
+                if (healthyCount > 0) {
+                    subject += healthyCount + " healthy app(s)";
+                }
+                if (unhealthyCount > 0) {
+                    if (!subject.isEmpty()) {
+                        subject += ", ";
+                    }
+                    subject += unhealthyCount + " unhealthy app(s)";
+                }
+                subject = config.getString(CONF_MAIL_SUBJECT) + ": " + subject;
                 EagleMailClient client = new EagleMailClient(properties);
-                success = client.send(config.getString(CONF_MAIL_SENDER),
+                String hostname = InetAddress.getLocalHost().getHostName();
+                if (!hostname.endsWith(".com")) {
+                    //avoid invalid host exception
+                    hostname += ".com";
+                }
+                success = client.send(
+                        System.getProperty("user.name") + "@" + hostname,
                         recipients,
                         config.hasPath(CONF_MAIL_CC) ? config.getString(CONF_MAIL_CC) : null,
-                        config.getString(CONF_MAIL_SUBJECT),
+                        subject,
                         config.getString(CONF_MAIL_TEMPLATE),
                         context,
                         null);

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3becca68/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckServiceImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckServiceImpl.java
b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckServiceImpl.java
index b292fa1..fb2a1b4 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckServiceImpl.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationHealthCheckServiceImpl.java
@@ -152,11 +152,11 @@ public class ApplicationHealthCheckServiceImpl extends ApplicationHealthCheckSer
         int dailySendHour = config.getInt(HEALTH_CHECK_DAILY_SEND_HOUR_PATH);
 
         GregorianCalendar cal = new GregorianCalendar(timeZone);
-        if (cal.get(Calendar.HOUR_OF_DAY) % dailySendHour == 0 && !hasSendDaily)
{
+        if (cal.get(Calendar.HOUR_OF_DAY) == dailySendHour && !hasSendDaily) {
             isDaily = true;
         }
 
-        if (cal.get(Calendar.HOUR_OF_DAY) % dailySendHour != 0) {
+        if (cal.get(Calendar.HOUR_OF_DAY) != dailySendHour) {
             hasSendDaily = false;
         }
         Map<String, HealthCheck> copyAppHealthChecks = new HashMap<>();

http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/3becca68/eagle-server/src/main/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/resources/application.conf b/eagle-server/src/main/resources/application.conf
index da0c7c9..91757d7 100644
--- a/eagle-server/src/main/resources/application.conf
+++ b/eagle-server/src/main/resources/application.conf
@@ -105,7 +105,6 @@ application {
       mail.smtp.host = "mail.host.com"
       mail.smtp.port = 25
       mail.smtp.recipients = "someone@email.com"
-      mail.smtp.sender = "someone@email.com"
       mail.smtp.subject = "Eagle Application Health Check"
       mail.smtp.template = "HealthCheckTemplate.vm"
     }


Mime
View raw message