com.caucho.health.predicate
Class IfFlapping

java.lang.Object
  extended by com.caucho.health.predicate.AbstractHealthPredicate
      extended by com.caucho.health.predicate.AbstractScheduledHealthPredicate
          extended by com.caucho.health.predicate.AbstractHealthCheckPredicate
              extended by com.caucho.health.predicate.IfFlapping
All Implemented Interfaces:
HealthPredicate

@Configurable
public class IfFlapping
extends AbstractHealthCheckPredicate

Qualifies an action to match only when the health check status is flapping.

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 Summary
IfFlapping()
           
IfFlapping(HealthCheck healthCheck)
           
 
Method Summary
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,
 
Methods inherited from class com.caucho.health.predicate.AbstractHealthCheckPredicate
getHealthCheck, getLastResult, setHealthCheck, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IfFlapping

public IfFlapping()

IfFlapping

public IfFlapping(HealthCheck healthCheck)
Method Detail

init

@PostConstruct
public void init()

getSampleSize

public int getSampleSize()
Returns the minimum sample size before attempting to detect flapping.


setSampleSize

@Configurable
public void setSampleSize(int sampleSize)
The minimum number of samples required before attempting to detect flapping. Assuming the default health system check period of 5 minutes, a minimum of 1 hour and 45 minutes of data collection is required.

Parameters:
sampleSize - minimum number of samples, default 21

getThreshold

public double getThreshold()
Returns the weighted percent change that must be exceeded to detect flapping, as a floating point number between 0 and 1.


setThreshold

@Configurable
public void setThreshold(double threshold)
Flapping is detected when the calculated weighted percent change exceeds this threshold,

Parameters:
threshold - percent change threshold as a floating point number between 0 and 1, default 0.5 (approximate 50% of samples, adjusted depending on weight)

getLowWeight

public double getLowWeight()
Returns the low weight (least recent)


setLowWeight

@Configurable
public void setLowWeight(double lowWeight)
Older state changes can be weighted less than more recent changes.

Parameters:
lowWeight - The starting weight (least recent), default .75

getHighWeight

public double getHighWeight()
Returns the high weight (most recent)


setHighWeight

@Configurable
public void setHighWeight(double highWeight)
Newer state changes can be weighted more than older changes.

Parameters:
highWeight - The ending weight, default 1.25

isMatch

public boolean isMatch(HealthEvent healthEvent)
Match if calculated weighted percent change exceeds the threshold

Specified by:
isMatch in interface HealthPredicate
Overrides:
isMatch in class AbstractScheduledHealthPredicate

isFlapping

protected boolean isFlapping(HealthService healthService,
                             HealthCheck healthCheck,
                             long sampleId)

calculatePercentChange

public static double calculatePercentChange(StatServiceValue[] data,
                                            double lowWeight,
                                            double highWeight)