-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3446 from mapfish/metrics-requests
Add new metrics
- Loading branch information
Showing
21 changed files
with
391 additions
and
135 deletions.
There are no files selected for viewing
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
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
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
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
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
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
49 changes: 49 additions & 0 deletions
49
core/src/main/java/org/mapfish/print/metrics/UnhealthyCountersHealthCheck.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,49 @@ | ||
package org.mapfish.print.metrics; | ||
|
||
import com.codahale.metrics.Counter; | ||
import com.codahale.metrics.MetricRegistry; | ||
import com.codahale.metrics.health.HealthCheck; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class UnhealthyCountersHealthCheck extends HealthCheck { | ||
@Autowired private MetricRegistry metricRegistry; | ||
|
||
private final Set<String> unhealthyCounters = new HashSet<>(); | ||
|
||
/** | ||
* When a Result is returned it can be healthy or unhealthy. In both cases it is associated to a | ||
* Http 200 status. When an exception is thrown it means the server is no longer working at all, | ||
* it is associated to a Http 500 status. | ||
*/ | ||
@Override | ||
protected HealthCheck.Result check() throws Exception { | ||
StringBuilder messageBuilder = new StringBuilder(); | ||
boolean first = true; | ||
for (String unhealthyCounter : this.unhealthyCounters) { | ||
if (metricRegistry.getNames().contains(unhealthyCounter)) { | ||
Counter counter = metricRegistry.counter(unhealthyCounter); | ||
if (counter.getCount() != 0) { | ||
if (first) { | ||
first = false; | ||
} else { | ||
messageBuilder.append("\n"); | ||
} | ||
messageBuilder.append(unhealthyCounter); | ||
messageBuilder.append(" = "); | ||
messageBuilder.append(counter.getCount()); | ||
} | ||
} | ||
} | ||
if (first) { | ||
return Result.healthy("No unhealthy counter found."); | ||
} | ||
return Result.unhealthy(messageBuilder.toString()); | ||
} | ||
|
||
/** To record a counter which might make the server unhealthy if its count is not zero. */ | ||
public void recordUnhealthyCounter(final String counterName) { | ||
unhealthyCounters.add(counterName); | ||
} | ||
} |
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
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
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
Oops, something went wrong.