From e6942b1c960f745b2b7fa62484e88b9b91af9243 Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Mon, 15 Feb 2016 13:15:27 -0700 Subject: [PATCH 1/5] Adds a cache type tag to all records written to InfluxDB. This resolves #1053. --- traffic_stats/traffic_stats.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/traffic_stats/traffic_stats.go b/traffic_stats/traffic_stats.go index 4bcd57480..d28a5f6a5 100644 --- a/traffic_stats/traffic_stats.go +++ b/traffic_stats/traffic_stats.go @@ -77,8 +77,8 @@ type StartupConfig struct { // RunningConfig is used to store runtime configuration for Traffic Stats. This includes information // about caches, cachegroups, health urls, and online InfluxDB servers type RunningConfig struct { - HealthUrls map[string]map[string]string // the 1st map key is CDN_name, the second is DsStats or CacheStats - CacheGroupMap map[string]string // map hostName to cacheGroup + HealthUrls map[string]map[string]string // the 1st map key is CDN_name, the second is DsStats or CacheStats + CacheMap map[string]traffic_ops.Server // map hostName to cache InfluxDBs []*InfluxDBProps LastSummaryTime time.Time } @@ -160,7 +160,7 @@ func main() { for cdnName, urls := range runningConfig.HealthUrls { for _, url := range urls { log.Debug(cdnName, " -> ", url) - go calcMetrics(cdnName, url, runningConfig.CacheGroupMap, config, runningConfig) + go calcMetrics(cdnName, url, runningConfig.CacheMap, config, runningConfig) } } case now := <-tickers.DailySummary: @@ -396,9 +396,9 @@ func getToData(config StartupConfig, init bool, configChan chan RunningConfig) { return } - runningConfig.CacheGroupMap = make(map[string]string) + runningConfig.CacheMap = make(map[string]traffic_ops.Server) for _, server := range servers { - runningConfig.CacheGroupMap[server.HostName] = server.Location + runningConfig.CacheMap[server.HostName] = server if server.Type == "INFLUXDB" && server.Status == "ONLINE" { fqdn := server.HostName + "." + server.DomainName port, err := strconv.ParseInt(server.TcpPort, 10, 32) @@ -470,7 +470,7 @@ func getToData(config StartupConfig, init bool, configChan chan RunningConfig) { configChan <- runningConfig } -func calcMetrics(cdnName string, url string, cacheGroupMap map[string]string, config StartupConfig, runningConfig RunningConfig) { +func calcMetrics(cdnName string, url string, cacheMap map[string]traffic_ops.Server, config StartupConfig, runningConfig RunningConfig) { sampleTime := int64(time.Now().Unix()) // get the data from trafficMonitor trafMonData, err := getURL(url) @@ -480,7 +480,7 @@ func calcMetrics(cdnName string, url string, cacheGroupMap map[string]string, co } if strings.Contains(url, "CacheStats") { - err = calcCacheValues(trafMonData, cdnName, sampleTime, cacheGroupMap, config) + err = calcCacheValues(trafMonData, cdnName, sampleTime, cacheMap, config) } else if strings.Contains(url, "DsStats") { err = calcDsValues(trafMonData, cdnName, sampleTime, config) } else { @@ -621,7 +621,7 @@ func calcDsValues(rascalData []byte, cdnName string, sampleTime int64, config St } */ -func calcCacheValues(trafmonData []byte, cdnName string, sampleTime int64, cacheGroupMap map[string]string, config StartupConfig) error { +func calcCacheValues(trafmonData []byte, cdnName string, sampleTime int64, cacheMap map[string]traffic_ops.Server, config StartupConfig) error { type CacheStatsJSON struct { Pp string `json:"pp"` @@ -647,6 +647,8 @@ func calcCacheValues(trafmonData []byte, cdnName string, sampleTime int64, cache errHndlr(err, ERROR) } for cacheName, cacheData := range jData.Caches { + cache := cacheMap[cacheName] + for statName, statData := range cacheData { dataKey := statName dataKey = strings.Replace(dataKey, ".bandwidth", ".kbps", 1) @@ -667,9 +669,10 @@ func calcCacheValues(trafmonData []byte, cdnName string, sampleTime int64, cache statFloatValue = 0.00 } tags := map[string]string{ - "cachegroup": cacheGroupMap[cacheName], + "cachegroup": cache.Location, "hostname": cacheName, "cdn": cdnName, + "type": cache.Type, } fields := map[string]interface{}{ From d8249ca1ccc845ba543379ae1b19492e92c89b61 Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Mon, 15 Feb 2016 13:36:28 -0700 Subject: [PATCH 2/5] Reduced logging levels for local host detection and polling loop. This closes #1056. --- .../traffic_monitor/config/RouterConfig.java | 6 +++--- .../traffic_monitor/health/CacheWatcher.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/config/RouterConfig.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/config/RouterConfig.java index a32052163..4593ff43b 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/config/RouterConfig.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/config/RouterConfig.java @@ -63,17 +63,17 @@ public RouterConfig(final JSONObject crConfigJson, final HealthDeterminer health final Peer peer = new Peer(id, peers.optJSONObject(id)); if (Network.isIpAddressLocal(peer.getIpAddress())) { - LOGGER.warn("Skipping monitor " + id + "; IP address " + peer.getIpAddress() + " is local"); + LOGGER.debug("Skipping monitor " + id + "; IP address " + peer.getIpAddress() + " is local"); continue; } if (Network.isLocalName(peer.getFqdn())) { - LOGGER.warn("Skipping monitor " + id + "; fqdn " + peer.getFqdn() + " is the local fully qualified name"); + LOGGER.debug("Skipping monitor " + id + "; fqdn " + peer.getFqdn() + " is the local fully qualified name"); continue; } if (Network.isLocalName(id)) { - LOGGER.warn("Skipping monitor " + id + "; short name " + id + " is the local hostname"); + LOGGER.debug("Skipping monitor " + id + "; short name " + id + " is the local hostname"); continue; } diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/CacheWatcher.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/CacheWatcher.java index 6e520c280..8396b2736 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/CacheWatcher.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/CacheWatcher.java @@ -169,7 +169,7 @@ public void run() { queryIntervalActual.set(completedTime - time); queryIntervalDelta.set((completedTime - time) - config.getHealthPollingInterval()); - LOGGER.warn("Check time of " + states.size() + " caches elapsed: " + mytime + " msec, (Active time was " + (completedTime - time) + ") msec, " + cancelCount.get() + " checks were cancelled, " + failCount.get() + " failed"); + LOGGER.debug("Check time of " + states.size() + " caches elapsed: " + mytime + " msec, (Active time was " + (completedTime - time) + ") msec, " + cancelCount.get() + " checks were cancelled, " + failCount.get() + " failed"); } catch (Exception e) { LOGGER.warn(e, e); From 55da403640f38423e8c11ac8509d8c2eb3af56da Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Mon, 15 Feb 2016 13:43:22 -0700 Subject: [PATCH 3/5] Introduced mechanism to override hardcoded values for config file and database paths and corrected any dependencies. This resolves #1057. --- traffic_monitor/README.md | 17 ++++++++++- .../traffic_monitor/MonitorApplication.java | 2 +- .../traffic_monitor/config/ConfigHandler.java | 30 +++++++++++++------ .../util/PeriodicResourceUpdater.java | 10 ++++--- .../traffic_monitor/Start.java | 6 ++++ .../traffic_monitor/TestHomePage.java | 5 ++++ .../test/java/config/ConfigHandlerTest.java | 9 ++---- 7 files changed, 57 insertions(+), 22 deletions(-) diff --git a/traffic_monitor/README.md b/traffic_monitor/README.md index 262e8fc57..c4fac332f 100644 --- a/traffic_monitor/README.md +++ b/traffic_monitor/README.md @@ -3,4 +3,19 @@ ### Why Tests are not in exactly matching packages The "com.comcast.cdn.traffic_control.traffic_monitor" portion of the package name was omitted from unit -tests to prevent improper referencing of package private fields and methods of the code under test. \ No newline at end of file +tests to prevent improper referencing of package private fields and methods of the code under test. + +### Running Traffic Monitor locally + +The "com.comcast.cdn.traffic_control.traffic_monitor.Start" class allows one to run Traffic Monitor +locally provided that necessary configuration is in place. By default, the files are specified +with paths relevant to certain IDEs, but these paths can be changed by specifying different +properties via System.properties. These properties are: + +* traffic_monitor.path.config +* traffic_monitor.path.db + +The first property refers to the location of traffic_monitor_config.js. The second property +refers to the directory that will be used for certain data files that are downloaded at runtime. +If you need to specify a different path, use the -D option to the Java command, or modify the +paths in the Start class directly. diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/MonitorApplication.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/MonitorApplication.java index 919142722..1253e8bb5 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/MonitorApplication.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/MonitorApplication.java @@ -62,7 +62,7 @@ public void init() { super.init(); if (!ConfigHandler.getInstance().configFileExists()) { - LOGGER.fatal("Cannot find configuration file: " + ConfigHandler.CONFIG_FILEPATH); + LOGGER.fatal("Cannot find configuration file: " + ConfigHandler.getInstance().getConfigFile()); // This will only stop Tomcat if the security manager allows it // https://tomcat.apache.org/tomcat-6.0-doc/security-manager-howto.html System.exit(1); diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/config/ConfigHandler.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/config/ConfigHandler.java index 974a69401..b2183c3cc 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/config/ConfigHandler.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/config/ConfigHandler.java @@ -26,14 +26,16 @@ public class ConfigHandler { private static final Logger LOGGER = Logger.getLogger(ConfigHandler.class); - public static final String CONFIG_FILEPATH = "/opt/traffic_monitor/conf/traffic_monitor_config.js"; - public static final String DB_FILEPATH = "/opt/traffic_monitor/db/"; + private static final String CONFIG_FILEPATH = "/opt/traffic_monitor/conf/traffic_monitor_config.js"; + private static final String DB_FILEPATH = "/opt/traffic_monitor/db"; + public static final String CONFIG_PROPERTY = "traffic_monitor.path.config"; + public static final String DB_PROPERTY = "traffic_monitor.path.db"; private final Object lok = new Object(); private MonitorConfig config = null; private boolean shutdown; - private final File configFile = new File(CONFIG_FILEPATH); - private final File dbDirectory = new File(DB_FILEPATH); + private final File configFile = new File(getFilePath(CONFIG_PROPERTY, CONFIG_FILEPATH)); + private final String dbPath = getFilePath(DB_PROPERTY, DB_FILEPATH); // Recommended Singleton Pattern implementation // https://community.oracle.com/docs/DOC-918906 @@ -71,7 +73,7 @@ public MonitorConfig getConfig() { final JSONObject jsonConfig = new JSONObject(IOUtils.toString(new FileReader(configFile))); config = new MonitorConfig(jsonConfig.getJSONObject("traffic_monitor_config")); } catch (FileNotFoundException e) { - LOGGER.error("Failed to find traffic monitor configuration file " + CONFIG_FILEPATH); + LOGGER.error("Failed to find traffic monitor configuration file " + configFile.toString()); } catch (Exception e) { LOGGER.warn(e, e); } @@ -84,13 +86,23 @@ public MonitorConfig getConfig() { return config; } - public String getDbDir() { - synchronized (lok) { - return dbDirectory.exists() ? DB_FILEPATH : null; - } + public File getDbFile(final String filename) { + return new File(dbPath, filename); + } + + public File getConfigFile() { + return configFile; } public boolean configFileExists() { return configFile.exists(); } + + private String getFilePath(final String property, final String staticFilePath) { + if (property != null && System.getProperty(property) != null) { + return System.getProperty(property); + } + + return staticFilePath; + } } diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/util/PeriodicResourceUpdater.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/util/PeriodicResourceUpdater.java index c7febcc42..6b01f5ee9 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/util/PeriodicResourceUpdater.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/util/PeriodicResourceUpdater.java @@ -60,11 +60,13 @@ private static class UpdateModel { private boolean hasBeenLoaded = false; private void putCurrent() { - final File existingDB = new File(ConfigHandler.getInstance().getDbDir() + databaseLocation); - if(existingDB.exists()) { - LOGGER.warn("loading: "+existingDB.getAbsolutePath()); + final File existingDB = ConfigHandler.getInstance().getDbFile(databaseLocation); + + if (existingDB.exists()) { + LOGGER.warn("loading: " + existingDB.getAbsolutePath()); listener.update(existingDB); } + hasBeenLoaded = true; } } @@ -152,7 +154,7 @@ protected File fetchFile(final String url) throws IOException { } public boolean updateDatabase(final UpdateModel um) { - final File existingDB = new File(ConfigHandler.getInstance().getDbDir() + um.databaseLocation); + final File existingDB = ConfigHandler.getInstance().getDbFile(um.databaseLocation); File newDB = null; try { if (um.hasBeenLoaded) { diff --git a/traffic_monitor/src/test/java/com/comcast/cdn/traffic_control/traffic_monitor/Start.java b/traffic_monitor/src/test/java/com/comcast/cdn/traffic_control/traffic_monitor/Start.java index d1524b29d..98d0e683a 100644 --- a/traffic_monitor/src/test/java/com/comcast/cdn/traffic_control/traffic_monitor/Start.java +++ b/traffic_monitor/src/test/java/com/comcast/cdn/traffic_control/traffic_monitor/Start.java @@ -16,6 +16,8 @@ package com.comcast.cdn.traffic_control.traffic_monitor; +import java.util.Properties; + import org.apache.wicket.util.time.Duration; import org.eclipse.jetty.http.ssl.SslContextFactory; import org.eclipse.jetty.server.Server; @@ -24,8 +26,12 @@ import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.webapp.WebAppContext; +import com.comcast.cdn.traffic_control.traffic_monitor.config.ConfigHandler; + public class Start { public static void main(String[] args) throws Exception { + System.getProperties().setProperty(ConfigHandler.CONFIG_PROPERTY, "target/test-classes/conf/traffic_monitor_config.js"); + System.getProperties().setProperty(ConfigHandler.DB_PROPERTY, "target/test-classes/db/"); int timeout = (int) Duration.ONE_HOUR.getMilliseconds(); Server server = new Server(); diff --git a/traffic_monitor/src/test/java/com/comcast/cdn/traffic_control/traffic_monitor/TestHomePage.java b/traffic_monitor/src/test/java/com/comcast/cdn/traffic_control/traffic_monitor/TestHomePage.java index 4912f9415..94689134e 100644 --- a/traffic_monitor/src/test/java/com/comcast/cdn/traffic_control/traffic_monitor/TestHomePage.java +++ b/traffic_monitor/src/test/java/com/comcast/cdn/traffic_control/traffic_monitor/TestHomePage.java @@ -32,6 +32,10 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic; import static org.powermock.api.mockito.PowerMockito.when; +import java.io.File; + +import static org.mockito.Matchers.anyString; + @PrepareForTest({ConfigHandler.class, CacheWatcher.class, SSLContext.class}) @RunWith(PowerMockRunner.class) public class TestHomePage { @@ -55,6 +59,7 @@ public void setUp() throws Exception { when(configHandler.getConfig()).thenReturn(monitorConfig); when(configHandler.configFileExists()).thenReturn(true); + when(configHandler.getDbFile(anyString())).thenReturn(mock(File.class)); mockStatic(ConfigHandler.class); when(ConfigHandler.getInstance()).thenReturn(configHandler); diff --git a/traffic_monitor/src/test/java/config/ConfigHandlerTest.java b/traffic_monitor/src/test/java/config/ConfigHandlerTest.java index 652d349f9..c6b7bc5a8 100644 --- a/traffic_monitor/src/test/java/config/ConfigHandlerTest.java +++ b/traffic_monitor/src/test/java/config/ConfigHandlerTest.java @@ -25,13 +25,11 @@ @RunWith(PowerMockRunner.class) public class ConfigHandlerTest { static File mockConfigFile = mock(File.class); - static File mockDbDirectory = mock(File.class); static ConfigHandler configHandler; @BeforeClass public static void beforeClass() throws Exception { whenNew(File.class).withArguments("/opt/traffic_monitor/conf/traffic_monitor_config.js").thenReturn(mockConfigFile); - whenNew(File.class).withArguments("/opt/traffic_monitor/db/").thenReturn(mockDbDirectory); configHandler = ConfigHandler.getInstance(); } @@ -78,10 +76,7 @@ public void itBuildsMonitorConfigFromJsonString() throws Exception { } @Test - public void itReportsTheDatabaseDirectoryExists() { - assertThat(configHandler.getDbDir(), nullValue()); - - when(mockDbDirectory.exists()).thenReturn(true); - assertThat(configHandler.getDbDir(), equalTo("/opt/traffic_monitor/db/")); + public void itReturnsCorrectPathToDbFile() { + assertThat(configHandler.getDbFile("health-config.json").toString(), equalTo("/opt/traffic_monitor/db/health-config.json")); } } \ No newline at end of file From 6264be723294988109dc6c04b4119c15ee556d94 Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Mon, 15 Feb 2016 13:47:23 -0700 Subject: [PATCH 4/5] Adds data aggregation and filtering by cache type in Traffic Monitor. This resolves #1058. --- .../traffic_monitor/health/AbstractState.java | 39 ++++++++-- .../traffic_monitor/health/DsState.java | 78 +++++++++++-------- .../traffic_monitor/health/EmbeddedStati.java | 29 +++++-- .../traffic_monitor/health/Event.java | 36 +++++++-- .../health/HealthDeterminer.java | 24 ++++-- .../traffic_monitor/health/PeerState.java | 15 ++-- .../traffic_monitor/publish/CacheStats.java | 29 +++---- .../traffic_monitor/publish/CrStates.java | 61 ++++++++------- .../wicket/components/CacheListPanel.html | 2 + .../wicket/components/CacheListPanel.java | 11 +-- .../wicket/components/DsListPanel.html | 2 +- .../wicket/components/DsListPanel.java | 3 +- .../wicket/components/EventLogPanel.html | 9 ++- .../wicket/components/EventLogPanel.java | 3 +- 14 files changed, 221 insertions(+), 120 deletions(-) diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/AbstractState.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/AbstractState.java index d6410feae..86fb6e50d 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/AbstractState.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/AbstractState.java @@ -16,16 +16,21 @@ package com.comcast.cdn.traffic_control.traffic_monitor.health; +import java.util.ArrayList; import java.util.Deque; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import com.comcast.cdn.traffic_control.traffic_monitor.data.StatisticsLog; +import com.comcast.cdn.traffic_control.traffic_monitor.health.Event.EventType; + import org.apache.log4j.Logger; import org.apache.wicket.ajax.json.JSONArray; import org.apache.wicket.ajax.json.JSONException; import org.apache.wicket.ajax.json.JSONObject; +import org.apache.wicket.util.string.Strings; import com.comcast.cdn.traffic_control.traffic_monitor.data.DataPoint; import com.comcast.cdn.traffic_control.traffic_monitor.data.DataSummary; @@ -49,6 +54,10 @@ public String getId() { } protected void putDataPoints(final Map statistics) { + if (statistics == null) { + return; + } + synchronized(this) { for(String key : statistics.keySet()) { putDataPoint(key, statistics.get(key)); @@ -137,19 +146,35 @@ public void setHistoryTime(final long t) { } public String getStatusString() { - String error = getLastValue("error-string"); - if(error == null) { - error = isAvailable()? "available" : ""; + final List errors = new ArrayList(); + final String error = getLastValue("error-string"); + final StringBuilder status = new StringBuilder(); + + status.append(getLastValue("status")); + + if (error != null) { + errors.add(error); + } else { + errors.add(isAvailable() ? "available" : "unavailable"); } - if(getBool("clearData")) { error = "No query"; } - return getLastValue("status") + " - " + error; + + if (getBool("clearData")) { + errors.add("monitoring disabled"); + } + + if (!errors.isEmpty()) { + status.append(" - "); + status.append(Strings.join(", ", errors)); + } + + return status.toString(); } public boolean isError() { return getLastValue("error-string") != null; } - public void setAvailable(final boolean isAvailable, final String error) { + public void setAvailable(final EventType type, final boolean isAvailable, final String error) { final boolean isHealthy = (error == null); boolean logChange = true; @@ -165,7 +190,7 @@ public void setAvailable(final boolean isAvailable, final String error) { putDataPoint(IS_HEALTHY_STR, String.valueOf(isHealthy)); if (logChange) { - lastEvent = Event.logStateChange(this.getId(), isAvailable, getStatusString()); + lastEvent = Event.logStateChange(this.getId(), type, isAvailable, getStatusString()); } } diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/DsState.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/DsState.java index fdef97dfb..7fd38a0e3 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/DsState.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/DsState.java @@ -16,6 +16,7 @@ package com.comcast.cdn.traffic_control.traffic_monitor.health; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -23,15 +24,17 @@ import org.apache.wicket.ajax.json.JSONException; import org.apache.wicket.ajax.json.JSONObject; +import com.comcast.cdn.traffic_control.traffic_monitor.health.EmbeddedStati.StatType; + public class DsState extends AbstractState { private static final long serialVersionUID = 1L; + final private Map> aggregateStats = new HashMap>(); + final public static String DISABLED_LOCATIONS = "disabledLocations"; private DsStati currentDsStati; private int cachesConfigured = 0; private int cachesAvailable = 0; private int cachesReporting = 0; - final private Map locs = new HashMap(); - final private Map cacheStatiMap = new HashMap(); public DsState(final String id) { super(id); @@ -48,23 +51,23 @@ public void accumulate(final DsStati stati, final String location, final CacheSt currentDsStati.accumulate(stati); } - EmbeddedStati loc = locs.get(location); + aggregateStats(StatType.LOCATION, location, stati); + aggregateStats(StatType.CACHE, state.id, stati); + aggregateStats(StatType.TYPE, state.getCache().getType(), stati); + } - if (loc == null) { - loc = new EmbeddedStati("location", location); - locs.put(location,loc); + private void aggregateStats(final StatType statType, final String statKey, final DsStati dsStat) { + if (!aggregateStats.containsKey(statType)) { + aggregateStats.put(statType, new HashMap()); } - loc.accumulate(stati); + final Map aggregate = aggregateStats.get(statType); - EmbeddedStati cacheStati = cacheStatiMap.get(state.id); - - if (cacheStati == null) { - cacheStati = new EmbeddedStati("cache", state.id); - cacheStatiMap.put(state.id, cacheStati); + if (!aggregate.containsKey(statKey)) { + aggregate.put(statKey, new EmbeddedStati(statType, statKey)); } - cacheStati.accumulate(stati); + aggregate.get(statKey).accumulate(dsStat); } public boolean completeRound(final JSONObject dsControls) { @@ -83,43 +86,50 @@ public boolean completeRound(final JSONObject dsControls) { HealthDeterminer.setIsAvailable(this, dsControls); - final StringBuilder sb = new StringBuilder(); + for (Map aggregate : aggregateStats.values()) { + processDataPoints(aggregate.values(), dsControls); + } + + return true; + } + + private void processDataPoints(final Collection stats, final JSONObject dsControls) { + final Map disabled = new HashMap(); - for (String locId : locs.keySet()) { - final EmbeddedStati loc = locs.get(locId); - final Map stati = loc.completeRound(); + for (EmbeddedStati stat : stats) { + final Map points = stat.completeRound(); - if (stati == null) { + if (points == null) { continue; } - putDataPoints(stati); + putDataPoints(points); - if (!HealthDeterminer.setIsAvailable(this, loc, dsControls)) { - sb.append("\"").append(locId).append("\", "); + if (stat.isHidden()) { + addHiddenStats(points.keySet()); } - } - - putDataPoint("disabledLocations", sb.toString()); - for (String cacheId : cacheStatiMap.keySet()) { - final EmbeddedStati cacheStat = cacheStatiMap.get(cacheId); - final Map stati = cacheStat.completeRound(); + if (stat.getStatType() == StatType.LOCATION) { + disabled.put(stat.getStatType(), new StringBuilder()); - if (stati == null) { - continue; + if (!HealthDeterminer.setIsLocationAvailable(this, stat, dsControls)) { + disabled.get(stat.getStatType()).append("\"").append(stat.getId()).append("\", "); + } } + } - addHiddenStats(stati.keySet()); + for (StatType statType : disabled.keySet()) { + final StringBuilder sb = disabled.get(statType); - putDataPoints(stati); + if (statType == StatType.LOCATION && sb != null) { + final String s = sb.toString(); + putDataPoint(DISABLED_LOCATIONS, s); + } } - - return true; } public JSONArray getDisabledLocations() throws JSONException { - return new JSONArray("["+this.getLastValue("disabledLocations")+"]"); + return new JSONArray("["+this.getLastValue(DISABLED_LOCATIONS)+"]"); } public void addCacheConfigured() { diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/EmbeddedStati.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/EmbeddedStati.java index b72b60f85..e9e98aa47 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/EmbeddedStati.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/EmbeddedStati.java @@ -7,22 +7,27 @@ public class EmbeddedStati implements java.io.Serializable { private static final long serialVersionUID = 1L; private DsStati currentDtati; private final String id; + private StatType statType; - public EmbeddedStati(final String base, final String id, final String delimiter) { - final StringBuilder statId = new StringBuilder(); + public enum StatType { + LOCATION, + CACHE, + TYPE + }; - if (base != null) { - statId.append(base); - statId.append(delimiter); - } + public EmbeddedStati(final StatType statType, final String id, final String delimiter) { + final StringBuilder statId = new StringBuilder(); + statId.append(statType.toString().toLowerCase()); + statId.append(delimiter); statId.append(id); this.id = statId.toString(); + this.statType = statType; } - public EmbeddedStati(final String base, final String id) { - this(base, id, "."); + public EmbeddedStati(final StatType statType, final String id) { + this(statType, id, "."); } public void accumulate(final DsStati stati) { @@ -49,4 +54,12 @@ public Map completeRound() { public String getId() { return id; } + + public boolean isHidden() { + return (statType == StatType.CACHE) ? true : false; + } + + public StatType getStatType() { + return statType; + } } diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/Event.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/Event.java index 4699d73aa..a98273aaa 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/Event.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/Event.java @@ -34,13 +34,37 @@ public class Event extends JSONObject implements Serializable { static List rollingLog = new LinkedList(); static int logIndex = 0; - public static Event logStateChange(final String hostname, final boolean isAvailable, final String message) { + public enum EventType { + CACHE_STATE_CHANGE, + PEER_STATE_CHANGE("Peer"), + DELIVERY_SERVICE_STATE_CHANGE("Delivery Service"); + + private String type; + + EventType(final String type) { + this.type = type; + } + + EventType() { + } + + @Override + public String toString() { + return (type != null) ? type : "UNKNOWN"; + } + + public void setType(final String type) { + this.type = type; + } + } + + public static Event logStateChange(final String name, final EventType type, final boolean isAvailable, final String message) { final long currentTimeMillis = System.currentTimeMillis(); final String timeString = String.format("%d.%03d", currentTimeMillis / 1000, currentTimeMillis % 1000); - EVENT_LOGGER.info(String.format("%s host=\"%s\", available=%s, msg=\"%s\"", timeString , hostname, String.valueOf(isAvailable), message)); + EVENT_LOGGER.info(String.format("%s name=\"%s\", type=%s, available=%s, msg=\"%s\"", timeString , name, type, String.valueOf(isAvailable), message)); - final Event ret = new Event(hostname, isAvailable, message); + final Event ret = new Event(name, type, isAvailable, message); final int eventLogCount = ConfigHandler.getInstance().getConfig().getEventLogCount(); synchronized (rollingLog) { @@ -58,9 +82,11 @@ public static List getEventLog() { } } - public Event(final String hostname, final boolean isAvailable, final String error) { + public Event(final String name, final EventType type, final boolean isAvailable, final String error) { try { - this.put("hostname", hostname); + this.put("hostname", name); // left this to preserve behavior for any dependent uses + this.put("name", name); + this.put("type", type.toString()); this.put("time", System.currentTimeMillis()); this.put("index", logIndex++); this.put("isAvailable", isAvailable); diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/HealthDeterminer.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/HealthDeterminer.java index f91beb5ab..618fb9152 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/HealthDeterminer.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/HealthDeterminer.java @@ -26,6 +26,7 @@ import org.apache.wicket.ajax.json.JSONObject; import com.comcast.cdn.traffic_control.traffic_monitor.config.Cache; +import com.comcast.cdn.traffic_control.traffic_monitor.health.Event.EventType; import com.comcast.cdn.traffic_control.traffic_monitor.util.Updatable; public class HealthDeterminer { @@ -162,15 +163,19 @@ public void setIsAvailable(final Cache cache, final CacheState state) { final String error = getErrorString(cache, state); state.putDataPoint(STATUS, status); state.putDataPoint(ERROR_STRING, error); - final boolean isHealthy = (error==null); - state.setAvailable(getIsAvailable(cache, isHealthy), error); + final boolean isHealthy = (error == null); + final EventType type = EventType.CACHE_STATE_CHANGE; + type.setType(cache.getType()); + state.setAvailable(type, getIsAvailable(cache, isHealthy), error); } public void setIsAvailable(final Cache cache, final String e, final CacheState state) { final String status = cache.getStatus(); state.putDataPoint(STATUS, status); state.putDataPoint(ERROR_STRING, e); - state.setAvailable(getIsAvailable(cache, false), e); + final EventType type = EventType.CACHE_STATE_CHANGE; + type.setType(cache.getType()); + state.setAvailable(type, getIsAvailable(cache, false), e); } private boolean shouldClearData(final String status) { @@ -353,23 +358,26 @@ public JSONObject getDsControls(final String id) { return deliveryServices.optJSONObject(id); } public static void setIsAvailable(final DsState dsState, final JSONObject dsControls) { - if(dsControls == null) { + final EventType type = EventType.DELIVERY_SERVICE_STATE_CHANGE; + + if (dsControls == null) { dsState.putDataPoint(STATUS, "ONLINE"); - dsState.setAvailable(getIsAvailable("ONLINE", true), null); + dsState.setAvailable(type, getIsAvailable("ONLINE", true), null); return; } + // first check ONLINEness final String status = dsControls.optString(STATUS); final String error = getErrorString(dsControls, dsState); dsState.putDataPoint(STATUS, status); dsState.putDataPoint(ERROR_STRING, error); - final boolean isHealthy = (error==null); - dsState.setAvailable(getIsAvailable(status, isHealthy), error); + final boolean isHealthy = (error == null); + dsState.setAvailable(EventType.DELIVERY_SERVICE_STATE_CHANGE, getIsAvailable(status, isHealthy), error); } private static String getErrorString(final JSONObject dsControls, final DsState dsState) { return mapControlsToError(dsControls, dsState, ""); } - public static boolean setIsAvailable(final DsState dsState, final EmbeddedStati loc, final JSONObject dsControls) { + public static boolean setIsLocationAvailable(final DsState dsState, final EmbeddedStati loc, final JSONObject dsControls) { boolean isAvailable = true; String error = null; if(dsControls != null) { diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/PeerState.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/PeerState.java index f22f3c187..8ac164a93 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/PeerState.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/PeerState.java @@ -27,6 +27,7 @@ import com.comcast.cdn.traffic_control.traffic_monitor.config.Cache; import com.comcast.cdn.traffic_control.traffic_monitor.config.Peer; +import com.comcast.cdn.traffic_control.traffic_monitor.health.Event.EventType; public class PeerState extends AbstractState { private static final Logger LOGGER = Logger.getLogger(PeerState.class); @@ -176,6 +177,8 @@ public static List getCacheAvailableOnPeers(final Cache c) { public static void logOverride(final Cache c) { final Boolean state = overrideMap.get(c.getFqdn()); + final EventType type = EventType.CACHE_STATE_CHANGE; + type.setType(c.getType()); if (PeerState.hasOnlinePeers()) { final List onlineList = PeerState.getCacheAvailableOnPeers(c); @@ -184,7 +187,7 @@ public static void logOverride(final Cache c) { if (state == null || !state.booleanValue()) { final StringBuffer msg = new StringBuffer("Health protocol override condition detected; healthy on (at least) "); msg.append(Arrays.toString(onlineList.toArray()).replaceAll("\\[|\\]", "")); - Event.logStateChange(c.getHostname(), true, msg.toString()); + Event.logStateChange(c.getHostname(), type, true, msg.toString()); overrideMap.put(c.getFqdn(), true); } } else if (onlineList.isEmpty()) { @@ -199,13 +202,13 @@ public static void logOverride(final Cache c) { msg.append("; local state unknown"); } - Event.logStateChange(c.getHostname(), c.isAvailable(), msg.toString()); + Event.logStateChange(c.getHostname(), type, c.isAvailable(), msg.toString()); overrideMap.put(c.getFqdn(), false); } } } else if (state != null && state.booleanValue()) { final StringBuffer msg = new StringBuffer("Health protocol override condition irrelevant; no peers online"); - Event.logStateChange(c.getHostname(), c.isAvailable(), msg.toString()); + Event.logStateChange(c.getHostname(), type, c.isAvailable(), msg.toString()); overrideMap.put(c.getFqdn(), false); } } @@ -215,7 +218,9 @@ public static void clearOverride(final Cache c) { final Boolean state = overrideMap.get(c.getFqdn()); if (state.booleanValue()) { - Event.logStateChange(c.getHostname(), true, "Health protocol override condition cleared; healthy locally"); + final EventType type = EventType.CACHE_STATE_CHANGE; + type.setType(c.getType()); + Event.logStateChange(c.getHostname(), type, true, "Health protocol override condition cleared; healthy locally"); } overrideMap.remove(c.getFqdn()); @@ -242,7 +247,7 @@ public void setReachable(final boolean reachable, final String reason) { sb.append(reason); } - Event.logStateChange(peer.getHostname(), reachable, sb.toString()); + Event.logStateChange(peer.getHostname(), EventType.PEER_STATE_CHANGE, reachable, sb.toString()); } this.reachable = reachable; diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/publish/CacheStats.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/publish/CacheStats.java index 7dc4bc547..67a9787b8 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/publish/CacheStats.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/publish/CacheStats.java @@ -34,16 +34,15 @@ public class CacheStats extends JsonPage { */ @Override public JSONObject getJson(final PageParameters pp) throws JSONException { - String str = pp.get("hc").toString(); - int hc = 0; - try { - hc = Integer.parseInt(str); - } catch(Exception e) {hc = 0;} String[] stats = null; - str = pp.get("stats").toString(); - if(str != null) { + final String str = pp.get("stats").toString(); + final int hc = pp.get("hc").toInt(0); + + if (str != null) { stats = str.split(","); } + + final String type = pp.get("type").toString(); final boolean wildcard = pp.get("wildcard").toBoolean(false); final boolean hidden = pp.get("hidden").toBoolean(false); final String host = pp.get(0).toString(); @@ -51,20 +50,24 @@ public JSONObject getJson(final PageParameters pp) throws JSONException { o.put("date", new Date().toString()); o.put("pp", pp); final JSONObject servers = new JSONObject(); - if(host != null && !host.equals("")) { - if(cacheStateRegistry.has(host)) { - servers.put(host,cacheStateRegistry.get(host).getStatsJson(hc, stats, wildcard, hidden)); + + if (host != null && !host.equals("")) { + if (cacheStateRegistry.has(host)) { + servers.put(host, cacheStateRegistry.get(host).getStatsJson(hc, stats, wildcard, hidden)); } else { - o.put("error", "Hostname not found: "+host); + o.put("error", "Hostname not found: " + host); } } else { for (CacheState cacheState : cacheStateRegistry.getAll()) { - servers.put(cacheState.getId(),cacheState.getStatsJson(hc, stats, wildcard, hidden)); + if (type == null || type.equals(cacheState.getCache().getType())) { + servers.put(cacheState.getId(), cacheState.getStatsJson(hc, stats, wildcard, hidden)); + } } } + o.put("caches", servers); + return o; } } - diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/publish/CrStates.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/publish/CrStates.java index c9cc64205..c554e0dfb 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/publish/CrStates.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/publish/CrStates.java @@ -16,26 +16,20 @@ package com.comcast.cdn.traffic_control.traffic_monitor.publish; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; - -import com.comcast.cdn.traffic_control.traffic_monitor.health.DeliveryServiceStateRegistry; import org.apache.log4j.Logger; import org.apache.wicket.ajax.json.JSONException; import org.apache.wicket.ajax.json.JSONObject; -import org.apache.wicket.request.cycle.RequestCycle; -import org.apache.wicket.request.http.WebRequest; import org.apache.wicket.request.mapper.parameter.PageParameters; import com.comcast.cdn.traffic_control.traffic_monitor.config.Cache; import com.comcast.cdn.traffic_control.traffic_monitor.config.ConfigHandler; -import com.comcast.cdn.traffic_control.traffic_monitor.config.RouterConfig; import com.comcast.cdn.traffic_control.traffic_monitor.config.MonitorConfig; +import com.comcast.cdn.traffic_control.traffic_monitor.config.RouterConfig; import com.comcast.cdn.traffic_control.traffic_monitor.health.AbstractState; import com.comcast.cdn.traffic_control.traffic_monitor.health.CacheWatcher; +import com.comcast.cdn.traffic_control.traffic_monitor.health.DeliveryServiceStateRegistry; import com.comcast.cdn.traffic_control.traffic_monitor.health.DsState; import com.comcast.cdn.traffic_control.traffic_monitor.health.HealthDeterminer; import com.comcast.cdn.traffic_control.traffic_monitor.health.PeerWatcher; @@ -46,63 +40,72 @@ public class CrStates extends JsonPage { private static CacheWatcher myCacheWatcher; private static PeerWatcher myPeerWatcher; private static HealthDeterminer myHealthDeterminer; - private static Map clientIps = new HashMap(); /** * Send out the json!!!! */ @Override public JSONObject getJson(final PageParameters pp) throws JSONException { - if(myPeerWatcher == null) { + if (myPeerWatcher == null) { return null; } - boolean raw = true; + final MonitorConfig config = ConfigHandler.getInstance().getConfig(); final RouterConfig crConfig = RouterConfig.getCrConfig(); - if(crConfig == null || myCacheWatcher.getCycleCount() < config.getStartupMinCycles()) { + + if (crConfig == null || myCacheWatcher.getCycleCount() < config.getStartupMinCycles()) { return null; } - if(pp == null || pp.getPosition("raw") == -1) { - final WebRequest req = (WebRequest) RequestCycle.get().getRequest(); - final HttpServletRequest httpReq = (HttpServletRequest) req.getContainerRequest(); - clientIps.put(httpReq.getRemoteHost(), new Long(System.currentTimeMillis())); - raw = false; - } + + final boolean raw = (pp.getPosition("raw") != -1); + final String cacheType = pp.get("cacheType").toString(); final JSONObject o = new JSONObject(); - o.put("caches", getCrStates(crConfig, raw)); - if(ConfigHandler.getInstance().getConfig().getPublishDsStates()) { + o.put("caches", getCrStates(crConfig, raw, cacheType)); + + if (ConfigHandler.getInstance().getConfig().getPublishDsStates()) { o.put("deliveryServices", getDsStates(crConfig)); } + return o; } - private JSONObject getCrStates(final RouterConfig crConfig, final boolean raw) { + private JSONObject getCrStates(final RouterConfig crConfig, final boolean raw, final String cacheType) { if (crConfig == null) { return null; } + try { final JSONObject servers = new JSONObject(); final List caches = crConfig.getCacheList(); - for(Cache c : caches) { + + for (Cache c : caches) { synchronized(c) { - if(c.getControls() == null) { continue; } + if (c.getControls() == null || (cacheType != null && !cacheType.equals(c.getType()))) { + continue; + } + final MonitorConfig config = ConfigHandler.getInstance().getConfig(); servers.put(c.getHostname(), myHealthDeterminer.getJSONStats(c, config.getPeerOptimistic(), raw)); } } - if(servers.length()==0) { + + if (servers.length() == 0) { LOGGER.warn("no caches returned! "); } + return servers; } catch (JSONException e) { - LOGGER.warn(e,e); + LOGGER.warn(e, e); } + return null; } + private JSONObject getDsStates(final RouterConfig crConfig) { - if(crConfig == null) { + if (crConfig == null) { return null; } + try { final JSONObject ret = new JSONObject(); @@ -114,14 +117,15 @@ private JSONObject getDsStates(final RouterConfig crConfig) { } dsJo.put(AbstractState.IS_AVAILABLE_STR, dsState.isAvailable()); - dsJo.put("disabledLocations", dsState.getDisabledLocations()); + dsJo.put(DsState.DISABLED_LOCATIONS, dsState.getDisabledLocations()); ret.put(dsState.getId(), dsJo); } return ret; } catch (JSONException e) { - LOGGER.warn(e,e); + LOGGER.warn(e, e); } + return null; } @@ -131,4 +135,3 @@ public static void init(final CacheWatcher cw, final PeerWatcher pw, final Healt myHealthDeterminer = hd; } } - diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/CacheListPanel.html b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/CacheListPanel.html index 243fffc47..24405c6bb 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/CacheListPanel.html +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/CacheListPanel.html @@ -7,6 +7,7 @@ + @@ -16,6 +17,7 @@ + diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/CacheListPanel.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/CacheListPanel.java index 7faa5e911..a13cdac8c 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/CacheListPanel.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/CacheListPanel.java @@ -21,6 +21,7 @@ import java.util.TreeMap; import com.comcast.cdn.traffic_control.traffic_monitor.health.AbstractState; +import com.comcast.cdn.traffic_control.traffic_monitor.health.CacheState; import com.comcast.cdn.traffic_control.traffic_monitor.health.CacheStateRegistry; import com.comcast.cdn.traffic_control.traffic_monitor.wicket.models.CacheStateModel; import org.apache.wicket.Component; @@ -52,7 +53,6 @@ public CacheListPanel(final String id, final Behavior updater, final Component[] final ModalWindow modal1; add(modal1 = new ModalWindow("modal1")); modal1.setInitialWidth(1000); - // modal1.setCookieName("modal-1"); modal1.setPageCreator(new ModalWindow.PageCreator() { private static final long serialVersionUID = 1L; public Page createPage() { @@ -60,7 +60,6 @@ public Page createPage() { } }); - this.updateList = updateList; final WebMarkupContainer container = new WebMarkupContainer("listpanel"); container.setOutputMarkupId(true); @@ -75,7 +74,6 @@ public Page createPage() { int serverCount = 0; @Override protected final void onTimer(final AjaxRequestTarget target) { - // target.add(getComponent()); final int size = CacheStateRegistry.getInstance().size(); if(serverCount != size) { serverCount = size; @@ -98,6 +96,7 @@ private ListView createServerListView(final Behavior updater, final Moda @Override protected void populateItem(final ListItem item) { final String cacheName = item.getModelObject(); + final CacheState cacheState = CacheStateRegistry.getInstance().get(cacheName); item.add(new UpdatingAttributeAppender("class", new Model("") { @Override @@ -108,8 +107,10 @@ public String getObject() { item.add(updater); - - Label label = new Label("status", new CacheStateModel(cacheName, "_status_string_")); + Label label = new Label("type", cacheState.getCache().getType()); + label.add(updater); + item.add(label); + label = new Label("status", new CacheStateModel(cacheName, "_status_string_")); label.add(updater); item.add(label); label = new Label("loadavg", new CacheStateModel(cacheName, "loadavg")); diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/DsListPanel.html b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/DsListPanel.html index 977a0dd0e..66fe395cb 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/DsListPanel.html +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/DsListPanel.html @@ -6,7 +6,7 @@
ServerType Status Load Avg Query Time
- + diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/DsListPanel.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/DsListPanel.java index b321b3a08..a366cae66 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/DsListPanel.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/DsListPanel.java @@ -22,6 +22,7 @@ import com.comcast.cdn.traffic_control.traffic_monitor.health.AbstractState; import com.comcast.cdn.traffic_control.traffic_monitor.health.DeliveryServiceStateRegistry; +import com.comcast.cdn.traffic_control.traffic_monitor.health.DsState; import com.comcast.cdn.traffic_control.traffic_monitor.wicket.models.DsStateModel; import org.apache.wicket.Component; import org.apache.wicket.Page; @@ -132,7 +133,7 @@ public String getObject( ) { label = new Label("tps_5xx", new DsStateModel(dsName, "total.tps_5xx")); label.add(updater); item.add(label); - label = new Label("disabled", new DsStateModel(dsName, "disabledLocations")); + label = new Label("disabled", new DsStateModel(dsName, DsState.DISABLED_LOCATIONS)); label.add(updater); item.add(label); diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/EventLogPanel.html b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/EventLogPanel.html index 7b807dc21..11e88e1f6 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/EventLogPanel.html +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/EventLogPanel.html @@ -8,7 +8,8 @@
ServerDelivery Service Status Caches
Reporting/Available/Configured
Bandwidth (kbps)
- + + @@ -18,14 +19,16 @@ + - + + diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/EventLogPanel.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/EventLogPanel.java index 2f3a94ed2..f01de5eeb 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/EventLogPanel.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/wicket/components/EventLogPanel.java @@ -70,7 +70,8 @@ protected void populateItem(final ListItem item) { } item.add(new Label("timeraw", Long.toString(jo.getLong("time")))); item.add(new Label("description", jo.getString("description"))); - item.add(new Label("hostname", jo.getString("hostname"))); + item.add(new Label("name", jo.getString("name"))); + item.add(new Label("type", jo.getString("type"))); String status = "available"; if(!jo.getBoolean("isAvailable")) { status = "offline"; From d075c4ffe6045862f2d19a04a9fa76387f88f574 Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Mon, 15 Feb 2016 14:00:04 -0700 Subject: [PATCH 5/5] Only create stat placeholder if necessary. --- .../cdn/traffic_control/traffic_monitor/health/DsState.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/DsState.java b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/DsState.java index 7fd38a0e3..d5e18ab0c 100644 --- a/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/DsState.java +++ b/traffic_monitor/src/main/java/com/comcast/cdn/traffic_control/traffic_monitor/health/DsState.java @@ -110,7 +110,9 @@ private void processDataPoints(final Collection stats, final JSON } if (stat.getStatType() == StatType.LOCATION) { - disabled.put(stat.getStatType(), new StringBuilder()); + if (!disabled.containsKey(stat.getStatType())) { + disabled.put(stat.getStatType(), new StringBuilder()); + } if (!HealthDeterminer.setIsLocationAvailable(this, stat, dsControls)) { disabled.get(stat.getStatType()).append("\"").append(stat.getId()).append("\", ");
ServerNameType Status Description Event Time - +