-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added prometheus endpoint and server metrics
- Loading branch information
Showing
12 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
client/src/main/java/io/pivotal/test/client/metrics/MetricsHandlerFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.pivotal.test.client.metrics; | ||
|
||
public class MetricsHandlerFunction { | ||
} |
60 changes: 60 additions & 0 deletions
60
client/src/main/java/io/pivotal/test/client/metrics/MetricsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.pivotal.test.client.metrics; | ||
|
||
import io.pivotal.test.client.function.AdminFunctions; | ||
import io.pivotal.test.client.service.TradeService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
@Component | ||
public class ServerMetricsProvider { | ||
|
||
@Autowired | ||
private TradeService service; | ||
|
||
@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 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; | ||
} | ||
|
||
private void addOperationMetrics(Map clientMetrics) { | ||
Map operationMetrics = new TreeMap(); | ||
clientMetrics.put("operations", operationMetrics); | ||
operationMetrics.put("puts", this.service.getPutOperations()); | ||
operationMetrics.put("gets", this.service.getGetOperations()); | ||
operationMetrics.put("destroys", this.service.getDestroyOperations()); | ||
operationMetrics.put("cusipQueries", this.service.getQueryByCusipOperations()); | ||
operationMetrics.put("functionUpdates", this.service.getFunctionUpdateOperations()); | ||
} | ||
|
||
public Object getMetrics(String type) { | ||
return new ClientAndServerMetrics(getClientMetrics(type), getServerMetrics(type)); | ||
} | ||
|
||
public int getMetric(String metricName) { | ||
System.out.println(Thread.currentThread().getName() + ": ServerMetricsProvider.getMetric metricName=" + metricName); | ||
return 100; | ||
//return this.serverMetrics.get(metricName).get(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
client/src/main/java/io/pivotal/test/client/metrics/OperationMeterBinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.pivotal.test.client.metrics; | ||
|
||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
import io.pivotal.test.client.service.TradeService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class OperationMetricsBinder implements MeterBinder { | ||
|
||
@Autowired | ||
private TradeService service; | ||
|
||
@Override | ||
public void bindTo(MeterRegistry registry) { | ||
Gauge | ||
.builder("client.puts", service, TradeService::getPutOperations) | ||
.description("Number of put operations") | ||
.register(registry); | ||
|
||
Gauge | ||
.builder("client.gets", service, TradeService::getGetOperations) | ||
.description("Number of get operations") | ||
.register(registry); | ||
|
||
Gauge | ||
.builder("client.destroys", service, TradeService::getDestroyOperations) | ||
.description("Number of destroy operations") | ||
.register(registry); | ||
|
||
Gauge | ||
.builder("client.queries.by.cusip", service, TradeService::getQueryByCusipOperations) | ||
.description("Number of queries by cusip operations") | ||
.register(registry); | ||
|
||
Gauge | ||
.builder("client.function.updates", service, TradeService::getFunctionUpdateOperations) | ||
.description("Number of function update operations") | ||
.register(registry); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
client/src/main/java/io/pivotal/test/client/metrics/ServerMeterBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.pivotal.test.client.metrics; | ||
|
||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class ServerMetricsBuilder implements MeterBinder { | ||
|
||
@Autowired | ||
private MetricsProvider provider; | ||
|
||
@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); | ||
}; | ||
this.provider.processServerMetrics(function); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.pivotal.test.metrics; | ||
|
||
import java.io.Serializable; | ||
|
||
public class Metric implements Serializable { | ||
|
||
private String name; | ||
|
||
private Number value; | ||
|
||
private boolean isCounter; | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public Metric(String name, Number value, boolean isCounter) { | ||
this.name = name; | ||
this.value = value; | ||
this.isCounter = isCounter; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public Number getValue() { | ||
return this.value; | ||
} | ||
|
||
public boolean isCounter() { | ||
return this.isCounter; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
gfsh \ | ||
-e "connect --url=$URL --user=$USERNAME --password=$PASSWORD --skip-ssl-validation" \ | ||
-e "set variable --name=APP_RESULT_VIEWER --value=any" \ | ||
-e "export stack-traces" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.pivotal.test.server.metrics; | ||
|
||
import java.io.Serializable; | ||
|
||
public class Metric implements Serializable { | ||
|
||
private String name; | ||
|
||
private Number value; | ||
|
||
private boolean isCounter; | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public Metric(String name, Number value, boolean isCounter) { | ||
this.name = name; | ||
this.value = value; | ||
this.isCounter = isCounter; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public Number getValue() { | ||
return this.value; | ||
} | ||
|
||
public boolean isCounter() { | ||
return this.isCounter; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
server/src/main/java/io/pivotal/test/server/function/GetMetricsListFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package io.pivotal.test.server.function; | ||
|
||
public class GetMetricsListFunction { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters