001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.web.health; 017 018import com.codahale.metrics.Gauge; 019import com.codahale.metrics.health.HealthCheck; 020 021/** 022 * A health check that checks whether the given {@link Gauge} (which should represent percentage usage of memory) 023 * returns a value that is below the supplied unhealthy threshold. 024 * 025 * @author Eric Westfall 026 */ 027public class MemoryUsageHealthCheck extends HealthCheck { 028 029 private final Gauge<Double> gauge; 030 private final double unhealthyThreshold; 031 032 public MemoryUsageHealthCheck(Gauge<Double> gauge, double unhealthyThreshold) { 033 this.gauge = gauge; 034 this.unhealthyThreshold = unhealthyThreshold; 035 } 036 037 @Override 038 protected Result check() throws Exception { 039 Double value = gauge.getValue(); 040 if (value >= unhealthyThreshold) { 041 return Result.unhealthy("Memory usage ratio of " + value + " was greater than or equal to threshold of " + unhealthyThreshold); 042 } 043 return Result.healthy(); 044 } 045}