Improved probe features.
This commit is contained in:
parent
614c064a24
commit
a9e817f653
4 changed files with 76 additions and 96 deletions
|
@ -22,6 +22,7 @@ import java.io.File;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -109,7 +110,8 @@ public final class StatoolInfosCLI
|
||||||
message.appendln(" statoolinfos clear <configurationfile> remove property files from conf");
|
message.appendln(" statoolinfos clear <configurationfile> remove property files from conf");
|
||||||
message.appendln(" statoolinfos crawl <configurationfile> crawl all file from conf and input");
|
message.appendln(" statoolinfos crawl <configurationfile> crawl all file from conf and input");
|
||||||
message.appendln(" statoolinfos htmlize <configurationfile> generate web pages from conf");
|
message.appendln(" statoolinfos htmlize <configurationfile> generate web pages from conf");
|
||||||
message.appendln(" statoolinfos probe [<directory>|<configurationfile>] generate metrics files from conf");
|
message.appendln(" statoolinfos probe OPTION [<directory>|<configurationfile>] generate metrics files from conf");
|
||||||
|
message.appendln(" OPTION = [-full|-today|-previousday|-NN] with NN a day count");
|
||||||
message.appendln(" statoolinfos uptime <configurationfile> update uptime journal");
|
message.appendln(" statoolinfos uptime <configurationfile> update uptime journal");
|
||||||
message.appendln();
|
message.appendln();
|
||||||
message.appendln(" statoolinfos format <fileordirectory> format property files in tiny way");
|
message.appendln(" statoolinfos format <fileordirectory> format property files in tiny way");
|
||||||
|
@ -383,32 +385,44 @@ public final class StatoolInfosCLI
|
||||||
|
|
||||||
StatoolInfos.listVisitors(source, filter);
|
StatoolInfos.listVisitors(source, filter);
|
||||||
}
|
}
|
||||||
else if (isMatching(args, "probe", "\\s*.+\\.conf\\s*"))
|
else if (isMatching(args, "probe", "\\S*(-full|-today|-previousday|-\\d+)\\s*", "\\s*.+\\s*"))
|
||||||
{
|
{
|
||||||
File configurationFile = new File(StringUtils.trim(args[1]));
|
File configurationFile = new File(StringUtils.trim(args[2]));
|
||||||
|
|
||||||
|
String filter = StringUtils.trim(args[1]);
|
||||||
|
int dayCountFilter;
|
||||||
|
if (filter.equals("-full"))
|
||||||
|
{
|
||||||
|
dayCountFilter = -1;
|
||||||
|
}
|
||||||
|
else if (filter.equals("-today"))
|
||||||
|
{
|
||||||
|
dayCountFilter = 0;
|
||||||
|
}
|
||||||
|
else if (filter.equals("-previousday"))
|
||||||
|
{
|
||||||
|
dayCountFilter = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dayCountFilter = -1 * NumberUtils.toInt(filter);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
|
||||||
StatoolInfos.probe(configurationFile);
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (isMatching(args, "probe", "\\s*.+/\\s*"))
|
|
||||||
{
|
|
||||||
File configurationFile = new File(StringUtils.trim(args[1]));
|
|
||||||
|
|
||||||
if (configurationFile.isDirectory())
|
|
||||||
{
|
{
|
||||||
Files inputs = FilesUtils.searchEndingWith(configurationFile, ".conf");
|
Files inputs = FilesUtils.searchEndingWith(configurationFile, ".conf");
|
||||||
|
if (inputs.isEmpty())
|
||||||
|
{
|
||||||
|
System.out.println("No configuration file found.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
for (File input : inputs)
|
for (File input : inputs)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
StatoolInfos.probe(input);
|
System.out.println("Probing [" + input + "] with day count filter " + dayCountFilter);
|
||||||
|
StatoolInfos.probe(input, dayCountFilter);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
|
@ -417,9 +431,11 @@ public final class StatoolInfosCLI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
System.out.println("Parameter is not a directory.");
|
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
||||||
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isMatching(args, "stat", "ip", "\\s*\\S+\\s*"))
|
else if (isMatching(args, "stat", "ip", "\\s*\\S+\\s*"))
|
||||||
|
|
|
@ -376,30 +376,6 @@ public class Configuration extends PathPropertyList
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the probe mode.
|
|
||||||
*
|
|
||||||
* @return the probe mode
|
|
||||||
*/
|
|
||||||
public ProbePeriod getProbeMode()
|
|
||||||
{
|
|
||||||
ProbePeriod result;
|
|
||||||
|
|
||||||
String value = get("conf.probe.mode");
|
|
||||||
|
|
||||||
if (StringUtils.isBlank(value))
|
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = ProbePeriod.valueOf(StringUtils.upperCase(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the probe target.
|
* Gets the probe target.
|
||||||
*
|
*
|
||||||
|
|
|
@ -325,9 +325,9 @@ public class StatoolInfos
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* Signals that an I/O exception has occurred.
|
* Signals that an I/O exception has occurred.
|
||||||
*/
|
*/
|
||||||
public static void probe(final File configurationFile) throws StatoolInfosException, IOException
|
public static void probe(final File configurationFile, final int dayCountFilter) throws StatoolInfosException, IOException
|
||||||
{
|
{
|
||||||
Prober.probe(configurationFile);
|
Prober.probe(configurationFile, dayCountFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,7 +35,6 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import fr.devinsy.statoolinfos.core.Configuration;
|
import fr.devinsy.statoolinfos.core.Configuration;
|
||||||
import fr.devinsy.statoolinfos.core.Factory;
|
import fr.devinsy.statoolinfos.core.Factory;
|
||||||
import fr.devinsy.statoolinfos.core.ProbePeriod;
|
|
||||||
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
||||||
import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
|
import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
|
||||||
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer;
|
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer;
|
||||||
|
@ -86,18 +85,21 @@ public class Prober
|
||||||
*
|
*
|
||||||
* @param configuration
|
* @param configuration
|
||||||
* the configuration
|
* the configuration
|
||||||
|
* @param dayCountFilter
|
||||||
|
* the day count filter, 0=today, 1=previous day, 7=previous
|
||||||
|
* week…
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* Signals that an I/O exception has occurred.
|
* Signals that an I/O exception has occurred.
|
||||||
* @throws StatoolInfosException
|
* @throws StatoolInfosException
|
||||||
* the statool infos exception
|
* the statool infos exception
|
||||||
*/
|
*/
|
||||||
public static void probe(final Configuration configuration) throws IOException, StatoolInfosException
|
public static void probe(final Configuration configuration, final int dayCountFilter) throws IOException, StatoolInfosException
|
||||||
{
|
{
|
||||||
StringList types = configuration.getProbeTypes();
|
StringList types = configuration.getProbeTypes();
|
||||||
|
|
||||||
System.out.println("Targets=" + types.toStringWithBrackets());
|
System.out.println("Targets=" + types.toStringWithBrackets());
|
||||||
|
|
||||||
if (configuration.getProbeMode() != null)
|
if (!types.isEmpty())
|
||||||
{
|
{
|
||||||
PathCounters counters = new PathCounters();
|
PathCounters counters = new PathCounters();
|
||||||
|
|
||||||
|
@ -148,21 +150,10 @@ public class Prober
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter.
|
// Filter.
|
||||||
logger.info("== Filtering");
|
logger.info("== Filtering with {}", dayCountFilter);
|
||||||
if (configuration.getProbeMode() == ProbePeriod.TODAY)
|
if (dayCountFilter >= 0)
|
||||||
{
|
{
|
||||||
logger.info("=== TODAY");
|
counters = counters.searchByPeriod(LocalDate.now().minusDays(dayCountFilter), LocalDate.now());
|
||||||
counters = counters.searchByPeriod(LocalDate.now(), LocalDate.now());
|
|
||||||
}
|
|
||||||
else if (configuration.getProbeMode() == ProbePeriod.PREVIOUS_DAY)
|
|
||||||
{
|
|
||||||
logger.info("=== PREVIOUS_DAY");
|
|
||||||
counters = counters.searchByPeriod(LocalDate.now().minusDays(1), LocalDate.now());
|
|
||||||
}
|
|
||||||
else if (configuration.getProbeMode() == ProbePeriod.PREVIOUS_DAYS_7)
|
|
||||||
{
|
|
||||||
logger.info("=== PREVIOUS_WEEK");
|
|
||||||
counters = counters.searchByPeriod(LocalDate.now().minusDays(7), LocalDate.now());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -176,9 +167,6 @@ public class Prober
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (target.exists())
|
if (target.exists())
|
||||||
{
|
|
||||||
logger.info("ModeProbe=" + configuration.getProbeMode());
|
|
||||||
if (configuration.getProbeMode() != ProbePeriod.FULL)
|
|
||||||
{
|
{
|
||||||
// Load.
|
// Load.
|
||||||
logger.info("== Reading previous target file.");
|
logger.info("== Reading previous target file.");
|
||||||
|
@ -202,7 +190,6 @@ public class Prober
|
||||||
|
|
||||||
//
|
//
|
||||||
counters = previousCounters;
|
counters = previousCounters;
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
logger.info("== Backing previous target file.");
|
logger.info("== Backing previous target file.");
|
||||||
|
@ -216,6 +203,7 @@ public class Prober
|
||||||
logger.info("== Writing.");
|
logger.info("== Writing.");
|
||||||
logger.info("size={}", counters.size());
|
logger.info("size={}", counters.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -226,13 +214,13 @@ public class Prober
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws StatoolInfosException
|
* @throws StatoolInfosException
|
||||||
*/
|
*/
|
||||||
public static void probe(final File configurationFile) throws StatoolInfosException, IOException
|
public static void probe(final File configurationFile, final int dayCountFilter) throws StatoolInfosException, IOException
|
||||||
{
|
{
|
||||||
logger.info("Probe {}", configurationFile.getAbsolutePath());
|
logger.info("Probe {}", configurationFile.getAbsolutePath());
|
||||||
|
|
||||||
Configuration configuration = Factory.loadConfiguration(configurationFile);
|
Configuration configuration = Factory.loadConfiguration(configurationFile);
|
||||||
|
|
||||||
probe(configuration);
|
probe(configuration, dayCountFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue