@Configurable public class IfFlapping extends AbstractHealthCheckPredicate
Flapping occurs when a health check changes state too frequently. This can serve as convenient filter for nuisance actions, as well as a useful indicator of real issues that would otherwise be hard to detect.
IfFlapping scans recent historical data for state changes to calculate a weighted percent change. By default, recent state changes are weighted more than older changes. This predicate matches if the overall weighted percent change exceeds a threshold.
Note: Use <health:Not> predicate for filtering.
<health:HttpStatusHealthCheck ee:Named="httpStatusCheck">
<url>http://localhost:8080/test-ping.jsp</url>
</health:HttpStatusHealthCheck>
<health:Restart>
<health:IfHealthCritical healthCheck="${httpStatusCheck}"/>
<health:Not>
<health:IfFlapping healthCheck="${httpStatusHealthCheck}"/>
</health:Not>
</health:Restart>
Constructor and Description |
---|
IfFlapping() |
IfFlapping(HealthCheck healthCheck) |
Modifier and Type | Method and Description |
---|---|
static double |
calculatePercentChange(StatServiceValue[] data,
double lowWeight,
double highWeight) |
double |
getHighWeight()
Returns the high weight (most recent)
|
double |
getLowWeight()
Returns the low weight (least recent)
|
int |
getSampleSize()
Returns the minimum sample size before attempting to detect flapping.
|
double |
getThreshold()
Returns the weighted percent change that must be exceeded to detect
flapping, as a floating point number between 0 and 1.
|
void |
init() |
protected boolean |
isFlapping(HealthService healthService,
HealthCheck healthCheck,
long sampleId) |
boolean |
isMatch(HealthEvent healthEvent)
Match if calculated weighted percent change exceeds the threshold
|
void |
setHighWeight(double highWeight)
Newer state changes can be weighted more than older changes.
|
void |
setLowWeight(double lowWeight)
Older state changes can be weighted less than more recent changes.
|
void |
setSampleSize(int sampleSize)
The minimum number of samples required before attempting to detect
flapping.
|
void |
setThreshold(double threshold)
Flapping is detected when the calculated weighted percent change exceeds
this threshold,
|
getHealthCheck, getLastResult, setHealthCheck, toString
public IfFlapping()
public IfFlapping(HealthCheck healthCheck)
@PostConstruct public void init()
public int getSampleSize()
@Configurable public void setSampleSize(int sampleSize)
sampleSize
- minimum number of samples, default 21public double getThreshold()
@Configurable public void setThreshold(double threshold)
threshold
- percent change threshold as a floating point number
between 0 and 1, default 0.5
(approximate 50% of samples, adjusted depending on weight)public double getLowWeight()
@Configurable public void setLowWeight(double lowWeight)
lowWeight
- The starting weight (least recent), default .75public double getHighWeight()
@Configurable public void setHighWeight(double highWeight)
highWeight
- The ending weight, default 1.25public boolean isMatch(HealthEvent healthEvent)
isMatch
in interface HealthPredicate
isMatch
in class AbstractScheduledHealthPredicate
protected boolean isFlapping(HealthService healthService, HealthCheck healthCheck, long sampleId)
public static double calculatePercentChange(StatServiceValue[] data, double lowWeight, double highWeight)