diff --git a/README.md b/README.md index b109858..d8bde9e 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Pushing from manifest to org pivot-boglesby / space playground as boglesby@pivot Using manifest file client/manifest.yml Getting app info... Updating app with these attributes... - name: sdgApp + name: clientApp path: /Users/boglesby/Dev/Tests/spring-boot/pcc-long-running-test/client/build/libs/client-0.0.1-SNAPSHOT.jar buildpacks: https://github.com/cloudfoundry/java-buildpack.git @@ -63,9 +63,9 @@ Updating app with these attributes... services: pccService routes: - sdgapp.apps.pcfone.io + clientapp.apps.pcfone.io -Updating app sdgApp... +Updating app clientApp... Mapping routes... Comparing local files to remote cache... Packaging files to upload... @@ -106,10 +106,10 @@ Staging app and tracing logs... Waiting for app to start... -name: sdgApp +name: clientApp requested state: started isolation segment: iso-01 -routes: sdgapp.apps.pcfone.io +routes: clientapp.apps.pcfone.io last uploaded: Fri 03 Jan 16:02:05 PST 2020 stack: cflinuxfs3 buildpacks: https://github.com/cloudfoundry/java-buildpack.git @@ -230,7 +230,7 @@ start command: JAVA_OPTS="-agentpath:$PWD/.java-buildpack/open_jdk_jre/bin/jvm Get the latest client application log messages using the **cf logs** command like: ``` -cf logs sdgApp --recent +cf logs clientApp --recent ... 2019-12-19T16:20:09.95-0800 [APP/PROC/WEB/0] OUT 2019-12-20 00:20:09.955 INFO 33 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '' 2019-12-19T16:20:09.96-0800 [APP/PROC/WEB/0] OUT 2019-12-20 00:20:09.960 INFO 33 --- [ main] io.pivotal.test.client.Client : Started Client in 7.316 seconds (JVM running for 8.365) @@ -241,8 +241,8 @@ cf logs sdgApp --recent Tail the client application log messages using the **cf logs** command like: ``` -cf logs sdgApp -Retrieving logs for app sdgApp in org pivot-boglesby / space playground as boglesby@pivotal.io... +cf logs clientApp +Retrieving logs for app clientApp in org pivot-boglesby / space playground as boglesby@pivotal.io... ``` #### Get CQ Client Application Logs ##### Get latest Logs @@ -260,7 +260,7 @@ Tail the CQ client application log messages using the **cf logs** command like: ``` cf logs clientCqApp -Retrieving logs for app sdgApp in org pivot-boglesby / space playground as boglesby@pivotal.io... +Retrieving logs for app clientApp in org pivot-boglesby / space playground as boglesby@pivotal.io... ``` ## Run Clients ### PCFOne @@ -279,9 +279,7 @@ name requested state instances memory disk urls sdgApp started 1/1 768M 1G sdgapp.apps.seoul.cf-app.com clientCqApp started 1/1 768M 1G clientcqapp.apps.seoul.cf-app.com ``` - -``` -curl -k -X POST https://sdgapp.apps.pcfone.io/trades/put/10/1024 +curl -k -X POST https://clientapp.apps.pcfone.io/trades/put/10/1024 {"operation":"put","status":"SUCCESS","completionTime":191} ``` The application will log messages like: @@ -304,7 +302,7 @@ The application will log messages like: Run the get command using **curl** like: ``` -curl -k https://sdgapp.apps.pcfone.io/trades/get/10 +curl -k https://clientapp.apps.pcfone.io/trades/get/10 {"operation":"get","status":"SUCCESS","completionTime":55} ``` The application will log messages like: @@ -327,7 +325,7 @@ The application will log messages like: Run the destroy command using **curl** like: ``` -curl -k -X DELETE https://sdgapp.apps.pcfone.io/trades/destroy/10 +curl -k -X DELETE https://clientapp.apps.pcfone.io/trades/destroy/10 {"operation":"destroy","status":"SUCCESS","completionTime":63} ``` The application will log messages like: @@ -350,7 +348,7 @@ The application will log messages like: Run the query by cusip command using **curl** like: ``` -curl -k https://sdgapp.apps.pcfone.io/trades/querybycusip/10 +curl -k https://clientapp.apps.pcfone.io/trades/querybycusip/10 ``` The application will log messages like: @@ -372,7 +370,7 @@ The application will log messages like: Run the function update command using **curl** like: ``` -curl -k -X POST https://sdgapp.apps.pcfone.io/trades/functionupdate/10 +curl -k -X POST https://clientapp.apps.pcfone.io/trades/functionupdate/10 {"operation":"functionupdate","status":"SUCCESS","completionTime":65} ``` The application will log messages like: @@ -395,7 +393,7 @@ The application will log messages like: Run the function update command using **curl** like: ``` -curl -k -X POST https://sdgapp.apps.pcfone.io/trades/putforever/10/1024 +curl -k -X POST https://clientapp.apps.pcfone.io/trades/putforever/10/1024 ``` The application will log messages like: @@ -407,7 +405,7 @@ The application will log messages like: Run the function update command using **curl** like: ``` -curl -k https://sdgapp.apps.pcfone.io/trades/getforever/10 +curl -k https://clientapp.apps.pcfone.io/trades/getforever/10 ``` The application will log messages like: @@ -419,7 +417,7 @@ The application will log messages like: Run the function update command using **curl** like: ``` -curl -k -X DELETE https://sdgapp.apps.pcfone.io/trades/destroyforever/10 +curl -k -X DELETE https://clientapp.apps.pcfone.io/trades/destroyforever/10 ``` The application will log messages like: @@ -431,7 +429,7 @@ The application will log messages like: Run the function update command using **curl** like: ``` -curl -k https://sdgapp.apps.pcfone.io/trades/querybycusipforever +curl -k https://clientapp.apps.pcfone.io/trades/querybycusipforever ``` The application will log messages like: @@ -443,7 +441,7 @@ The application will log messages like: Run the function update command using **curl** like: ``` -curl -k -X POST https://sdgapp.apps.pcfone.io/trades/functionupdateforever/10 +curl -k -X POST https://clientapp.apps.pcfone.io/trades/functionupdateforever/10 ``` The application will log messages like: @@ -455,7 +453,7 @@ The application will log messages like: Run the multi-threaded put forever command using **curl** like: ``` -curl -k -X POST https://sdgapp.apps.pcfone.io/trades/putforever/10/1024/5 +curl -k -X POST https://clientapp.apps.pcfone.io/trades/putforever/10/1024/5 ``` The application will log messages like: @@ -467,7 +465,7 @@ The application will log messages like: Run the multi-threaded get forever command using **curl** like: ``` -curl -k https://sdgapp.apps.pcfone.io/trades/getforever/10/5 +curl -k https://clientapp.apps.pcfone.io/trades/getforever/10/5 ``` The application will log messages like: @@ -478,7 +476,7 @@ The application will log messages like: Run the multi-threaded destroy forever command using **curl** like: ``` -curl -k -X DELETE https://sdgapp.apps.pcfone.io/trades/destroyforever/10/5 +curl -k -X DELETE https://clientapp.apps.pcfone.io/trades/destroyforever/10/5 ``` The application will log messages like: @@ -489,7 +487,7 @@ The application will log messages like: Run the multi-threaded query by cusip forever command using **curl** like: ``` -curl -k https://sdgapp.apps.pcfone.io/trades/querybycusipforever/5 +curl -k https://clientapp.apps.pcfone.io/trades/querybycusipforever/5 ``` The application will log messages like: @@ -500,7 +498,7 @@ The application will log messages like: Run the multi-threaded function update command using **curl** like: ``` -curl -k -X POST https://sdgapp.apps.pcfone.io/trades/functionupdateforever/10/5 +curl -k -X POST https://clientapp.apps.pcfone.io/trades/functionupdateforever/10/5 ``` The application will log messages like: @@ -511,7 +509,7 @@ The application will log messages like: Run the get one command using **curl** like: ``` -curl -k https://sdgapp.apps.pcfone.io/trades/getone/0 +curl -k https://clientapp.apps.pcfone.io/trades/getone/0 ``` The application will log messages like: @@ -521,7 +519,7 @@ The application will log messages like: Run the query one by cusip command using **curl** like: ``` -curl -k https://sdgapp.apps.pcfone.io/trades/queryonebycusip/AAPL +curl -k https://clientapp.apps.pcfone.io/trades/queryonebycusip/AAPL ``` The application will log messages like: @@ -531,7 +529,7 @@ The application will log messages like: Run the test command using **curl** like: ``` -curl -k -X POST https://sdgapp.apps.pcfone.io/trades/starttest/100000/1024 +curl -k -X POST https://clientapp.apps.pcfone.io/trades/starttest/100000/1024 [{"operation":"putforever","status":"SUCCESS","completionTime":0},{"operation":"getforever","status":"SUCCESS","completionTime":0},{"operation":"querybycusipforever","status":"SUCCESS","completionTime":0},{"operation":"functionupdateforever","status":"SUCCESS","completionTime":0}] ``` The application will log messages like: @@ -559,7 +557,7 @@ The application will log messages like: Run the stop operations command using **curl** like: ``` -curl -k -X POST https://sdgapp.apps.pcfone.io/trades/stopoperations +curl -k -X POST https://clientapp.apps.pcfone.io/trades/stopoperations ``` The application will log messages like: diff --git a/build.gradle b/build.gradle index 59d10bf..e9da045 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,7 @@ project(':client') { compile 'org.springframework.geode:spring-geode-starter:1.2.2.RELEASE' compile 'org.springframework.geode:spring-geode-starter-actuator:1.2.2.RELEASE' compile "org.springframework.boot:spring-boot-starter-web:2.2.2.RELEASE" + compile group: 'io.micrometer', name: 'micrometer-registry-prometheus', version: '1.3.2' } } @@ -70,11 +71,14 @@ project(':client-cq') { compile 'org.springframework.geode:spring-geode-starter:1.2.2.RELEASE' compile 'org.springframework.geode:spring-geode-starter-actuator:1.2.2.RELEASE' compile "org.springframework.boot:spring-boot-starter-web:2.2.2.RELEASE" + compile group: 'io.micrometer', name: 'micrometer-registry-prometheus', version: '1.3.2' } } project(':server') { dependencies { + compile 'org.projectlombok:lombok:1.18.8' + annotationProcessor 'org.projectlombok:lombok:1.18.10' provided 'io.pivotal.gemfire:geode-core:9.8.3' } } \ No newline at end of file diff --git a/client-cq/manifest.yml b/client-cq/manifest.yml index e8ed2f9..bc218b0 100644 --- a/client-cq/manifest.yml +++ b/client-cq/manifest.yml @@ -3,7 +3,7 @@ applications: - name: clientCqApp memory: 768M instances: 1 - path: build/libs/client_cq-0.0.1-SNAPSHOT.jar + path: build/libs/client-cq-0.0.1-SNAPSHOT.jar services: - pccService buildpacks: diff --git a/client-cq/src/main/java/io/pivotal/test/client/cq/TradeProcessor.java b/client-cq/src/main/java/io/pivotal/test/client/cq/TradeProcessor.java index b9d93f6..ec56d2d 100644 --- a/client-cq/src/main/java/io/pivotal/test/client/cq/TradeProcessor.java +++ b/client-cq/src/main/java/io/pivotal/test/client/cq/TradeProcessor.java @@ -1,15 +1,15 @@ package io.pivotal.test.client.cq; import org.apache.geode.cache.query.CqEvent; -import org.apache.geode.internal.logging.LogService; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.gemfire.listener.annotation.ContinuousQuery; import org.springframework.stereotype.Component; @Component public class TradeProcessor { - private static final Logger logger = LogService.getLogger(); + private static final Logger logger = LoggerFactory.getLogger(TradeProcessor.class); @ContinuousQuery(name = "TradeProcessor", query = "SELECT * FROM /Trades WHERE cusip = 'AAPL'") public void processTrade(CqEvent event) { diff --git a/client/manifest.yml b/client/manifest.yml index 621415e..e872c82 100644 --- a/client/manifest.yml +++ b/client/manifest.yml @@ -1,6 +1,6 @@ --- applications: - - name: sdgApp + - name: clientApp memory: 768M instances: 1 path: build/libs/client-0.0.1-SNAPSHOT.jar diff --git a/client/src/main/java/io/pivotal/test/client/Client.java b/client/src/main/java/io/pivotal/test/client/Client.java index 327654d..3b08427 100644 --- a/client/src/main/java/io/pivotal/test/client/Client.java +++ b/client/src/main/java/io/pivotal/test/client/Client.java @@ -1,9 +1,11 @@ package io.pivotal.test.client; import io.pivotal.test.client.domain.Trade; +import io.pivotal.test.client.metrics.OperationMeterBinder; +import io.pivotal.test.client.metrics.ServerMeterBuilder; import io.pivotal.test.client.service.TradeService; -import org.apache.geode.internal.logging.LogService; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; @@ -14,6 +16,7 @@ import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions; import org.springframework.data.gemfire.config.annotation.EnableStatistics; import org.springframework.geode.boot.autoconfigure.ContinuousQueryAutoConfiguration; +import org.springframework.scheduling.annotation.EnableScheduling; import java.util.Arrays; import java.util.List; @@ -24,9 +27,10 @@ @SpringBootApplication(exclude = ContinuousQueryAutoConfiguration.class) // disable subscriptions @EnableEntityDefinedRegions(basePackageClasses = Trade.class) @EnableStatistics +@EnableScheduling public class Client { - private static final Logger logger = LogService.getLogger(); + private static final Logger logger = LoggerFactory.getLogger(Client.class); @Autowired private TradeService service; @@ -101,6 +105,16 @@ ApplicationRunner runner() { }; } + @Bean + OperationMeterBinder getOperationMeterBuilder(){ + return new OperationMeterBinder(); + } + + @Bean + ServerMeterBuilder getServerMeterBuilder() { + return new ServerMeterBuilder(); + } + // @Bean // MappingPdxSerializer myCustomMappingPdxSerializer() { // logger.warn("XXX Client.myCustomMappingPdxSerializer ", new Exception()); diff --git a/client/src/main/java/io/pivotal/test/client/controller/AdminController.java b/client/src/main/java/io/pivotal/test/client/controller/AdminController.java index 6ebf474..03ef3d0 100644 --- a/client/src/main/java/io/pivotal/test/client/controller/AdminController.java +++ b/client/src/main/java/io/pivotal/test/client/controller/AdminController.java @@ -1,23 +1,23 @@ package io.pivotal.test.client.controller; -import io.pivotal.test.client.function.AdminFunctions; +import io.pivotal.test.client.metrics.MetricsProvider; import org.apache.geode.cache.client.Pool; import org.apache.geode.cache.client.PoolManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import java.util.Collection; -import java.util.Map; + +import static io.pivotal.test.client.Constants.METRICS_PATH; @RestController public class AdminController { -// @Autowired -// private AdminFunctions functions; + @Autowired + MetricsProvider provider; @GetMapping("/pools") @ResponseStatus(HttpStatus.OK) @@ -38,20 +38,9 @@ public String getPools() { return builder.toString(); } -// @GetMapping("/metrics/{type}") -// @ResponseStatus(HttpStatus.OK) -// public Object getMetrics(@PathVariable String type) { -// StringBuilder builder = new StringBuilder(); -// Map>> allServerMetrics = this.functions.getMetrics(type); -// for (Map.Entry>> serverMetrics : allServerMetrics.entrySet()) { -// builder.append("\n").append(serverMetrics.getKey()).append(":"); -// for (Map.Entry> serverMetricTypes : serverMetrics.getValue().entrySet()) { -// builder.append("\n\t").append(serverMetricTypes.getKey()).append(":"); -// for (Map.Entry serverMetric : serverMetricTypes.getValue().entrySet()) { -// builder.append("\n\t\t").append(serverMetric.getKey()).append("=").append(serverMetric.getValue()); -// } -// } -// } -// return builder.toString(); -// } + @GetMapping(METRICS_PATH) + @ResponseStatus(HttpStatus.OK) + public Object getMetrics() { + return this.provider.getMetrics(); + } } diff --git a/client/src/main/java/io/pivotal/test/client/controller/TradeController.java b/client/src/main/java/io/pivotal/test/client/controller/TradeController.java index 0d3273c..e6f747e 100644 --- a/client/src/main/java/io/pivotal/test/client/controller/TradeController.java +++ b/client/src/main/java/io/pivotal/test/client/controller/TradeController.java @@ -128,10 +128,4 @@ public OperationResponse[] startTest(@PathVariable int entries, @PathVariable in public OperationResponse stopOperations() { return this.service.stopOperations(); } - - @GetMapping(METRICS_PATH + METRICS_TYPE_PARAMETER) - @ResponseStatus(HttpStatus.OK) - public Object getMetrics(@PathVariable String type) { - return this.service.getMetrics(type); - } } diff --git a/client/src/main/java/io/pivotal/test/client/function/AdminFunctions.java b/client/src/main/java/io/pivotal/test/client/function/AdminFunctions.java index 91dc8b2..422f918 100644 --- a/client/src/main/java/io/pivotal/test/client/function/AdminFunctions.java +++ b/client/src/main/java/io/pivotal/test/client/function/AdminFunctions.java @@ -10,7 +10,10 @@ @OnRegion(region = "Trades", resultCollector = "adminResultCollector") public interface AdminFunctions { - @FunctionId("GetMetricsFunction") - //Map>> getMetrics(String type); - Object getMetrics(); + @FunctionId("GetMetricsMapFunction") + //Map>> getMetrics(String type); + Object getMetricsMap(); + + @FunctionId("GetMetricsListFunction") + Object getMetricsList(); } diff --git a/client/src/main/java/io/pivotal/test/client/function/AdminFunctionsResultCollector.java b/client/src/main/java/io/pivotal/test/client/function/AdminFunctionsResultCollector.java index dbedd2f..a4e43dd 100644 --- a/client/src/main/java/io/pivotal/test/client/function/AdminFunctionsResultCollector.java +++ b/client/src/main/java/io/pivotal/test/client/function/AdminFunctionsResultCollector.java @@ -3,7 +3,6 @@ import org.apache.geode.cache.execute.FunctionException; import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.distributed.DistributedMember; -import org.apache.geode.internal.logging.LogService; import org.springframework.stereotype.Component; import java.util.Collections; @@ -13,9 +12,9 @@ import java.util.concurrent.TimeUnit; @Component("adminResultCollector") -public class AdminFunctionsResultCollector implements ResultCollector { +public class AdminFunctionsResultCollector implements ResultCollector { - private Map results = new ConcurrentHashMap<>(); + private Map results = new ConcurrentHashMap<>(); @Override public Set getResult() throws FunctionException { @@ -51,15 +50,12 @@ public Set getResult(long timeout, TimeUnit unit) throws FunctionException, Inte } @Override - public void addResult(DistributedMember memberID, Map result) { - //LogService.getLogger().warn("XXX AdminFunctionsResultCollector.addResult memberID=" + memberID + "; result=" + result); - this.results.put(memberID.toString(), result); + public void addResult(DistributedMember memberID, Object result) { + this.results.put(memberID.getName(), result); } @Override - public void endResults() { - - } + public void endResults() {} @Override public void clearResults() { diff --git a/client/src/main/java/io/pivotal/test/client/metrics/ClientAndServerMetrics.java b/client/src/main/java/io/pivotal/test/client/metrics/ClientAndServerMetrics.java index 5b7db84..204d465 100644 --- a/client/src/main/java/io/pivotal/test/client/metrics/ClientAndServerMetrics.java +++ b/client/src/main/java/io/pivotal/test/client/metrics/ClientAndServerMetrics.java @@ -7,13 +7,13 @@ @Getter @ToString -public class Metrics { +public class ClientAndServerMetrics { private Map clientMetrics; private Map serverMetrics; - public Metrics(Map clientMetrics, Map serverMetrics) { + public ClientAndServerMetrics(Map clientMetrics, Map serverMetrics) { this.clientMetrics = clientMetrics; this.serverMetrics = serverMetrics; } diff --git a/client/src/main/java/io/pivotal/test/client/metrics/MetricsHandlerFunction.java b/client/src/main/java/io/pivotal/test/client/metrics/MetricsHandlerFunction.java index 929410a..c0bc34b 100644 --- a/client/src/main/java/io/pivotal/test/client/metrics/MetricsHandlerFunction.java +++ b/client/src/main/java/io/pivotal/test/client/metrics/MetricsHandlerFunction.java @@ -1,4 +1,9 @@ package io.pivotal.test.client.metrics; -public class MetricsHandlerFunction { +import io.pivotal.test.metrics.Metric; + +@FunctionalInterface +public interface MetricsHandlerFunction { + + void process(String serverName, Metric metric); } diff --git a/client/src/main/java/io/pivotal/test/client/metrics/MetricsProvider.java b/client/src/main/java/io/pivotal/test/client/metrics/MetricsProvider.java index 41ff96e..6b5d9fb 100644 --- a/client/src/main/java/io/pivotal/test/client/metrics/MetricsProvider.java +++ b/client/src/main/java/io/pivotal/test/client/metrics/MetricsProvider.java @@ -2,14 +2,23 @@ import io.pivotal.test.client.function.AdminFunctions; import io.pivotal.test.client.service.TradeService; +import io.pivotal.test.metrics.Metric; +import io.pivotal.test.metrics.MetricsHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; @Component -public class ServerMetricsProvider { +public class MetricsProvider { @Autowired private TradeService service; @@ -17,24 +26,26 @@ public class ServerMetricsProvider { @Autowired private AdminFunctions adminFunctions; - public Map getServerMetrics(String type) { - Map serverMetrics = null; - if (type.equals("all") || type.equals("server")) { - Iterable serverMetricsIter = (Iterable) this.adminFunctions.getMetrics(); - serverMetrics = (Map) serverMetricsIter.iterator().next(); - } - return serverMetrics; + private Map> serverMetrics = new ConcurrentHashMap<>(); + + private static final Logger logger = LoggerFactory.getLogger(MetricsProvider.class); + + public Map getServerMetrics() { + Iterable serverMetricsIter = (Iterable) this.adminFunctions.getMetricsMap(); + return (Map) serverMetricsIter.iterator().next(); } - private Map getClientMetrics(String type) { - Map clientMetrics = null; - if (type.equals("all") || type.equals("client")) { - clientMetrics = new TreeMap(); - addOperationMetrics(clientMetrics); - MetricsHelper.addOSMetrics(clientMetrics); - MetricsHelper.addGCMetrics(clientMetrics); - MetricsHelper.addMemoryMetrics(clientMetrics); - } + public Map getServerMetricsList() { + Iterable serverMetricsIter = (Iterable) this.adminFunctions.getMetricsList(); + return (Map) serverMetricsIter.iterator().next(); + } + + private Map getClientMetrics() { + Map clientMetrics = new TreeMap(); + addOperationMetrics(clientMetrics); + MetricsHelper.addStatisticsMetrics(clientMetrics); + MetricsHelper.addGCMetrics(clientMetrics); + MetricsHelper.addMemoryMetrics(clientMetrics); return clientMetrics; } @@ -48,13 +59,76 @@ private void addOperationMetrics(Map clientMetrics) { operationMetrics.put("functionUpdates", this.service.getFunctionUpdateOperations()); } - public Object getMetrics(String type) { - return new ClientAndServerMetrics(getClientMetrics(type), getServerMetrics(type)); + public Object getMetrics() { + return new ClientAndServerMetrics(getClientMetrics(), getServerMetrics()); + } + + public double getServerMetric(String serverName, Metric metric) { + Map metrics = this.serverMetrics.get(serverName); + Number currentAtomicValue = metrics.get(metric.getMapName()); + double currentValue = 0; + if (currentAtomicValue == null) { + logger.warn("Metric {} cannot be retrieved since it does not exist", metric.getName()); + } else { + if (currentAtomicValue instanceof AtomicInteger) { + AtomicInteger ai = (AtomicInteger) currentAtomicValue; + currentValue = ai.get(); + } else if (currentAtomicValue instanceof AtomicLong && metric.getValue() instanceof Long) { + AtomicLong al = (AtomicLong) currentAtomicValue; + currentValue = al.get(); + } else if (currentAtomicValue instanceof AtomicLong && metric.getValue() instanceof Double) { + AtomicLong al = (AtomicLong) currentAtomicValue; + currentValue = Double.longBitsToDouble(al.get()); + } + } + return currentValue; + } + + @Scheduled(fixedDelay = 5000) + public void updateServerMetrics() { + MetricsHandlerFunction function = (serverName, metric) -> updateServerMetric(serverName, metric); + processServerMetrics(function); + } + + public void addServerMetric(String serverName, Metric metric, Number metricValue) { + Map metrics = this.serverMetrics.get(serverName); + if (metrics == null) { + metrics = new ConcurrentHashMap<>(); + this.serverMetrics.put(serverName, metrics); + } + metrics.put(metric.getMapName(), metricValue); } - public int getMetric(String metricName) { - System.out.println(Thread.currentThread().getName() + ": ServerMetricsProvider.getMetric metricName=" + metricName); - return 100; - //return this.serverMetrics.get(metricName).get(); + public void updateServerMetric(String serverName, Metric metric) { + Map metrics = this.serverMetrics.get(serverName); + Number currentValue = metrics.get(metric.getMapName()); + if (currentValue == null) { + logger.warn("Metric {} cannot be updated since it does not exist", metric.getName()); + } else { + Number newValue = metric.getValue(); + if (newValue instanceof Integer && currentValue instanceof AtomicInteger) { + AtomicInteger ai = (AtomicInteger) currentValue; + Integer i = (Integer) newValue; + ai.set(i); + } else if (newValue instanceof Long && currentValue instanceof AtomicLong) { + AtomicLong al = (AtomicLong) currentValue; + Long l = (Long) newValue; + al.set(l); + } else if (newValue instanceof Double && currentValue instanceof AtomicLong) { + AtomicLong al = (AtomicLong) currentValue; + Long l = Double.doubleToLongBits((Double) newValue); + al.set(l); + } + } + } + + public void processServerMetrics(MetricsHandlerFunction function) { + Map> allMetrics = getServerMetricsList(); + for (Map.Entry> metrics : allMetrics.entrySet()) { + String serverName = metrics.getKey(); + for (Metric metric : metrics.getValue()) { + function.process(serverName, metric); + } + } } } diff --git a/client/src/main/java/io/pivotal/test/client/metrics/OperationMeterBinder.java b/client/src/main/java/io/pivotal/test/client/metrics/OperationMeterBinder.java index 81b3ab0..ca96027 100644 --- a/client/src/main/java/io/pivotal/test/client/metrics/OperationMeterBinder.java +++ b/client/src/main/java/io/pivotal/test/client/metrics/OperationMeterBinder.java @@ -6,7 +6,7 @@ import io.pivotal.test.client.service.TradeService; import org.springframework.beans.factory.annotation.Autowired; -public class OperationMetricsBinder implements MeterBinder { +public class OperationMeterBinder implements MeterBinder { @Autowired private TradeService service; diff --git a/client/src/main/java/io/pivotal/test/client/metrics/ServerMeterBuilder.java b/client/src/main/java/io/pivotal/test/client/metrics/ServerMeterBuilder.java index 3f0c799..3378792 100644 --- a/client/src/main/java/io/pivotal/test/client/metrics/ServerMeterBuilder.java +++ b/client/src/main/java/io/pivotal/test/client/metrics/ServerMeterBuilder.java @@ -2,19 +2,50 @@ import io.micrometer.core.instrument.Gauge; import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tags; +import io.micrometer.core.instrument.binder.BaseUnits; import io.micrometer.core.instrument.binder.MeterBinder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -public class ServerMetricsBuilder implements MeterBinder { +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +public class ServerMeterBuilder implements MeterBinder { @Autowired private MetricsProvider provider; + private static final Logger logger = LoggerFactory.getLogger(ServerMeterBuilder.class); + @Override public void bindTo(MeterRegistry registry) { MetricsHandlerFunction function = (serverName, metric) -> { - //Gauge gauge = Gauge.builder(metricName, provider, provider -> provider.getServerMetric(metricName)).register(registry); - System.out.println(Thread.currentThread().getName() + ": XXX ServerMetricsBuilder.bindTo serverName=" + serverName + "; metric=" + metric); + Tags tags = Tags.of("member", serverName); + if (metric.getType() != null) { + tags = tags.and("type", metric.getType()); + } + Gauge.Builder builder = Gauge + .builder(metric.getName(), this.provider, provider -> provider.getServerMetric(serverName, metric)) + .tags(tags); + if (metric.isMemoryType()) { + builder.baseUnit(BaseUnits.BYTES); + } + builder.register(registry); + Number metricCounter; + if (metric.getValue() instanceof Integer) { + metricCounter = new AtomicInteger((Integer) metric.getValue()); + this.provider.addServerMetric(serverName, metric, metricCounter); + } else if (metric.getValue() instanceof Long) { + metricCounter = new AtomicLong((Long) metric.getValue()); + this.provider.addServerMetric(serverName, metric, metricCounter); + } else if (metric.getValue() instanceof Double) { + long metricValueL = Double.doubleToLongBits((Double) metric.getValue()); + metricCounter = new AtomicLong(metricValueL); + this.provider.addServerMetric(serverName, metric, metricCounter); + } + logger.info("Bound gauge server={}; metric={}", serverName, metric); }; this.provider.processServerMetrics(function); } diff --git a/client/src/main/java/io/pivotal/test/client/service/TradeService.java b/client/src/main/java/io/pivotal/test/client/service/TradeService.java index 37573ef..f2fb2b8 100644 --- a/client/src/main/java/io/pivotal/test/client/service/TradeService.java +++ b/client/src/main/java/io/pivotal/test/client/service/TradeService.java @@ -2,13 +2,10 @@ import io.pivotal.test.client.domain.CusipHelper; import io.pivotal.test.client.domain.Trade; -import io.pivotal.test.client.function.AdminFunctions; import io.pivotal.test.client.function.TradeFunctions; -import io.pivotal.test.client.metrics.Metrics; -import io.pivotal.test.client.metrics.MetricsHelper; import io.pivotal.test.client.repository.TradeRepository; -import org.apache.geode.internal.logging.LogService; -import org.apache.logging.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,10 +13,8 @@ import java.math.BigInteger; import java.util.Collection; import java.util.Collections; -import java.util.Map; import java.util.Optional; import java.util.Random; -import java.util.TreeMap; import java.util.concurrent.atomic.AtomicInteger; import static io.pivotal.test.client.Constants.*; @@ -33,9 +28,6 @@ public class TradeService { @Autowired private TradeFunctions tradeFunctions; - @Autowired - private AdminFunctions adminFunctions; - private final AtomicInteger putOperations = new AtomicInteger(); private final AtomicInteger getOperations = new AtomicInteger(); @@ -48,7 +40,7 @@ public class TradeService { private volatile boolean continueOperations; - private static final Logger logger = LogService.getLogger(); + private static final Logger logger = LoggerFactory.getLogger(TradeService.class); private static final Random RANDOM = new Random(); @@ -237,6 +229,7 @@ public void functionUpdateForever(int numEntries) { public OperationResponse putForever(final int numEntries, final int entrySize, Optional numThreads) { for (int i=0; i putForever(numEntries, entrySize)); + thread.setDaemon(true); thread.start(); } return new OperationResponse(PUT_FOREVER, Status.SUCCESS, 0); @@ -245,6 +238,7 @@ public OperationResponse putForever(final int numEntries, final int entrySize, O public OperationResponse getForever(final int numEntries, Optional numThreads) { for (int i=0; i getForever(numEntries)); + thread.setDaemon(true); thread.start(); } return new OperationResponse(GET_FOREVER, Status.SUCCESS, 0); @@ -253,6 +247,7 @@ public OperationResponse getForever(final int numEntries, Optional numT public OperationResponse destroyForever(final int numEntries, Optional numThreads) { for (int i=0; i destroyForever(numEntries)); + thread.setDaemon(true); thread.start(); } return new OperationResponse(DESTROY_FOREVER, Status.SUCCESS, 0); @@ -261,6 +256,7 @@ public OperationResponse destroyForever(final int numEntries, Optional public OperationResponse queryByCusipForever(Optional numThreads) { for (int i=0; i queryByCusipForever()); + thread.setDaemon(true); thread.start(); } return new OperationResponse(QUERY_BY_CUSIP_FOREVER, Status.SUCCESS, 0); @@ -269,6 +265,7 @@ public OperationResponse queryByCusipForever(Optional numThreads) { public OperationResponse functionUpdateForever(final int numEntries, Optional numThreads) { for (int i=0; i functionUpdateForever(numEntries)); + thread.setDaemon(true); thread.start(); } return new OperationResponse(FUNCTION_UPDATE_FOREVER, Status.SUCCESS, 0); @@ -288,10 +285,6 @@ public OperationResponse stopOperations() { return new OperationResponse(STOP_OPERATIONS, Status.SUCCESS, 0); } - public Object getMetrics(String type) { - return new Metrics(getClientMetrics(type), getServerMetrics(type)); - } - private void put(int index, int entrySize, boolean log) { Trade trade = new Trade(String.valueOf(index), CusipHelper.getCusip(), RANDOM.nextInt(100), new BigDecimal(BigInteger.valueOf(RANDOM.nextInt(100000)), 2), new byte[entrySize]); trade = this.repository.save(trade); @@ -329,38 +322,27 @@ private Object executUpdateFunction(int index) { return this.tradeFunctions.updateTrade(Collections.singleton(String.valueOf(index)), RANDOM.nextInt(100), new BigDecimal(BigInteger.valueOf(RANDOM.nextInt(100000)), 2)); } - private Map getServerMetrics(String type) { - Map serverMetrics = null; - if (type.equals("all") || type.equals("server")) { - Iterable serverMetricsIter = (Iterable) this.adminFunctions.getMetrics(); - serverMetrics = (Map) serverMetricsIter.iterator().next(); - } - return serverMetrics; + private boolean continueOperations() { + return this.continueOperations; } - private Map getClientMetrics(String type) { - Map clientMetrics = null; - if (type.equals("all") || type.equals("client")) { - clientMetrics = new TreeMap(); - addOperationMetrics(clientMetrics); - MetricsHelper.addOSMetrics(clientMetrics); - MetricsHelper.addGCMetrics(clientMetrics); - MetricsHelper.addMemoryMetrics(clientMetrics); - } - return clientMetrics; + public int getGetOperations() { + return this.getOperations.get(); } - private void addOperationMetrics(Map clientMetrics) { - Map operationMetrics = new TreeMap(); - clientMetrics.put("operations", operationMetrics); - operationMetrics.put("puts", this.putOperations.get()); - operationMetrics.put("gets", this.getOperations.get()); - operationMetrics.put("destroys", this.destroyOperations.get()); - operationMetrics.put("cusipQueries", this.queryByCusipOperations.get()); - operationMetrics.put("functionUpdates", this.functionUpdateOperations.get()); + public int getPutOperations() { + return this.putOperations.get(); } - private boolean continueOperations() { - return this.continueOperations; + public int getDestroyOperations() { + return this.destroyOperations.get(); + } + + public int getQueryByCusipOperations() { + return this.queryByCusipOperations.get(); + } + + public int getFunctionUpdateOperations() { + return this.functionUpdateOperations.get(); } } diff --git a/client/src/main/java/io/pivotal/test/metrics/Metric.java b/client/src/main/java/io/pivotal/test/metrics/Metric.java index 853ae64..e0a794d 100644 --- a/client/src/main/java/io/pivotal/test/metrics/Metric.java +++ b/client/src/main/java/io/pivotal/test/metrics/Metric.java @@ -8,14 +8,22 @@ public class Metric implements Serializable { private Number value; - private boolean isCounter; + private String category; + + private String type; private static final long serialVersionUID = 1L; - public Metric(String name, Number value, boolean isCounter) { + + public Metric(String name, Number value, String category) { + this(name, value, category, null); + } + + public Metric(String name, Number value, String category, String type) { this.name = name; this.value = value; - this.isCounter = isCounter; + this.category = category; + this.type = type; } public String getName() { @@ -26,7 +34,41 @@ public Number getValue() { return this.value; } - public boolean isCounter() { - return this.isCounter; + public String getCategory() { + return this.category; + } + + public String getType() { + return this.type; + } + + public String toString() { + return new StringBuilder() + .append(getClass().getSimpleName()) + .append("[") + .append("name=") + .append(this.name) + .append("; value=") + .append(this.value) + .append("; valueClass=") + .append(this.value.getClass().getSimpleName()) + .append("; category=") + .append(this.category) + .append("; type=") + .append(this.type) + .append("]") + .toString(); + } + + public boolean isMemoryType() { + return this.category.equals("VMMemoryPoolStats"); + } + + public String getMapName() { + String mapName = this.name; + if (this.type != null) { + mapName = mapName + "." + this.type; + } + return mapName; } } diff --git a/client/src/main/java/io/pivotal/test/metrics/MetricsHelper.java b/client/src/main/java/io/pivotal/test/metrics/MetricsHelper.java index 7b14ddf..8465348 100644 --- a/client/src/main/java/io/pivotal/test/metrics/MetricsHelper.java +++ b/client/src/main/java/io/pivotal/test/metrics/MetricsHelper.java @@ -1,38 +1,45 @@ -package io.pivotal.test.client.metrics; +package io.pivotal.test.metrics; import org.apache.geode.StatisticDescriptor; import org.apache.geode.Statistics; import org.apache.geode.StatisticsType; -import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.internal.statistics.platform.LinuxSystemStats; -import org.apache.geode.management.ManagementService; -import org.apache.geode.management.OSMetrics; -import org.apache.geode.management.internal.beans.MemberMBean; import java.lang.management.GarbageCollectorMXBean; import java.lang.management.ManagementFactory; import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryUsage; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.stream.Collectors; public class MetricsHelper { - public static void addOSMetrics(Map allMetrics) { - InternalDistributedSystem system = (InternalDistributedSystem) CacheFactory.getAnyInstance().getDistributedSystem(); + private static final InternalDistributedSystem system = + (InternalDistributedSystem) CacheFactory.getAnyInstance().getDistributedSystem(); - Map osMetrics = new TreeMap(); - allMetrics.put("os", osMetrics); + private static final String[] typeNames = new String[] { + "LinuxSystemStats", "VMStats" + }; + + private static final List types = + Arrays.stream(typeNames).map(name -> system.findType(name)).collect(Collectors.toList()); + + public static void addStatisticsMetrics(Map allMetrics) { + for (StatisticsType type : types) { + addMetrics(allMetrics, type); + } + } - // If the linux system statistics exist, add them to the os metrics map. - // Otherwise add the available stats from the osmetrics. - Statistics[] systemStatisticsArr = system.findStatisticsByType(LinuxSystemStats.getType()); + public static void addMetrics(Map allMetrics, StatisticsType type) { + Map osMetrics = new TreeMap(); + allMetrics.put(type.getName(), osMetrics); + Statistics[] systemStatisticsArr = system.findStatisticsByType(type); if (systemStatisticsArr.length > 0) { Statistics systemStatistics = systemStatisticsArr[0]; - StatisticsType type = systemStatistics.getType(); for (StatisticDescriptor descriptor : type.getStatistics()) { String statName = descriptor.getName(); Number statValue = systemStatistics.get(statName); diff --git a/server/src/main/java/io/pivotal/test/metrics/Metric.java b/server/src/main/java/io/pivotal/test/metrics/Metric.java index 09705dc..e0a794d 100644 --- a/server/src/main/java/io/pivotal/test/metrics/Metric.java +++ b/server/src/main/java/io/pivotal/test/metrics/Metric.java @@ -1,4 +1,4 @@ -package io.pivotal.test.server.metrics; +package io.pivotal.test.metrics; import java.io.Serializable; @@ -8,14 +8,22 @@ public class Metric implements Serializable { private Number value; - private boolean isCounter; + private String category; + + private String type; private static final long serialVersionUID = 1L; - public Metric(String name, Number value, boolean isCounter) { + + public Metric(String name, Number value, String category) { + this(name, value, category, null); + } + + public Metric(String name, Number value, String category, String type) { this.name = name; this.value = value; - this.isCounter = isCounter; + this.category = category; + this.type = type; } public String getName() { @@ -26,7 +34,41 @@ public Number getValue() { return this.value; } - public boolean isCounter() { - return this.isCounter; + public String getCategory() { + return this.category; + } + + public String getType() { + return this.type; + } + + public String toString() { + return new StringBuilder() + .append(getClass().getSimpleName()) + .append("[") + .append("name=") + .append(this.name) + .append("; value=") + .append(this.value) + .append("; valueClass=") + .append(this.value.getClass().getSimpleName()) + .append("; category=") + .append(this.category) + .append("; type=") + .append(this.type) + .append("]") + .toString(); + } + + public boolean isMemoryType() { + return this.category.equals("VMMemoryPoolStats"); + } + + public String getMapName() { + String mapName = this.name; + if (this.type != null) { + mapName = mapName + "." + this.type; + } + return mapName; } } diff --git a/server/src/main/java/io/pivotal/test/metrics/MetricsHelper.java b/server/src/main/java/io/pivotal/test/metrics/MetricsHelper.java index 107fd03..a809a1b 100644 --- a/server/src/main/java/io/pivotal/test/metrics/MetricsHelper.java +++ b/server/src/main/java/io/pivotal/test/metrics/MetricsHelper.java @@ -1,60 +1,51 @@ -package io.pivotal.test.server.metrics; +package io.pivotal.test.metrics; import org.apache.geode.StatisticDescriptor; import org.apache.geode.Statistics; import org.apache.geode.StatisticsType; -import org.apache.geode.cache.Cache; import org.apache.geode.cache.CacheFactory; import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.internal.statistics.platform.LinuxSystemStats; -import org.apache.geode.management.ManagementService; -import org.apache.geode.management.OSMetrics; -import org.apache.geode.management.internal.beans.MemberMBean; import java.lang.management.GarbageCollectorMXBean; import java.lang.management.ManagementFactory; import java.lang.management.MemoryPoolMXBean; +import java.lang.management.MemoryType; import java.lang.management.MemoryUsage; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.stream.Collectors; public class MetricsHelper { - public static void addOSMetrics(Map allMetrics) { - Cache cache = CacheFactory.getAnyInstance(); - InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem(); + private static final InternalDistributedSystem system = + (InternalDistributedSystem) CacheFactory.getAnyInstance().getDistributedSystem(); - Map osMetrics = new TreeMap(); - allMetrics.put("os", osMetrics); - ManagementService managementService = ManagementService.getManagementService(cache); - MemberMBean bean = (MemberMBean) managementService.getMemberMXBean(); - OSMetrics osm = bean.showOSMetrics(); - osMetrics.put("fdsOpen", osm.getOpenFileDescriptorCount()); - osMetrics.put("fdLimit", osm.getMaxFileDescriptorCount()); - osMetrics.put("processCpuTime", osm.getProcessCpuTime()); - osMetrics.put("name", osm.getName()); - osMetrics.put("version", osm.getVersion()); - osMetrics.put("architecture", osm.getArch()); + private static final String[] typeNames = new String[] { + "LinuxSystemStats", "VMStats", "CacheServerStats", "DistributionStats" + }; + + private static final List types = + Arrays.stream(typeNames).map(name -> system.findType(name)).collect(Collectors.toList()); + + public static void addStatisticsMetrics(Map allMetrics) { + for (StatisticsType type : types) { + addMetrics(allMetrics, type); + } + } - // If the linux system statistics exist, add them to the os metrics map. - // Otherwise add the available stats from the osmetrics. - Statistics[] systemStatisticsArr = system.findStatisticsByType(LinuxSystemStats.getType()); + public static void addMetrics(Map allMetrics, StatisticsType type) { + Map osMetrics = new TreeMap(); + allMetrics.put(type.getName(), osMetrics); + Statistics[] systemStatisticsArr = system.findStatisticsByType(type); if (systemStatisticsArr.length > 0) { Statistics systemStatistics = systemStatisticsArr[0]; - StatisticsType type = systemStatistics.getType(); for (StatisticDescriptor descriptor : type.getStatistics()) { String statName = descriptor.getName(); Number statValue = systemStatistics.get(statName); osMetrics.put(statName, statValue); } - } else { - osMetrics.put("totalMemory", osm.getTotalPhysicalMemorySize()); - osMetrics.put("freeMemory", osm.getFreePhysicalMemorySize()); - osMetrics.put("cpus", osm.getAvailableProcessors()); - osMetrics.put("loadAverage1", osm.getSystemLoadAverage()); - osMetrics.put("allocatedSwap", osm.getTotalSwapSpaceSize()); - osMetrics.put("freeSwap", osm.getFreeSwapSpaceSize()); } } @@ -68,14 +59,6 @@ public static void addGCMetrics(Map allMetrics) { } } - public static void addGCMetrics(List allMetrics) { - List gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); - for (GarbageCollectorMXBean gcBean : gcBeans) { - allMetrics.add(new Metric(gcBean.getName() + "_collections", gcBean.getCollectionCount(), true)); - allMetrics.add(new Metric(gcBean.getName() + "_collectionTime", gcBean.getCollectionTime(), true)); - } - } - public static void addMemoryMetrics(Map allMetrics) { Map memoryMetrics = new TreeMap(); allMetrics.put("memory", memoryMetrics); @@ -90,4 +73,42 @@ public static void addMemoryMetrics(Map allMetrics) { } } } + + public static void addStatisticsMetrics(List allMetrics) { + for (StatisticsType type : types) { + addMetrics(allMetrics, type); + } + } + + public static void addMetrics(List allMetrics, StatisticsType type) { + Statistics[] systemStatsArr = system.findStatisticsByType(type); + if (systemStatsArr.length > 0) { + Statistics systemStatistics = systemStatsArr[0]; + for (StatisticDescriptor descriptor : type.getStatistics()) { + String statName = descriptor.getName(); + Number statValue = systemStatistics.get(statName); + allMetrics.add(new Metric(statName, statValue, type.getName())); + } + } + } + + public static void addGCMetrics(List allMetrics) { + List gcBeans = ManagementFactory.getGarbageCollectorMXBeans(); + for (GarbageCollectorMXBean gcBean : gcBeans) { + allMetrics.add(new Metric("server.jvm.gc.collections", gcBean.getCollectionCount(), "VMGCStats", gcBean.getName())); + allMetrics.add(new Metric("server.jvm.gc.collection.time", gcBean.getCollectionTime(), "VMGCStats", gcBean.getName())); + } + } + + public static void addMemoryMetrics(List allMetrics) { + List memoryBeans = ManagementFactory.getMemoryPoolMXBeans(); + for (MemoryPoolMXBean memoryBean : memoryBeans) { + if (memoryBean.getType().equals(MemoryType.HEAP)) { + String memoryBeanName = memoryBean.getName().replaceAll(" ", ""); + MemoryUsage usage = memoryBean.getUsage(); + allMetrics.add(new Metric("server.jvm.memory.used", usage.getUsed(), "VMMemoryPoolStats", memoryBeanName)); + allMetrics.add(new Metric("server.jvm.memory.max", usage.getMax(), "VMMemoryPoolStats", memoryBeanName)); + } + } + } } diff --git a/server/src/main/java/io/pivotal/test/server/function/GetMetricsListFunction.java b/server/src/main/java/io/pivotal/test/server/function/GetMetricsListFunction.java index 6568e01..2fe1a16 100644 --- a/server/src/main/java/io/pivotal/test/server/function/GetMetricsListFunction.java +++ b/server/src/main/java/io/pivotal/test/server/function/GetMetricsListFunction.java @@ -1,4 +1,31 @@ package io.pivotal.test.server.function; -public class GetMetricsListFunction { +import io.pivotal.test.metrics.Metric; +import io.pivotal.test.metrics.MetricsHelper; +import org.apache.geode.cache.execute.Function; +import org.apache.geode.cache.execute.FunctionContext; + +import java.util.ArrayList; +import java.util.List; + +public class GetMetricsListFunction implements Function { + + @Override + public void execute(FunctionContext context) { + List allMetrics = new ArrayList<>(); + MetricsHelper.addStatisticsMetrics(allMetrics); + MetricsHelper.addGCMetrics(allMetrics); + MetricsHelper.addMemoryMetrics(allMetrics); + context.getResultSender().lastResult(allMetrics); + } + + @Override + public String getId() { + return getClass().getSimpleName(); + } + + @Override + public boolean optimizeForWrite() { + return true; + } } diff --git a/server/src/main/java/io/pivotal/test/server/function/GetMetricsMapFunction.java b/server/src/main/java/io/pivotal/test/server/function/GetMetricsMapFunction.java index 919825a..ff4a34e 100644 --- a/server/src/main/java/io/pivotal/test/server/function/GetMetricsMapFunction.java +++ b/server/src/main/java/io/pivotal/test/server/function/GetMetricsMapFunction.java @@ -7,13 +7,12 @@ import java.util.Map; import java.util.TreeMap; -public class GetMetricsFunction implements Function { +public class GetMetricsMapFunction implements Function { @Override public void execute(FunctionContext context) { Map allMetrics = new TreeMap(); - MetricsHelper.addOSMetrics(allMetrics); - MetricsHelper.addVMMetrics(allMetrics); + MetricsHelper.addStatisticsMetrics(allMetrics); MetricsHelper.addGCMetrics(allMetrics); MetricsHelper.addMemoryMetrics(allMetrics); context.getResultSender().lastResult(allMetrics);