@@ -0,0 +1,2532 @@
+/*%0A Source https://code.google.com/p/vellum by @evanxsummers%0A%0A       Licensed to the Apache Software Foundation (ASF) under one%0A       or more contributor license agreements. See the NOTICE file%0A       distributed with this work for additional information%0A       regarding copyright ownership. The ASF licenses this file to%0A       you under the Apache License, Version 2.0 (the %22License%22).%0A       You may not use this file except in compliance with the%0A       License. You may obtain a copy of the License at:%0A%0A         http://www.apache.org/licenses/LICENSE-2.0%0A%0A       Unless required by applicable law or agreed to in writing,%0A       software distributed under the License is distributed on an%0A       %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A       KIND, either express or implied.  See the License for the%0A       specific language governing permissions and limitations%0A       under the License.  %0A */%0Apackage vellum.system;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.File;%0Aimport java.io.FileReader;%0Aimport java.io.IOException;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A/**%0A *%0A * @author evanx%0A */%0Apublic final class LoadAvgReader %7B%0A%0A   static Logger logger = LoggerFactory.getLogger(LoadAvgReader.class);%0A%0A   long lastTimestamp ;%0A   long period;%0A   double cachedLoadAvg;%0A   double highThreshold;%0A   double lowThreshold;%0A   static File procFile = new File(%22/proc/loadavg%22);%0A%0A   public LoadAvgReader(long period, double lowThreshold, double highThreshold) throws IOException %7B%0A      this.lowThreshold = lowThreshold;%0A      this.highThreshold = highThreshold;%0A      if (!procFile.exists()) %7B%0A         throw new IOException(%22missing: %22 + procFile.getAbsolutePath());%0A      %7D%0A   %7D%0A%0A   private void readLoadAvg() %7B%0A      try %7B%0A         try (BufferedReader reader = new BufferedReader(new FileReader(procFile))) %7B%0A            cachedLoadAvg = Float.parseFloat(reader.readLine().split(%22%5C%5Cs%22)%5B0%5D);%0A         %7D%0A      %7D catch (IOException e) %7B%0A         logger.warn(%22read load failed%22, e);%0A      %7D%0A   %7D%0A%0A   public double getLoadAvg() %7B%0A      long timestamp = System.currentTimeMillis();%0A      if (lastTimestamp == 0 %7C%7C lastTimestamp + period %3E timestamp) %7B%0A         lastTimestamp = timestamp;%0A         readLoadAvg();%0A      %7D%0A      return cachedLoadAvg;%0A   %7D%0A%0A   public boolean isHighLoad() %7B%0A      return getLoadAvg() %3E highThreshold;%0A   %7D%0A%0A   public boolean isLowLoad() %7B%0A      return getLoadAvg() %3C lowThreshold;%0A   %7D%0A%0A   public boolean isMediumLoad() %7B%0A      return !isHighLoad() && !isLowLoad();%0A   %7D%0A%7D%0A

load avg reader