Clean metrics.httpaccess package.

This commit is contained in:
Christian P. MOMON 2024-07-18 19:24:02 +02:00
parent 70f6c9fb02
commit f1074afe95
3 changed files with 66 additions and 156 deletions

View file

@ -1,119 +0,0 @@
/*
* Copyright (C) 2021-2023 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/>.
*/
package fr.devinsy.statoolinfos.metrics.http;
import java.io.File;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.util.LineIterator;
/**
* The Class HttpLogIterator.
*/
public class HttpLogIterator
{
private static Logger logger = LoggerFactory.getLogger(HttpLogIterator.class);
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 HttpAccessLog next() throws IOException
{
HttpAccessLog result;
try
{
String line = this.iterator.next();
result = HttpAccessLogParser.parseLog(line, HttpAccessLogParser.COMBINED_PATTERN, HttpAccessLogParser.DATETIME_FORMATTER);
}
catch (Exception exception)
{
exception.printStackTrace();
this.errorCount += 1;
if (this.iterator.hasNext())
{
result = next();
}
else
{
result = null;
}
}
//
return result;
}
}

View file

@ -1,37 +0,0 @@
/*
* 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/>.
*/
package fr.devinsy.statoolinfos.metrics.http;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class NGinxLogAnalyzer.
*/
public class NGinxLogAnalyzer
{
private static Logger logger = LoggerFactory.getLogger(NGinxLogAnalyzer.class);
/**
* Instantiates a new n ginx log analyzer.
*/
private NGinxLogAnalyzer()
{
}
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (C) 2022-2024 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/>.
*/
package fr.devinsy.statoolinfos.util;
import java.io.File;
import java.util.Iterator;
/**
* The Class FilesLines.
*/
public class FilesLines implements Iterable<String>
{
private Files source;
/**
* Instantiates a new file lines.
*
* @param source
* the source
*/
public FilesLines(final File source)
{
this(new Files(source));
}
/**
* Instantiates a new files lines.
*
* @param source
* the source
*/
public FilesLines(final Files source)
{
this.source = source;
}
/* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/
@Override
public Iterator<String> iterator()
{
Iterator<String> result;
result = new FilesLineIterator(this.source);
//
return result;
}
}