Skip to content

Commit

Permalink
Prepares reporting metrics to an external system like prometheus.
Browse files Browse the repository at this point in the history
  • Loading branch information
andyHa committed Oct 5, 2018
1 parent aec89ab commit 18eb8c1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<url>http://www.sirius-lib.net</url>

<properties>
<sirius.kernel>12.0-rc25</sirius.kernel>
<sirius.web>19.0-rc22</sirius.web>
<sirius.db>5.0-rc31</sirius.db>
<sirius.kernel>12.0-rc26</sirius.kernel>
<sirius.web>19.0-rc23</sirius.web>
<sirius.db>5.0-rc33</sirius.db>
</properties>

<dependencies>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/sirius/biz/cluster/ClusterController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class ClusterController implements Controller {
public static final String PERMISSION_SYSTEM_CLUSTER = "permission-system-cluster";

public static final String RESPONSE_NAME = "name";
public static final String RESPONSE_LABEL = "label";
public static final String RESPONSE_CODE = "code";
public static final String RESPONSE_DESCRIPTION = "description";
public static final String RESPONSE_NODE_STATE = "nodeState";
public static final String RESPONSE_UPTIME = "uptime";
Expand Down Expand Up @@ -104,7 +106,8 @@ public void nodeInfo(WebContext ctx, JSONStructuredOutput out) {
out.beginArray(RESPONSE_METRICS);
for (Metric m : metrics.getMetrics()) {
out.beginObject(RESPONSE_METRIC);
out.property(RESPONSE_NAME, m.getName());
out.property(RESPONSE_CODE, m.getCode());
out.property(RESPONSE_LABEL, m.getLabel());
out.property(RESPONSE_VALUE, m.getValue());
out.property(RESPONSE_UNIT, m.getUnit());
out.property(RESPONSE_STATE, m.getState().name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private NodeInfo parseNodeState(JSONObject response) {
for (int i = 0; i < nodeMetrics.size(); i++) {
try {
JSONObject metric = (JSONObject) nodeMetrics.get(i);
Metric m = new Metric(metric.getString(ClusterController.RESPONSE_NAME),
Metric m = new Metric(metric.getString(ClusterController.RESPONSE_CODE),metric.getString(ClusterController.RESPONSE_LABEL),
metric.getDoubleValue(ClusterController.RESPONSE_VALUE),
MetricState.valueOf(metric.getString(ClusterController.RESPONSE_STATE)),
metric.getString(ClusterController.RESPONSE_UNIT));
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/sirius/biz/i5/I5MetricProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ public class I5MetricProvider implements MetricProvider {
@Override
public void gather(MetricsCollector collector) {
if (!i5.pools.isEmpty()) {
collector.differentialMetric("i5-use", "i5-uses", "I5 Uses", i5.borrows.getCount(), "/min");
collector.differentialMetric("i5-calls", "i5-calls", "I5 Calls", i5.calls.getCount(), "/min");
collector.metric("i5-call-duration", "I5 Call Duration", i5.callDuration.getAndClear(), "ms");
collector.metric("i5-call-utilization", "I5 Call Utilization", i5.callUtilization.getAndClear(), "ms");
collector.differentialMetric("i5_use", "i5-uses", "I5 Uses", i5.borrows.getCount(), "/min");
collector.differentialMetric("i5_calls", "i5-calls", "I5 Calls", i5.calls.getCount(), "/min");
collector.metric("i5_call_duration",
"i5-call-duration",
"I5 Call Duration",
i5.callDuration.getAndClear(),
"ms");
collector.metric("i5_call_utilization",
"i5-call-utilization",
"I5 Call Utilization",
i5.callUtilization.getAndClear(),
"ms");
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/sirius/biz/locks/Locks.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public void gather(MetricsCollector collector) {
List<LockInfo> locks = getLocks();
LocalDateTime limitForAcquired = LocalDateTime.now().minus(LONG_RUNNING_LOGS_THRESHOLD);

collector.metric("locks-count", "Active Locks", locks.size(), null);
collector.metric("locks-long-running",
collector.metric("locks_count", "locks-count", "Active Locks", locks.size(), null);
collector.metric("locks_long_running","locks-long-running",
"Long locks",
locks.stream().filter(l -> l.getAcquired().isBefore(limitForAcquired)).count(),
null);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sirius/biz/vfs/SystemRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private VirtualFile createStatsFile(VirtualFile parent) {
return new VirtualFile(parent, "stats").withInputStreamSupplier(() -> {
StringBuilder sb = new StringBuilder();
for (Metric metric : metrics.getMetrics()) {
sb.append(metric.getName());
sb.append(metric.getCode());
sb.append(": ");
sb.append(metric.getValueAsString());
sb.append("\n");
Expand Down

0 comments on commit 18eb8c1

Please sign in to comment.