Add read from start opton
This commit is contained in:
@@ -26,6 +26,7 @@ public class Cli {
|
|||||||
public static Option fileParam = new Option( "paramfile", true , "Input a param file" );
|
public static Option fileParam = new Option( "paramfile", true , "Input a param file" );
|
||||||
public static Option debugOption = new Option( "debug", "Active debug output message" );
|
public static Option debugOption = new Option( "debug", "Active debug output message" );
|
||||||
public static Option infoOption = new Option( "info", "Active info output message" );
|
public static Option infoOption = new Option( "info", "Active info output message" );
|
||||||
|
public static Option once = new Option( "once", "Read the file once time" );
|
||||||
private static long lastModifiedTime = 0L;
|
private static long lastModifiedTime = 0L;
|
||||||
public Cli() {
|
public Cli() {
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
@@ -52,6 +53,7 @@ public class Cli {
|
|||||||
|
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
boolean readFromStart = false;
|
boolean readFromStart = false;
|
||||||
|
boolean onceTime = false;
|
||||||
CommandLineParser parser = new DefaultParser();
|
CommandLineParser parser = new DefaultParser();
|
||||||
CommandLine cmd = null;
|
CommandLine cmd = null;
|
||||||
try {
|
try {
|
||||||
@@ -91,15 +93,20 @@ public class Cli {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(cmd.hasOption("once")) {
|
||||||
|
onceTime = true;
|
||||||
|
}
|
||||||
|
|
||||||
if(cmd.hasOption("paramfile")) {
|
if(cmd.hasOption("paramfile")) {
|
||||||
String fileParamName = cmd.getOptionValue("paramfile");
|
String fileParamName = cmd.getOptionValue("paramfile");
|
||||||
File param = new File(fileParamName);
|
File param = new File(fileParamName);
|
||||||
ParserEngine engine = new ParserEngine(patternPath);
|
ParserEngine engine = new ParserEngine(patternPath);
|
||||||
Log log = Log.getLogger(Cli.class.getName());
|
Log log = Log.getLogger(Cli.class.getName());
|
||||||
try {
|
try {
|
||||||
startParserFromFile(param, engine );
|
startParserFromFile(param, engine , onceTime);
|
||||||
lastModifiedTime = param.lastModified();
|
lastModifiedTime = param.lastModified();
|
||||||
log.info("All parsers started");
|
log.info("All parsers started");
|
||||||
|
// Check for reload the param file
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
@@ -108,7 +115,7 @@ public class Cli {
|
|||||||
if ( param.lastModified() != lastModifiedTime )
|
if ( param.lastModified() != lastModifiedTime )
|
||||||
{
|
{
|
||||||
engine.stopAllParser();
|
engine.stopAllParser();
|
||||||
startParserFromFile(param, engine );
|
startParserFromFile(param, engine , onceTime);
|
||||||
lastModifiedTime = param.lastModified();
|
lastModifiedTime = param.lastModified();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,7 +161,7 @@ public class Cli {
|
|||||||
String[] filesName = cmd.getOptionValues("logfile");
|
String[] filesName = cmd.getOptionValues("logfile");
|
||||||
for (int i = 0; i < filesName.length ; i++) {
|
for (int i = 0; i < filesName.length ; i++) {
|
||||||
File f = new File (filesName[i]);
|
File f = new File (filesName[i]);
|
||||||
engine.addNewParser(f, regexName[i], applicationName, readFromStart);
|
engine.addNewParser(f, regexName[i], applicationName, readFromStart, onceTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,7 +169,7 @@ public class Cli {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void startParserFromFile(File file, ParserEngine engine) throws FileNotFoundException {
|
static void startParserFromFile(File file, ParserEngine engine, boolean onceTime) throws FileNotFoundException {
|
||||||
|
|
||||||
Scanner scanner = new Scanner(file);
|
Scanner scanner = new Scanner(file);
|
||||||
|
|
||||||
@@ -175,10 +182,14 @@ public class Cli {
|
|||||||
String applicationName = arguments[0].toLowerCase();
|
String applicationName = arguments[0].toLowerCase();
|
||||||
Paths paths = new Paths("/", arguments[1]);
|
Paths paths = new Paths("/", arguments[1]);
|
||||||
String regexName = arguments[2];
|
String regexName = arguments[2];
|
||||||
if (arguments[3] != null)
|
if (arguments.length == 4) {
|
||||||
readFromStart = true;
|
if ( arguments[3].equalsIgnoreCase("true") ){
|
||||||
|
readFromStart = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (File f : paths.getFiles()) {
|
for (File f : paths.getFiles()) {
|
||||||
engine.addNewParser(f, regexName, applicationName, readFromStart);
|
engine.addNewParser(f, regexName, applicationName, readFromStart, onceTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public class ParserEngine implements Runnable{
|
|||||||
final private String database = "qualif";
|
final private String database = "qualif";
|
||||||
final private String urlInfluxdb = "http://diqmqs.airfrance.fr/influxdb_query/write?rp=one_week&db=" + database;
|
final private String urlInfluxdb = "http://diqmqs.airfrance.fr/influxdb_query/write?rp=one_week&db=" + database;
|
||||||
final long delay = 200;
|
final long delay = 200;
|
||||||
|
private boolean onceTime = false;
|
||||||
private ArrayList<Thread> threadsParser = null;
|
private ArrayList<Thread> threadsParser = null;
|
||||||
static BlockingDeque<String> queue = new LinkedBlockingDeque<String>(2000);
|
static BlockingDeque<String> queue = new LinkedBlockingDeque<String>(2000);
|
||||||
private String patternPath = "";
|
private String patternPath = "";
|
||||||
@@ -50,7 +51,7 @@ public class ParserEngine implements Runnable{
|
|||||||
log.info("Schedule sender is set to " + 1 + " secs" );
|
log.info("Schedule sender is set to " + 1 + " secs" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void addNewParser(File f , String regexName, String application , boolean readFromStart) {
|
void addNewParser(File f , String regexName, String application , boolean readFromStart, boolean onceTime) {
|
||||||
TailerListener listener = new Parser(application, regexName, this);
|
TailerListener listener = new Parser(application, regexName, this);
|
||||||
Tailer tailer = new Tailer(f, listener, delay, !readFromStart, true, 8192);
|
Tailer tailer = new Tailer(f, listener, delay, !readFromStart, true, 8192);
|
||||||
Thread thread = new Thread(tailer);
|
Thread thread = new Thread(tailer);
|
||||||
@@ -58,6 +59,7 @@ public class ParserEngine implements Runnable{
|
|||||||
thread.setName("Parser - " + threadsParser.size() );
|
thread.setName("Parser - " + threadsParser.size() );
|
||||||
thread.start();
|
thread.start();
|
||||||
threadsParser.add(thread);
|
threadsParser.add(thread);
|
||||||
|
this.onceTime = onceTime;
|
||||||
log.info("Thread Parser - " + threadsParser.size() + " started on file : " + f.getName());
|
log.info("Thread Parser - " + threadsParser.size() + " started on file : " + f.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +82,14 @@ public class ParserEngine implements Runnable{
|
|||||||
postData.append( s + "\n" );
|
postData.append( s + "\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (onceTime)
|
||||||
|
{
|
||||||
|
stopAllParser();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (postData.length() > 0) {
|
if (postData.length() > 0) {
|
||||||
if (sendMetricToInfluxdb(postData.toString()))
|
if (sendMetricToInfluxdb(postData.toString()))
|
||||||
|
|||||||
Reference in New Issue
Block a user