@Test public void testDeleteObsoleteJRobinFiles() { JRobin.deleteObsoleteJRobinFiles(TEST_APPLICATION); Utils.setProperty(Parameter.OBSOLETE_GRAPHS_DAYS, "1"); JRobin.deleteObsoleteJRobinFiles(TEST_APPLICATION); }
static long deleteObsoleteJRobinFiles(String application) { final Calendar nowMinusThreeMonthsAndADay = Calendar.getInstance(); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -getObsoleteGraphsDays()); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -1); final long timestamp = Util.getTimestamp(nowMinusThreeMonthsAndADay); final int counterRequestIdLength = new CounterRequest("", "").getId().length(); long diskUsage = 0; final Map<String, Long> lastUpdateTimesByPath = new HashMap<String, Long>(); final List<File> rrdFiles = new ArrayList<File>(listRrdFiles(application)); for (final File file : rrdFiles) { if (file.getName().length() > counterRequestIdLength && file.lastModified() < nowMinusThreeMonthsAndADay.getTimeInMillis()) { final long lastUpdateTime = getLastUpdateTime(file); lastUpdateTimesByPath.put(file.getPath(), lastUpdateTime); final boolean obsolete = lastUpdateTime < timestamp; boolean deleted = false; if (obsolete) { deleted = file.delete(); } if (!deleted) { diskUsage += file.length(); } } else { diskUsage += file.length(); } } final long maxRrdDiskUsage = getMaxRrdDiskUsageMb() * 1024L * 1024L; if (diskUsage > maxRrdDiskUsage) { for (final File file : rrdFiles) { if (lastUpdateTimesByPath.get(file.getPath()) == null) { lastUpdateTimesByPath.put(file.getPath(), getLastUpdateTime(file)); } } final Comparator<File> comparatorByLastUpdateTime = new Comparator<File>() { @Override public int compare(File o1, File o2) { return lastUpdateTimesByPath.get(o1.getPath()) .compareTo(lastUpdateTimesByPath.get(o2.getPath())); } }; Collections.sort(rrdFiles, comparatorByLastUpdateTime); for (final File file : rrdFiles) { if (diskUsage < maxRrdDiskUsage) { break; } if (file.getName().length() > counterRequestIdLength) { final long length = file.length(); if (file.delete()) { diskUsage -= length; } } } } return diskUsage; }
JRobin { static long deleteObsoleteJRobinFiles(String application) { final Calendar nowMinusThreeMonthsAndADay = Calendar.getInstance(); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -getObsoleteGraphsDays()); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -1); final long timestamp = Util.getTimestamp(nowMinusThreeMonthsAndADay); final int counterRequestIdLength = new CounterRequest("", "").getId().length(); long diskUsage = 0; final Map<String, Long> lastUpdateTimesByPath = new HashMap<String, Long>(); final List<File> rrdFiles = new ArrayList<File>(listRrdFiles(application)); for (final File file : rrdFiles) { if (file.getName().length() > counterRequestIdLength && file.lastModified() < nowMinusThreeMonthsAndADay.getTimeInMillis()) { final long lastUpdateTime = getLastUpdateTime(file); lastUpdateTimesByPath.put(file.getPath(), lastUpdateTime); final boolean obsolete = lastUpdateTime < timestamp; boolean deleted = false; if (obsolete) { deleted = file.delete(); } if (!deleted) { diskUsage += file.length(); } } else { diskUsage += file.length(); } } final long maxRrdDiskUsage = getMaxRrdDiskUsageMb() * 1024L * 1024L; if (diskUsage > maxRrdDiskUsage) { for (final File file : rrdFiles) { if (lastUpdateTimesByPath.get(file.getPath()) == null) { lastUpdateTimesByPath.put(file.getPath(), getLastUpdateTime(file)); } } final Comparator<File> comparatorByLastUpdateTime = new Comparator<File>() { @Override public int compare(File o1, File o2) { return lastUpdateTimesByPath.get(o1.getPath()) .compareTo(lastUpdateTimesByPath.get(o2.getPath())); } }; Collections.sort(rrdFiles, comparatorByLastUpdateTime); for (final File file : rrdFiles) { if (diskUsage < maxRrdDiskUsage) { break; } if (file.getName().length() > counterRequestIdLength) { final long length = file.length(); if (file.delete()) { diskUsage -= length; } } } } return diskUsage; } }
JRobin { static long deleteObsoleteJRobinFiles(String application) { final Calendar nowMinusThreeMonthsAndADay = Calendar.getInstance(); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -getObsoleteGraphsDays()); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -1); final long timestamp = Util.getTimestamp(nowMinusThreeMonthsAndADay); final int counterRequestIdLength = new CounterRequest("", "").getId().length(); long diskUsage = 0; final Map<String, Long> lastUpdateTimesByPath = new HashMap<String, Long>(); final List<File> rrdFiles = new ArrayList<File>(listRrdFiles(application)); for (final File file : rrdFiles) { if (file.getName().length() > counterRequestIdLength && file.lastModified() < nowMinusThreeMonthsAndADay.getTimeInMillis()) { final long lastUpdateTime = getLastUpdateTime(file); lastUpdateTimesByPath.put(file.getPath(), lastUpdateTime); final boolean obsolete = lastUpdateTime < timestamp; boolean deleted = false; if (obsolete) { deleted = file.delete(); } if (!deleted) { diskUsage += file.length(); } } else { diskUsage += file.length(); } } final long maxRrdDiskUsage = getMaxRrdDiskUsageMb() * 1024L * 1024L; if (diskUsage > maxRrdDiskUsage) { for (final File file : rrdFiles) { if (lastUpdateTimesByPath.get(file.getPath()) == null) { lastUpdateTimesByPath.put(file.getPath(), getLastUpdateTime(file)); } } final Comparator<File> comparatorByLastUpdateTime = new Comparator<File>() { @Override public int compare(File o1, File o2) { return lastUpdateTimesByPath.get(o1.getPath()) .compareTo(lastUpdateTimesByPath.get(o2.getPath())); } }; Collections.sort(rrdFiles, comparatorByLastUpdateTime); for (final File file : rrdFiles) { if (diskUsage < maxRrdDiskUsage) { break; } if (file.getName().length() > counterRequestIdLength) { final long length = file.length(); if (file.delete()) { diskUsage -= length; } } } } return diskUsage; } private  JRobin(String application, String name, File rrdFile, int step, String requestName); }
JRobin { static long deleteObsoleteJRobinFiles(String application) { final Calendar nowMinusThreeMonthsAndADay = Calendar.getInstance(); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -getObsoleteGraphsDays()); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -1); final long timestamp = Util.getTimestamp(nowMinusThreeMonthsAndADay); final int counterRequestIdLength = new CounterRequest("", "").getId().length(); long diskUsage = 0; final Map<String, Long> lastUpdateTimesByPath = new HashMap<String, Long>(); final List<File> rrdFiles = new ArrayList<File>(listRrdFiles(application)); for (final File file : rrdFiles) { if (file.getName().length() > counterRequestIdLength && file.lastModified() < nowMinusThreeMonthsAndADay.getTimeInMillis()) { final long lastUpdateTime = getLastUpdateTime(file); lastUpdateTimesByPath.put(file.getPath(), lastUpdateTime); final boolean obsolete = lastUpdateTime < timestamp; boolean deleted = false; if (obsolete) { deleted = file.delete(); } if (!deleted) { diskUsage += file.length(); } } else { diskUsage += file.length(); } } final long maxRrdDiskUsage = getMaxRrdDiskUsageMb() * 1024L * 1024L; if (diskUsage > maxRrdDiskUsage) { for (final File file : rrdFiles) { if (lastUpdateTimesByPath.get(file.getPath()) == null) { lastUpdateTimesByPath.put(file.getPath(), getLastUpdateTime(file)); } } final Comparator<File> comparatorByLastUpdateTime = new Comparator<File>() { @Override public int compare(File o1, File o2) { return lastUpdateTimesByPath.get(o1.getPath()) .compareTo(lastUpdateTimesByPath.get(o2.getPath())); } }; Collections.sort(rrdFiles, comparatorByLastUpdateTime); for (final File file : rrdFiles) { if (diskUsage < maxRrdDiskUsage) { break; } if (file.getName().length() > counterRequestIdLength) { final long length = file.length(); if (file.delete()) { diskUsage -= length; } } } } return diskUsage; } private  JRobin(String application, String name, File rrdFile, int step, String requestName); static void stop(); static void initBackendFactory(Timer timer); byte[] graph(Range range, int width, int height); byte[] graph(Range range, int width, int height, boolean maxHidden); double getLastValue(); void dumpXml(OutputStream output, Range range); String dumpTxt(Range range); String getName(); String getLabel(); @Override String toString(); }
JRobin { static long deleteObsoleteJRobinFiles(String application) { final Calendar nowMinusThreeMonthsAndADay = Calendar.getInstance(); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -getObsoleteGraphsDays()); nowMinusThreeMonthsAndADay.add(Calendar.DAY_OF_YEAR, -1); final long timestamp = Util.getTimestamp(nowMinusThreeMonthsAndADay); final int counterRequestIdLength = new CounterRequest("", "").getId().length(); long diskUsage = 0; final Map<String, Long> lastUpdateTimesByPath = new HashMap<String, Long>(); final List<File> rrdFiles = new ArrayList<File>(listRrdFiles(application)); for (final File file : rrdFiles) { if (file.getName().length() > counterRequestIdLength && file.lastModified() < nowMinusThreeMonthsAndADay.getTimeInMillis()) { final long lastUpdateTime = getLastUpdateTime(file); lastUpdateTimesByPath.put(file.getPath(), lastUpdateTime); final boolean obsolete = lastUpdateTime < timestamp; boolean deleted = false; if (obsolete) { deleted = file.delete(); } if (!deleted) { diskUsage += file.length(); } } else { diskUsage += file.length(); } } final long maxRrdDiskUsage = getMaxRrdDiskUsageMb() * 1024L * 1024L; if (diskUsage > maxRrdDiskUsage) { for (final File file : rrdFiles) { if (lastUpdateTimesByPath.get(file.getPath()) == null) { lastUpdateTimesByPath.put(file.getPath(), getLastUpdateTime(file)); } } final Comparator<File> comparatorByLastUpdateTime = new Comparator<File>() { @Override public int compare(File o1, File o2) { return lastUpdateTimesByPath.get(o1.getPath()) .compareTo(lastUpdateTimesByPath.get(o2.getPath())); } }; Collections.sort(rrdFiles, comparatorByLastUpdateTime); for (final File file : rrdFiles) { if (diskUsage < maxRrdDiskUsage) { break; } if (file.getName().length() > counterRequestIdLength) { final long length = file.length(); if (file.delete()) { diskUsage -= length; } } } } return diskUsage; } private  JRobin(String application, String name, File rrdFile, int step, String requestName); static void stop(); static void initBackendFactory(Timer timer); byte[] graph(Range range, int width, int height); byte[] graph(Range range, int width, int height, boolean maxHidden); double getLastValue(); void dumpXml(OutputStream output, Range range); String dumpTxt(Range range); String getName(); String getLabel(); @Override String toString(); static final int SMALL_HEIGHT; }