2021-02-11 02:36:03 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
|
|
|
|
*
|
|
|
|
* This file is part of StatoolInfos, simple service statistics tool.
|
|
|
|
*
|
|
|
|
* StatoolInfos is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* StatoolInfos is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-02-19 02:16:56 +01:00
|
|
|
package fr.devinsy.statoolinfos.metrics.http;
|
2021-02-11 02:36:03 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2021-02-19 02:16:56 +01:00
|
|
|
import fr.devinsy.statoolinfos.util.LineIterator;
|
|
|
|
|
2021-02-11 02:36:03 +01:00
|
|
|
/**
|
|
|
|
* The Class HttpLogIterator.
|
|
|
|
*/
|
|
|
|
public class HttpLogIterator
|
|
|
|
{
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(HttpLogIterator.class);
|
|
|
|
|
|
|
|
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
|
|
|
|
|
|
|
|
private long errorCount;
|
|
|
|
private LineIterator iterator;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new http log iterator.
|
|
|
|
*
|
|
|
|
* @param source
|
|
|
|
* the source
|
|
|
|
* @throws IOException
|
|
|
|
* Signals that an I/O exception has occurred.
|
|
|
|
*/
|
|
|
|
public HttpLogIterator(final File source) throws IOException
|
|
|
|
{
|
|
|
|
this.errorCount = 0;
|
|
|
|
this.iterator = new LineIterator(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close.
|
|
|
|
*/
|
|
|
|
public void close()
|
|
|
|
{
|
|
|
|
this.iterator.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the error count.
|
|
|
|
*
|
|
|
|
* @return the error count
|
|
|
|
*/
|
|
|
|
public long getErrorCount()
|
|
|
|
{
|
|
|
|
return this.errorCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks for next.
|
|
|
|
*
|
|
|
|
* @return true, if successful
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
|
|
|
public boolean hasNext() throws IOException
|
|
|
|
{
|
|
|
|
boolean result;
|
|
|
|
|
|
|
|
result = this.iterator.hasNext();
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Next.
|
|
|
|
*
|
|
|
|
* @return the http log
|
|
|
|
* @throws IOException
|
|
|
|
*/
|
|
|
|
public HttpLog next() throws IOException
|
|
|
|
{
|
|
|
|
HttpLog result;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
String line = this.iterator.next();
|
2021-02-18 05:33:27 +01:00
|
|
|
result = HttpAccessLogAnalyzer.parseNginxCombinedLog(line);
|
2021-02-11 02:36:03 +01:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
exception.printStackTrace();
|
|
|
|
this.errorCount += 1;
|
|
|
|
if (this.iterator.hasNext())
|
|
|
|
{
|
|
|
|
result = next();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|