Compare commits

..

No commits in common. "65354e89cc8b0787bedb51ab91341b69efbfa0b1" and "62815f6d1e1c6ed17559a955386d61df30b04b58" have entirely different histories.

42 changed files with 224 additions and 1546 deletions

View file

@ -24,9 +24,9 @@
<classpathentry kind="lib" path="lib/jOpenDocument-1.3.jar" sourcepath="lib/jOpenDocument-src-1.3.zip"/> <classpathentry kind="lib" path="lib/jOpenDocument-1.3.jar" sourcepath="lib/jOpenDocument-src-1.3.zip"/>
<classpathentry kind="lib" path="lib/threeten-extra-1.5.0.jar" sourcepath="lib/threeten-extra-1.5.0-sources.jar"/> <classpathentry kind="lib" path="lib/threeten-extra-1.5.0.jar" sourcepath="lib/threeten-extra-1.5.0-sources.jar"/>
<classpathentry kind="lib" path="lib/devinsy-strings-0.11.4.jar" sourcepath="lib/devinsy-strings-0.11.4-sources.zip"/> <classpathentry kind="lib" path="lib/devinsy-strings-0.11.4.jar" sourcepath="lib/devinsy-strings-0.11.4-sources.zip"/>
<classpathentry kind="lib" path="lib/Logs/log4j-api-2.17.0.jar" sourcepath="lib/Logs/log4j-api-2.17.0-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/log4j-core-2.17.0.jar" sourcepath="lib/Logs/log4j-core-2.17.0-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/log4j-slf4j-impl-2.17.0.jar" sourcepath="lib/Logs/log4j-slf4j-impl-2.17.0-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/slf4j-api-1.7.32.jar" sourcepath="lib/Logs/slf4j-api-1.7.32-sources.jar"/> <classpathentry kind="lib" path="lib/Logs/slf4j-api-1.7.32.jar" sourcepath="lib/Logs/slf4j-api-1.7.32-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/log4j-api-2.17.1.jar" sourcepath="lib/Logs/log4j-api-2.17.1-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/log4j-core-2.17.1.jar" sourcepath="lib/Logs/log4j-core-2.17.1-sources.jar"/>
<classpathentry kind="lib" path="lib/Logs/log4j-slf4j-impl-2.17.1.jar" sourcepath="lib/Logs/log4j-slf4j-impl-2.17.1-sources.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project default="main" name="Build-appjar"> <project default="main" name="Build-appjar">
<!--ANT 1.11 is required --> <!--ANT 1.7 is required -->
<property name="buildjar.version" value="1.11" /> <property name="buildjar.version" value="1.8" />
<property file="build.properties" /> <property file="build.properties" />
<property name="build.dir" value="${basedir}/build" /> <property name="build.dir" value="${basedir}/build" />
<property name="build.src" value="${basedir}/src" /> <property name="build.src" value="${basedir}/src" />
@ -11,7 +11,8 @@
<property name="test.classes" value="${build.dir}/test-classes" /> <property name="test.classes" value="${build.dir}/test-classes" />
<property name="debug" value="on" /> <property name="debug" value="on" />
<path id="project.libs"> <path id="project.libs">
<fileset dir="${basedir}/lib" includes="**/*.jar" excludes="*sources* **/*sources* *src* **/*src*" /> <fileset dir="${basedir}/lib" includes="**/*.jar" excludes="*sources* *src*" />
<!--fileset dir="${basedir}/lib/Logs" includes="**.jar" excludes="*sources* *src*" /-->
</path> </path>
<property name="classpath.absolute" value="${toString:project.libs}" /> <property name="classpath.absolute" value="${toString:project.libs}" />
@ -94,18 +95,26 @@
<entry key="product.revision.author" value="${user.name}"/> <entry key="product.revision.author" value="${user.name}"/>
</propertyfile> </propertyfile>
<!-- Build the jar file list. --> <!-- Build the jar file list. -->
<!-- Package jar --> <!-- Package jar -->
<property name="dist.jar" value="${dist.dir}/${product.name}.jar" /> <property name="dist.jar" value="${dist.dir}/${product.name}.jar" />
<jar destfile="${dist.jar}"> <jar destfile="${dist.jar}">
<fileset dir="${build.classes}" /> <restrict>
<zipgroupfileset dir="${basedir}/lib" includes="*.jar **/*.jar" excludes="*sources* **/*sources* *src* **/*src*" /> <name regex=".*/*\.(class|gif|ico|jpg|ngp|png|pom|properties|svg@|xml|xsd)"/>
<archives>
<zips>
<fileset dir="${basedir}/lib" includes="**/*.jar" excludes="*sources* *src*" />
</zips>
</archives>
</restrict>
<manifest> <manifest>
<attribute name="Built-By" value="${user.name} using ant" /> <attribute name="Built-By" value="${user.name} using ant" />
<attribute name="Built-Date" value="${dist.time}" /> <attribute name="Built-Date" value="${dist.time}" />
<attribute name="Main-Class" value = "fr.devinsy.statoolinfos.StatoolInfosLauncher"/> <attribute name="Main-Class" value = "fr.devinsy.statoolinfos.StatoolInfosLauncher"/>
<attribute name="Multi-Release" value = "true"/> </manifest>
</manifest> <fileset dir="${build.classes}" />
<!--zipfileset dir="${basedir}/lib" includes="${toString:project.libs}" /-->
</jar> </jar>
<!-- Package sources --> <!-- Package sources -->

View file

@ -1,21 +1,10 @@
#!/bin/bash #!/bin/bash
# Optional environment settings: # Java check.
# export LOG4J_CONFIGURATION_FILE="toto.properties"
# export LOG4J_LEVEL=ERROR
# https://logging.apache.org/log4j/log4j-2.11.2/manual/configuration.html#System_Properties
# Java check.
javaCheck=`which java` javaCheck=`which java`
if [[ "$javaCheck" =~ ^/.* ]]; then if [[ "$javaCheck" =~ ^/.* ]]; then
#echo "Java requirement............... OK" #echo "Java requirement............... OK"
java -Djava.awt.headless=true -jar "$(dirname "$0")"/statoolinfos.jar $@
# Optional system properties:
# LOGFILE="-Dlog4j2.configurationFile=../../log4j2.properties"
# LOGLEVEL="-Dlog4j2.level=ERROR"
# https://logging.apache.org/log4j/log4j-2.11.2/manual/configuration.html#System_Properties
java -Djava.awt.headless=true $LOGFILE $LOGLEVEL -jar "$(dirname "$0")"/statoolinfos.jar $@
else else
echo "Java requirement............... MISSING" echo "Java requirement............... MISSING"
fi fi

View file

@ -1,3 +0,0 @@
#!/bin/bash
./build.sh -snapshot

View file

@ -20,15 +20,9 @@ package fr.devinsy.statoolinfos;
import java.io.File; import java.io.File;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.config.Configurator; import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder; import org.apache.logging.log4j.core.config.DefaultConfiguration;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -39,6 +33,8 @@ import fr.devinsy.statoolinfos.cli.StatoolInfosCLI;
*/ */
public final class StatoolInfosLauncher public final class StatoolInfosLauncher
{ {
private static Logger logger = LoggerFactory.getLogger(StatoolInfosLauncher.class);
/** /**
* Instantiates a new statool infos launcher. * Instantiates a new statool infos launcher.
*/ */
@ -54,45 +50,18 @@ public final class StatoolInfosLauncher
*/ */
public static void main(final String[] args) public static void main(final String[] args)
{ {
String logFileEnv = System.getenv().get("LOG4J_CONFIGURATION_FILE");
String logFileProperty = System.getProperty("log4j2.configurationFile");
// Configure log. // Configure log.
if ((StringUtils.isBlank(logFileEnv) && (StringUtils.isBlank(logFileProperty)))) File loggerConfig = new File("log4j.properties");
if (loggerConfig.exists())
{ {
File loggerConfig = new File("log4j2.properties"); Configurator.initialize(null, loggerConfig.getAbsolutePath());
if (loggerConfig.exists()) logger.info("Dedicated log configuration done.");
{ logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile());
// Try to initialize logs with a log file. }
Configurator.initialize(null, loggerConfig.getAbsolutePath()); else
Logger logger = LoggerFactory.getLogger(StatoolInfosLauncher.class); {
logger.info("Dedicated log configuration done."); Configurator.initialize(new DefaultConfiguration());
logger.info("Configuration file was found in [{}].", loggerConfig.getAbsoluteFile()); Configurator.setRootLevel(Level.INFO);
}
else
{
// Build a custom default log configuration.
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setStatusLevel(Level.ERROR);
builder.setConfigurationName("CustomDefaultLogger");
AppenderComponentBuilder appenderBuilder = builder.newAppender("Console", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "%m%n"));
RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.INFO);
rootLogger.add(builder.newAppenderRef("Console"));
builder.add(appenderBuilder);
builder.add(rootLogger);
Configurator.reconfigure(builder.build());
Logger logger = LoggerFactory.getLogger(StatoolInfosLauncher.class);
logger.debug("Custom default log configuration done.");
/*
Configurator.initialize(new DefaultConfiguration());
Configurator.setRootLevel(Level.INFO);
Logger logger = LoggerFactory.getLogger(StatoolInfosLauncher.class);
logger.debug("Default log configuration done.");
*/
}
} }
// Run. // Run.

View file

@ -161,7 +161,7 @@ public class CrawlJournalFile
PrintWriter out = null; PrintWriter out = null;
try try
{ {
out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
write(out, source); write(out, source);
} }
finally finally

View file

@ -69,7 +69,7 @@ public class EditoPage
FileUtils.copyDirectory(editoDirectory, htmlizeDirectory); FileUtils.copyDirectory(editoDirectory, htmlizeDirectory);
// Load body edito xhtml file. // Load body edito xhtml file.
edito = FileUtils.readFileToString(editoFile, StandardCharsets.UTF_8); edito = FileUtils.readFileToString(editoFile, "UTF-8");
edito = XidynUtils.extractBodyContent(edito); edito = XidynUtils.extractBodyContent(edito);
} }
else else

View file

@ -25,7 +25,6 @@ import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -58,7 +57,7 @@ public class CSVWriter implements SpreadsheetWriter
public CSVWriter(final File file, final char separator) throws UnsupportedEncodingException, FileNotFoundException public CSVWriter(final File file, final char separator) throws UnsupportedEncodingException, FileNotFoundException
{ {
this.separator = separator; this.separator = separator;
this.out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); this.out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
this.isNewline = true; this.isNewline = true;
} }

View file

@ -482,44 +482,4 @@ public class PathCounters extends HashMap<String, PathCounter>
// //
return result; return result;
} }
/**
* Sets the.
*
* @param value
* the value
* @param path
* the path
* @param timeMarks
* the time marks
*/
public void set(final long value, final String path, final String... timeMarks)
{
for (String timeMark : timeMarks)
{
set(value, path, timeMark);
}
}
/**
* Sets the.
*
* @param value
* the value
* @param path
* the path
* @param timeMark
* the time mark
*/
public void set(final long value, final String path, final String timeMark)
{
PathCounter counter = get(path, timeMark);
if (counter == null)
{
counter = new PathCounter(path, timeMark);
put(counter);
}
counter.setCounter(value);
}
} }

View file

@ -41,12 +41,9 @@ import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer; import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer;
import fr.devinsy.statoolinfos.metrics.http.HttpErrorLogAnalyzer; import fr.devinsy.statoolinfos.metrics.http.HttpErrorLogAnalyzer;
import fr.devinsy.statoolinfos.metrics.minetest.MinetestProber; import fr.devinsy.statoolinfos.metrics.minetest.MinetestProber;
import fr.devinsy.statoolinfos.metrics.mumble.MumbleProber;
import fr.devinsy.statoolinfos.metrics.privatebin.PrivatebinProber;
import fr.devinsy.statoolinfos.properties.PathProperties; import fr.devinsy.statoolinfos.properties.PathProperties;
import fr.devinsy.statoolinfos.properties.PathProperty; import fr.devinsy.statoolinfos.properties.PathProperty;
import fr.devinsy.statoolinfos.properties.PathPropertyUtils; import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
import fr.devinsy.statoolinfos.util.BuildInformation;
import fr.devinsy.strings.StringList; import fr.devinsy.strings.StringList;
import fr.devinsy.strings.StringsUtils; import fr.devinsy.strings.StringsUtils;
@ -57,6 +54,8 @@ public class Prober
{ {
private static Logger logger = LoggerFactory.getLogger(Prober.class); private static Logger logger = LoggerFactory.getLogger(Prober.class);
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
public static final Pattern YEAR_PATTERN = Pattern.compile("^\\d{4}$"); public static final Pattern YEAR_PATTERN = Pattern.compile("^\\d{4}$");
/** /**
@ -156,26 +155,11 @@ public class Prober
if (types.containsAnyIgnoreCase("Mumble")) if (types.containsAnyIgnoreCase("Mumble"))
{ {
logger.info("== Processing Mumble."); logger.info("== Processing Mumble.");
String source = configuration.get("conf.probe.mumble.logs"); String source = configuration.getProbeHttpErrorLogSource();
logger.info("source=[{}]", source); logger.info("source=[{}]", source);
PathCounters data = MumbleProber.probe(source); // PathCounters data = HttpErrorLogAnalyzer.probe(source);
counters.putAll(data); // counters.putAll(data);
}
//
if (types.containsAnyIgnoreCase("PrivateBin"))
{
logger.info("== Processing Privatebin.");
String httpAccessLogs = configuration.getProbeHttpAccessLogSource();
String httpAccessLogRegex = configuration.getProbeHttpAccessLogPattern();
File dataDirectory = configuration.getAsFile("conf.probe.privatebin.data");
logger.info("source=[{}]", httpAccessLogs);
logger.info("pattern=[{}]", httpAccessLogRegex);
logger.info("dataDirectory=[{}]", dataDirectory);
PathCounters data = PrivatebinProber.probe(httpAccessLogs, httpAccessLogRegex, dataDirectory);
counters.putAll(data);
} }
// Filter. // Filter.
@ -366,8 +350,7 @@ public class Prober
metrics.appendln("file.class=metrics"); metrics.appendln("file.class=metrics");
metrics.appendln("file.generator=StatoolInfos"); metrics.appendln("file.generator=StatoolInfos");
metrics.appendln("file.datetime=" + LocalDateTime.now().toString()); metrics.appendln("file.datetime=" + LocalDateTime.now().toString());
metrics.appendln("file.protocol=" + BuildInformation.instance().protocol()); metrics.appendln("file.protocol=StatoolInfos-0.3.0");
metrics.appendln(); metrics.appendln();
metrics.appendln("# [Metrics]"); metrics.appendln("# [Metrics]");

View file

@ -223,6 +223,42 @@ public class TimeMark
return result; return result;
} }
/**
* Month of.
*
* @param date
* the date
* @return the time mark
*/
public static TimeMark monthOf(final LocalDate date)
{
TimeMark result;
String month = date.format(DateTimeFormatter.ofPattern("yyyy-MM", Locale.FRANCE));
result = new TimeMark(month);
//
return result;
}
/**
* Month of.
*
* @param date
* the date
* @return the time mark
*/
public static TimeMark monthOf(final LocalDateTime date)
{
TimeMark result;
String month = date.format(DateTimeFormatter.ofPattern("yyyy-MM", Locale.FRANCE));
result = new TimeMark(month);
//
return result;
}
/** /**
* Month of. * Month of.
* *
@ -241,42 +277,6 @@ public class TimeMark
return result; return result;
} }
/**
* Month of.
*
* @param date
* the date
* @return the time mark
*/
public static TimeMark yearMonthOf(final LocalDate date)
{
TimeMark result;
String month = date.format(DateTimeFormatter.ofPattern("yyyy-MM", Locale.FRANCE));
result = new TimeMark(month);
//
return result;
}
/**
* Month of.
*
* @param date
* the date
* @return the time mark
*/
public static TimeMark yearMonthOf(final LocalDateTime date)
{
TimeMark result;
String month = date.format(DateTimeFormatter.ofPattern("yyyy-MM", Locale.FRANCE));
result = new TimeMark(month);
//
return result;
}
/** /**
* Year of. * Year of.
* *
@ -324,7 +324,7 @@ public class TimeMark
{ {
TimeMark result; TimeMark result;
String yearWeek = date.format(DateTimeFormatter.ofPattern("yyyy-'W'ww", Locale.FRANCE)); String yearWeek = date.format(DateTimeFormatter.ofPattern("yyyyWW", Locale.FRANCE));
result = new TimeMark(yearWeek); result = new TimeMark(yearWeek);
// //
@ -342,7 +342,7 @@ public class TimeMark
{ {
TimeMark result; TimeMark result;
String yearWeek = date.format(DateTimeFormatter.ofPattern("yyyyww", Locale.FRANCE)); String yearWeek = date.format(DateTimeFormatter.ofPattern("yyyyWW", Locale.FRANCE));
result = new TimeMark(yearWeek); result = new TimeMark(yearWeek);
// //

View file

@ -31,7 +31,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.IpCounters;
import fr.devinsy.statoolinfos.metrics.PathCounters; import fr.devinsy.statoolinfos.metrics.PathCounters;
import fr.devinsy.statoolinfos.util.FilesUtils; import fr.devinsy.statoolinfos.util.FilesUtils;
import fr.devinsy.statoolinfos.util.LineIterator; import fr.devinsy.statoolinfos.util.LineIterator;
@ -43,6 +42,8 @@ public class HttpAccessLogAnalyzer
{ {
private static Logger logger = LoggerFactory.getLogger(HttpAccessLogAnalyzer.class); private static Logger logger = LoggerFactory.getLogger(HttpAccessLogAnalyzer.class);
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
// log_format combined '$remote_addr - $remote_user [$time_local] ' // log_format combined '$remote_addr - $remote_user [$time_local] '
// '"$request" $status $body_bytes_sent ' // '"$request" $status $body_bytes_sent '
// '"$http_referer" "$http_user_agent"'; // '"$http_referer" "$http_user_agent"';

View file

@ -41,6 +41,8 @@ public class HttpErrorLogAnalyzer
{ {
private static Logger logger = LoggerFactory.getLogger(HttpErrorLogAnalyzer.class); private static Logger logger = LoggerFactory.getLogger(HttpErrorLogAnalyzer.class);
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
public static final Pattern NGINX_ERROR_PATTERN = Pattern.compile("^(?<time>\\S+\\s\\S+)\\s\\[(?<level>[^\\]]*)\\]\\s.*$"); public static final Pattern NGINX_ERROR_PATTERN = Pattern.compile("^(?<time>\\S+\\s\\S+)\\s\\[(?<level>[^\\]]*)\\]\\s.*$");
public static final Pattern APACHE_ERROR_PATTERN = Pattern.compile("^\\[(?<time>[^\\]]+)\\]\\s\\[(?<level>[^\\]]*)\\]\\s(?<message>.*)$"); public static final Pattern APACHE_ERROR_PATTERN = Pattern.compile("^\\[(?<time>[^\\]]+)\\]\\s\\[(?<level>[^\\]]*)\\]\\s(?<message>.*)$");

View file

@ -33,6 +33,8 @@ public class HttpLogIterator
{ {
private static Logger logger = LoggerFactory.getLogger(HttpLogIterator.class); private static Logger logger = LoggerFactory.getLogger(HttpLogIterator.class);
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
private long errorCount; private long errorCount;
private LineIterator iterator; private LineIterator iterator;

View file

@ -16,13 +16,11 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>. * along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.devinsy.statoolinfos.metrics; package fr.devinsy.statoolinfos.metrics.http;
import java.util.HashMap; import java.util.HashMap;
import org.apache.commons.lang3.StringUtils; import fr.devinsy.statoolinfos.metrics.PathCounters;
import fr.devinsy.statoolinfos.util.IpUtils;
import fr.devinsy.strings.StringSet; import fr.devinsy.strings.StringSet;
/** /**
@ -88,17 +86,14 @@ public class IpCounters extends HashMap<String, StringSet>
*/ */
public void put(final String ip, final String timemark) public void put(final String ip, final String timemark)
{ {
if (!StringUtils.isBlank(ip)) StringSet set = super.get(timemark);
if (set == null)
{ {
StringSet set = super.get(timemark); set = new StringSet();
if (set == null) put(timemark, set);
{
set = new StringSet();
put(timemark, set);
}
set.put(ip);
} }
set.put(ip);
} }
/** /**
@ -111,44 +106,9 @@ public class IpCounters extends HashMap<String, StringSet>
*/ */
public void put(final String ip, final String... timeMarks) public void put(final String ip, final String... timeMarks)
{ {
if (!StringUtils.isBlank(ip)) for (String timeMark : timeMarks)
{ {
for (String timeMark : timeMarks) put(ip, timeMark);
{
put(ip, timeMark);
}
}
}
/**
* Put ipv 4.
*
* @param ip
* the ip
* @param timeMarks
* the time marks
*/
public void putIpv4(final String ip, final String... timeMarks)
{
if (IpUtils.isIpv4(ip))
{
put(ip, timeMarks);
}
}
/**
* Put ipv 6.
*
* @param ip
* the ip
* @param timeMarks
* the time marks
*/
public void putIpv6(final String ip, final String... timeMarks)
{
if (IpUtils.isIpv6(ip))
{
put(ip, timeMarks);
} }
} }
} }

View file

@ -28,6 +28,8 @@ public class NGinxLogAnalyzer
{ {
private static Logger logger = LoggerFactory.getLogger(NGinxLogAnalyzer.class); private static Logger logger = LoggerFactory.getLogger(NGinxLogAnalyzer.class);
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
/** /**
* Instantiates a new n ginx log analyzer. * Instantiates a new n ginx log analyzer.
*/ */

View file

@ -1,84 +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.jitsi;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.PathCounters;
/**
* The Class JitsiProber.
*/
public class JitsiProber
{
private static Logger logger = LoggerFactory.getLogger(JitsiProber.class);
/**
* Instantiates a new minetest prober.
*/
public JitsiProber()
{
}
/**
* Probe.
*
* @param logs
* the logs
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probe(final String logs) throws IOException, StatoolInfosException
{
PathCounters result;
result = new PathCounters();
// result = MumbleLogAnalyzer.probe(logs);
// metrics.service.users
// metrics.service.accounts
// metrics.service.accounts.active
// metrics.service.database.bytes
// metrics.service.files.bytes
// metrics.videos.count
// metrics.videos.lives
// metrics.videos.views
// metrics.videos.comments
// metrics.videos.channels
// metrics.videos.federated.count
// metrics.videos.federated.comments
// metrics.videos.instances.followed
// metrics.videos.instances.followers
// accounts
// database size
// file size
//
return result;
}
}

View file

@ -16,25 +16,24 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>. * along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
*/ */
package fr.devinsy.statoolinfos.metrics; package fr.devinsy.statoolinfos.metrics.minetest;
import java.util.HashMap; import java.util.HashMap;
import org.apache.commons.lang3.StringUtils; import fr.devinsy.statoolinfos.metrics.PathCounters;
import fr.devinsy.strings.StringSet; import fr.devinsy.strings.StringSet;
/** /**
* The Class ActivePlayerCounters. * The Class ActivePlayerCounters.
*/ */
public class UserCounters extends HashMap<String, StringSet> public class ActivePlayerCounters extends HashMap<String, StringSet>
{ {
private static final long serialVersionUID = 8340304752282908677L; private static final long serialVersionUID = 8340304752282908677L;
/** /**
* Instantiates a new active player counters. * Instantiates a new active player counters.
*/ */
public UserCounters() public ActivePlayerCounters()
{ {
super(); super();
} }
@ -87,17 +86,14 @@ public class UserCounters extends HashMap<String, StringSet>
*/ */
public void put(final String nickname, final String timemark) public void put(final String nickname, final String timemark)
{ {
if (!StringUtils.isBlank(nickname)) StringSet set = super.get(timemark);
if (set == null)
{ {
StringSet set = super.get(timemark); set = new StringSet();
if (set == null) put(timemark, set);
{
set = new StringSet();
put(timemark, set);
}
set.put(nickname);
} }
set.put(nickname);
} }
/** /**
@ -110,12 +106,9 @@ public class UserCounters extends HashMap<String, StringSet>
*/ */
public void put(final String nickname, final String... timeMarks) public void put(final String nickname, final String... timeMarks)
{ {
if (!StringUtils.isBlank(nickname)) for (String timeMark : timeMarks)
{ {
for (String timeMark : timeMarks) put(nickname, timeMark);
{
put(nickname, timeMark);
}
} }
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org> * Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of StatoolInfos, simple service statistics tool. * This file is part of StatoolInfos, simple service statistics tool.
* *
@ -31,9 +31,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException; import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.IpCounters;
import fr.devinsy.statoolinfos.metrics.PathCounters; import fr.devinsy.statoolinfos.metrics.PathCounters;
import fr.devinsy.statoolinfos.metrics.UserCounters; import fr.devinsy.statoolinfos.metrics.http.IpCounters;
import fr.devinsy.statoolinfos.util.FilesUtils; import fr.devinsy.statoolinfos.util.FilesUtils;
import fr.devinsy.statoolinfos.util.IpUtils; import fr.devinsy.statoolinfos.util.IpUtils;
import fr.devinsy.statoolinfos.util.LineIterator; import fr.devinsy.statoolinfos.util.LineIterator;
@ -45,6 +44,8 @@ public class MinetestLogAnalyzer
{ {
private static Logger logger = LoggerFactory.getLogger(MinetestLogAnalyzer.class); private static Logger logger = LoggerFactory.getLogger(MinetestLogAnalyzer.class);
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
// log_format combined '$remote_addr - $remote_user [$time_local] ' // log_format combined '$remote_addr - $remote_user [$time_local] '
// '"$request" $status $body_bytes_sent ' // '"$request" $status $body_bytes_sent '
// '"$http_referer" "$http_user_agent"'; // '"$http_referer" "$http_user_agent"';
@ -53,7 +54,7 @@ public class MinetestLogAnalyzer
private int errorCount; private int errorCount;
private PathCounters counters; private PathCounters counters;
private UserCounters activePlayers; private ActivePlayerCounters activePlayers;
private IpCounters ips; private IpCounters ips;
private IpCounters ipv4; private IpCounters ipv4;
private IpCounters ipv6; private IpCounters ipv6;
@ -64,7 +65,7 @@ public class MinetestLogAnalyzer
public MinetestLogAnalyzer() public MinetestLogAnalyzer()
{ {
this.counters = new PathCounters(); this.counters = new PathCounters();
this.activePlayers = new UserCounters(); this.activePlayers = new ActivePlayerCounters();
this.ips = new IpCounters(); this.ips = new IpCounters();
this.ipv4 = new IpCounters(); this.ipv4 = new IpCounters();
this.ipv6 = new IpCounters(); this.ipv6 = new IpCounters();
@ -82,10 +83,10 @@ public class MinetestLogAnalyzer
result = new PathCounters(); result = new PathCounters();
result.putAll(this.counters); result.putAll(this.counters);
result.putAll(this.activePlayers.getCounters("metrics.service.users")); result.putAll(this.activePlayers.getCounters("metrics.metaverse.players.active"));
result.putAll(this.ips.getCounters("metrics.service.ip")); result.putAll(this.ips.getCounters("metrics.metaverse.ip"));
result.putAll(this.ipv4.getCounters("metrics.service.ip.ipv4")); result.putAll(this.ipv4.getCounters("metrics.metaverse.ip.ipv4"));
result.putAll(this.ipv6.getCounters("metrics.service.ip.ipv6")); result.putAll(this.ipv6.getCounters("metrics.metaverse.ip.ipv6"));
// //
return result; return result;
@ -147,8 +148,9 @@ public class MinetestLogAnalyzer
if (log != null) if (log != null)
{ {
// logger.info("LINE IS MATCHING [{}]", log); // logger.info("LINE IS MATCHING [{}]", log);
// logger.info(log.getHttpUserAgent().toString());
// Timemarks. // General HTTP access logs.
String year = log.getYear(); String year = log.getYear();
String yearMonth = log.getYearMonth(); String yearMonth = log.getYearMonth();
String yearWeek = log.getYearWeek(); String yearWeek = log.getYearWeek();
@ -183,21 +185,20 @@ public class MinetestLogAnalyzer
} }
// metrics.metaverse.players.active // metrics.metaverse.players.active
// metrics.service.users
this.activePlayers.put(log.getNickname(), year, yearMonth, yearWeek, date); this.activePlayers.put(log.getNickname(), year, yearMonth, yearWeek, date);
// metrics.metaverse.players.max // metrics.metaverse.players.max
// TODO // TODO
// metrics.metaverse.joiners -- // metrics.metaverse.joins --
if (log.getMessage().contains(" joins game.")) if (log.getMessage().contains(" joins game."))
{ {
this.counters.inc("metrics.metaverse.joiners", year, yearMonth, yearWeek, date); this.counters.inc("metrics.metaverse.joins", year, yearMonth, yearWeek, date);
} }
// metrics.service.ip // metrics.metaverse.ip
// metrics.service.ip.ipv4 // metrics.metaverse.ip.ipv4
// metrics.service.ip.ipv6 // metrics.metaverse.ip.ipv6
String ip = log.getIp(); String ip = log.getIp();
if (ip != null) if (ip != null)
{ {

View file

@ -32,11 +32,11 @@ public enum MinetestLogLevel
UNKNOWN; UNKNOWN;
/** /**
* Of. * Value of.
* *
* @param value * @param httpCode
* the value * the code
* @return the minetest log level * @return the http status category
*/ */
public static MinetestLogLevel of(final String value) public static MinetestLogLevel of(final String value)
{ {

View file

@ -0,0 +1,63 @@
/*
* Copyright (C) 2020 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.minetest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class HttpAccesLogStat.
*/
public class MinetestLogStat
{
private static Logger logger = LoggerFactory.getLogger(MinetestLogStat.class);
private int hitCount;
private int hitIpv4Count;
private int hitIpv6Count;
private int pageCount;
private int pageIpv4Count;
private int pageIpv6Count;
private int byteCount;
private int byteIpv4Count;
private int byteIpv6Count;
private int fileCount;
private int fileIpv4Count;
private int fileIpv6Count;
private int status1xxCount;
private int status2xxCount;
private int status3xxCount;
private int status4xxCount;
private int status5xxCount;
private int ipCount;
private int ipIpv4Count;
private int ipIpv6Count;
/**
* Instantiates a new http acces log stat.
*/
public MinetestLogStat()
{
}
}

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org> * Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
* *
* This file is part of StatoolInfos, simple service statistics tool. * This file is part of StatoolInfos, simple service statistics tool.
* *
@ -34,6 +34,8 @@ public class MinetestProber
{ {
private static Logger logger = LoggerFactory.getLogger(MinetestProber.class); private static Logger logger = LoggerFactory.getLogger(MinetestProber.class);
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
/** /**
* Instantiates a new minetest prober. * Instantiates a new minetest prober.
*/ */

View file

@ -1,63 +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.mumble;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.PathCounters;
/**
* The Class HttpAccessLogProber.
*/
public class MumbleDatabaseAnalyzer
{
private static Logger logger = LoggerFactory.getLogger(MumbleDatabaseAnalyzer.class);
/**
* Instantiates a new http access log prober.
*/
private MumbleDatabaseAnalyzer()
{
}
/**
* Probe.
*
* @param databasePath
* the database path
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probe(final String databasePath) throws IOException, StatoolInfosException
{
PathCounters result;
result = new PathCounters();
//
return result;
}
}

View file

@ -1,250 +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.mumble;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.metrics.TimeMarkUtils;
import fr.devinsy.strings.StringList;
/**
* The Class MinetestLog.
*/
public class MumbleLog
{
private static Logger logger = LoggerFactory.getLogger(MumbleLog.class);
// 1 => <8:neox(-1)> Authenticated
public static final Pattern NICK_PATTERN = Pattern.compile("^1 => <\\d+:(?<nickname>neox)(-?\\d+)> Authenticated$");
// 1 => <6:Cpm(-1)> Moved Cpm:6(-1) to Salon blabla 1[3:0]
public static final Pattern ROOM_PATTERN = Pattern.compile("^Moved .+ to (?<room>.+)[.+]$");
// 1 => <6:(-1)> New connection: 123.456.78.90:54958
// 1 => <2:(-1)> New connection: [1234:5678:90ab:cdef::aaaa:eeee]:57588
public static final Pattern IP_PATTERN = Pattern.compile("^New connection: (?<ip>.+)$");
private MumbleLogLevel level;
private LocalDateTime time;
private String message;
/**
* Instantiates a new mumble log.
*/
public MumbleLog()
{
this.time = null;
this.level = null;
this.message = null;
}
public String getDate()
{
String result;
result = this.time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.FRANCE));
//
return result;
}
/**
* Gets the ip.
*
* @return the ip
*/
public String getIp()
{
String result;
Matcher matcher = IP_PATTERN.matcher(this.message);
if (matcher.matches())
{
result = matcher.group("ip");
}
else
{
result = null;
}
//
return result;
}
public MumbleLogLevel getLevel()
{
return this.level;
}
public String getMessage()
{
return this.message;
}
/**
* Gets the nickname.
*
* @return the nickname
*/
public String getNickname()
{
String result;
Matcher matcher = NICK_PATTERN.matcher(this.message);
if (matcher.matches())
{
result = matcher.group("nickname");
}
else
{
result = null;
}
//
return result;
}
public String getRoomName()
{
String result;
Matcher matcher = ROOM_PATTERN.matcher(this.message);
if (matcher.matches())
{
result = matcher.group("room");
}
else
{
result = null;
}
//
return result;
}
public LocalDateTime getTime()
{
return this.time;
}
/**
* Gets the year.
*
* @return the year
*/
public String getYear()
{
String result;
if (this.time == null)
{
result = null;
}
else
{
result = TimeMarkUtils.yearOf(this.time);
}
//
return result;
}
/**
* Gets the year month.
*
* @return the year month
*/
public String getYearMonth()
{
String result;
if (this.time == null)
{
result = null;
}
else
{
result = TimeMarkUtils.yearMonthOf(this.time);
}
//
return result;
}
/**
* Gets the year week.
*
* @return the year week
*/
public String getYearWeek()
{
String result;
if (this.time == null)
{
result = null;
}
else
{
result = TimeMarkUtils.yearWeekOf(this.time);
}
//
return result;
}
public void setLevel(final MumbleLogLevel level)
{
this.level = level;
}
public void setMessage(final String message)
{
this.message = message;
}
public void setTime(final LocalDateTime time)
{
this.time = time;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString()
{
String result;
StringList buffer = new StringList();
buffer.append("[time=").append(this.time).append("]");
result = buffer.toString();
//
return result;
}
}

View file

@ -1,284 +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.mumble;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.IpCounters;
import fr.devinsy.statoolinfos.metrics.PathCounters;
import fr.devinsy.statoolinfos.metrics.UserCounters;
import fr.devinsy.statoolinfos.util.FilesUtils;
import fr.devinsy.statoolinfos.util.IpUtils;
import fr.devinsy.statoolinfos.util.LineIterator;
/**
* The Class HttpAccessLogProber.
*/
public class MumbleLogAnalyzer
{
private static Logger logger = LoggerFactory.getLogger(MumbleLogAnalyzer.class);
// https://salsa.debian.org/pkg-voip-team/mumble/-/blob/debian/src/murmur/main.cpp#L92
// QString m= QString::fromLatin1("<%1>%2 %3")
// .arg(QChar::fromLatin1(c))
// .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"))
// .arg(msg);
public static final Pattern MUMBLE_LOG_PATTERN = Pattern.compile("^<(?<level>[DWCFX])>(?<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}) (?<message>.*)$");
private int errorCount;
private PathCounters counters;
private UserCounters users;
private IpCounters ips;
private IpCounters ipv4;
private IpCounters ipv6;
private UserCounters rooms;
/**
* Instantiates a new http access log prober.
*/
public MumbleLogAnalyzer()
{
this.counters = new PathCounters();
this.users = new UserCounters();
this.ips = new IpCounters();
this.ipv4 = new IpCounters();
this.ipv6 = new IpCounters();
this.rooms = new UserCounters();
}
/**
* Gets the counters.
*
* @return the counters
*/
public PathCounters getCounters()
{
PathCounters result;
result = new PathCounters();
result.putAll(this.counters);
result.putAll(this.users.getCounters("metrics.service.users"));
result.putAll(this.ips.getCounters("metrics.service.ip"));
result.putAll(this.ipv4.getCounters("metrics.service.ip.ipv4"));
result.putAll(this.ipv6.getCounters("metrics.service.ip.ipv6"));
result.putAll(this.rooms.getCounters("metrics.audioconferencing.rooms.active"));
//
return result;
}
/**
* Probe.
*
* @param file
* the file
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public void probe(final File file) throws IOException
{
System.out.println("Probing file [" + file.getAbsolutePath() + "]");
//
LineIterator iterator = new LineIterator(file);
while (iterator.hasNext())
{
String line = iterator.next();
try
{
if ((!StringUtils.isBlank(line)) && (!StringUtils.startsWith(line, " ")) && (!StringUtils.startsWith(line, "-")))
{
MumbleLog log = parseLog(line);
if (log == null)
{
logger.warn("LINE IS NOT MATCHING [{}]", line);
}
else
{
probeLog(log);
}
}
}
catch (Exception exception)
{
logger.warn("Error parsing line [{}][{}]", line, exception.getMessage());
exception.printStackTrace();
this.errorCount += 1;
}
}
}
/**
* Probe log.
*
* @param log
* the log
*/
public void probeLog(final MumbleLog log)
{
// logger.info("==================");
if (log != null)
{
// logger.info("LINE IS MATCHING [{}]", log);
// Timemarks.
String year = log.getYear();
String yearMonth = log.getYearMonth();
String yearWeek = log.getYearWeek();
String date = log.getDate();
// metrics.mumble.logs
this.counters.inc("metrics.mumble.logs", year, yearMonth, yearWeek, date);
// metrics.mumble.logs.debug
// metrics.mumble.logs.warning
// metrics.mumble.logs.critical
// metrics.mumble.logs.fatal
// metrics.mumble.logs.default
if (log.getLevel() == MumbleLogLevel.DEBUG)
{
this.counters.inc("metrics.mumble.logs.debug", year, yearMonth, yearWeek, date);
}
else if (log.getLevel() == MumbleLogLevel.WARNING)
{
this.counters.inc("metrics.mumble.logs.warning", year, yearMonth, yearWeek, date);
}
else if (log.getLevel() == MumbleLogLevel.CRITICAL)
{
this.counters.inc("metrics.mumble.logs.critical", year, yearMonth, yearWeek, date);
}
else if (log.getLevel() == MumbleLogLevel.FATAL)
{
this.counters.inc("metrics.mumble.logs.fatal", year, yearMonth, yearWeek, date);
}
else if (log.getLevel() == MumbleLogLevel.DEFAULT)
{
this.counters.inc("metrics.mumble.logs.DEFAULT", year, yearMonth, yearWeek, date);
}
// metrics.service.users
this.users.put(log.getNickname(), year, yearMonth, yearWeek, date);
// metrics.service.users.max
// TODO
// metrics.audioconferencing.joiners
if (log.getMessage().contains(" Authenticated"))
{
this.counters.inc("metrics.audioconferencing.joiners", year, yearMonth, yearWeek, date);
}
// metrics.sevice.ip
// metrics.service.ip.ipv4
// metrics.service.ip.ipv6
String ip = log.getIp();
if (ip != null)
{
this.ips.put(ip, year, yearMonth, yearWeek, date);
if (IpUtils.isIpv4(ip))
{
this.ipv4.put(ip, year, yearMonth, yearWeek, date);
}
else
{
this.ipv6.put(ip, year, yearMonth, yearWeek, date);
}
}
// metrics.audioconferencing.rooms.active
this.rooms.put(log.getRoomName(), year, yearMonth, yearWeek, date);
// metrics.audioconferencing.conferences
// metrics.audioconferencing.hours
// metrics.audioconferencing.traffic.received.bytes
// metrics.audioconferencing.traffic.sent.bytes
// TODO
}
}
/**
* Parses the log.
*
* @param line
* the line
* @return the http log
*/
public static MumbleLog parseLog(final String line)
{
MumbleLog result;
Matcher matcher = MUMBLE_LOG_PATTERN.matcher(line);
if (matcher.matches())
{
result = new MumbleLog();
result.setTime(LocalDateTime.parse(matcher.group("datetime"), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS").withLocale(Locale.ENGLISH)));
result.setLevel(MumbleLogLevel.of(matcher.group("level")));
result.setMessage(matcher.group("message"));
}
else
{
result = null;
}
//
return result;
}
/**
* Probe.
*
* @param source
* the source
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probe(final String source) throws IOException, StatoolInfosException
{
PathCounters result;
MumbleLogAnalyzer analyzer = new MumbleLogAnalyzer();
for (File file : FilesUtils.searchByWildcard(source))
{
analyzer.probe(file);
}
result = analyzer.getCounters();
//
return result;
}
}

View file

@ -1,72 +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.mumble;
import org.apache.commons.lang3.StringUtils;
/**
* The Enum MinetestLogLevel.
*
* List comes from Mumble-server source:
* https://salsa.debian.org/pkg-voip-team/mumble/-/blob/debian/src/murmur/main.cpp#L74
*/
public enum MumbleLogLevel
{
DEBUG,
WARNING,
CRITICAL,
FATAL,
DEFAULT;
/**
* Of.
*
* @param value
* the value
* @return the mumble log level
*/
public static MumbleLogLevel of(final String value)
{
MumbleLogLevel result;
if (StringUtils.equals(value, "DEBUG"))
{
result = DEBUG;
}
else if (StringUtils.equals(value, "WARNING"))
{
result = WARNING;
}
else if (StringUtils.equals(value, "CRITICAL"))
{
result = CRITICAL;
}
else if (StringUtils.equals(value, "FATAL"))
{
result = FATAL;
}
else
{
result = DEFAULT;
}
//
return result;
}
}

View file

@ -1,69 +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.mumble;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.PathCounters;
/**
* The Class MinetestProber.
*/
public class MumbleProber
{
private static Logger logger = LoggerFactory.getLogger(MumbleProber.class);
/**
* Instantiates a new minetest prober.
*/
public MumbleProber()
{
}
/**
* Probe.
*
* @param logs
* the logs
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probe(final String logs) throws IOException, StatoolInfosException
{
PathCounters result;
result = MumbleLogAnalyzer.probe(logs);
// result.putAll(MumbleDatabaseAnalyzer.probe());
// accounts
// database size
// file size
//
return result;
}
}

View file

@ -1,91 +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.privatebin;
import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.PathCounters;
import fr.devinsy.statoolinfos.metrics.TimeMark;
import fr.devinsy.statoolinfos.util.FilesUtils;
/**
* The Class PrivatebinDataAnalyzer.
*/
public class PrivatebinDataAnalyzer
{
private static Logger logger = LoggerFactory.getLogger(PrivatebinDataAnalyzer.class);
/**
* Instantiates a new http access log prober.
*/
private PrivatebinDataAnalyzer()
{
}
/**
* Probe.
*
* @param dataDirectory
* the data directory
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probe(final File dataDirectory) throws IOException, StatoolInfosException
{
PathCounters result;
System.out.println("Probing directory [" + dataDirectory + "]");
result = new PathCounters();
if ((dataDirectory.exists()) && (dataDirectory.isDirectory()))
{
LocalDate now = LocalDate.now();
String year = TimeMark.yearOf(now).toString();
String yearMonth = TimeMark.yearMonthOf(now).toString();
String yearWeek = TimeMark.yearWeekOf(now).toString();
String date = TimeMark.dayOf(now).toString();
// metrics.service.files.bytes
long size = FileUtils.sizeOfDirectory(dataDirectory);
result.set(size, "metrics.service.files.bytes", year, yearMonth, yearWeek, date);
// metrics.pastebins.count
long count = FilesUtils.searchByWildcard(dataDirectory.getAbsolutePath() + "/??/*").size();
result.set(count, "metrics.pastebins.count", year, yearMonth, yearWeek, date);
}
else
{
System.out.println("WARNING: Privatebin data path is not valid.");
}
//
return result;
}
}

View file

@ -1,215 +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.privatebin;
import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.PathCounters;
import fr.devinsy.statoolinfos.metrics.UserCounters;
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLog;
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer;
import fr.devinsy.statoolinfos.util.FilesUtils;
import fr.devinsy.statoolinfos.util.LineIterator;
/**
* The Class HttpAccessLogProber.
*/
public class PrivatebinHttpLogAnalyzer
{
private static Logger logger = LoggerFactory.getLogger(PrivatebinHttpLogAnalyzer.class);
private PathCounters counters;
private UserCounters users;
private UserCounters ipv4Users;
private UserCounters ipv6Users;
/**
* Instantiates a new http access log prober.
*/
public PrivatebinHttpLogAnalyzer()
{
this.counters = new PathCounters();
this.users = new UserCounters();
this.ipv4Users = new UserCounters();
this.ipv6Users = new UserCounters();
}
/**
* Gets the counters.
*
* @return the counters
*/
public PathCounters getCounters()
{
PathCounters result;
result = new PathCounters();
result.putAll(this.counters);
result.putAll(this.users.getCounters("metrics.service.users"));
result.putAll(this.ipv4Users.getCounters("metrics.service.users.ipv4"));
result.putAll(this.ipv6Users.getCounters("metrics.service.users.ipv6"));
//
return result;
}
/**
* Probe.
*
* @param file
* the file
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public void probe(final File file, final String patternRegex) throws IOException
{
System.out.println("Probing file [" + file.getAbsolutePath() + "]");
//
Pattern pattern;
if (patternRegex == null)
{
pattern = HttpAccessLogAnalyzer.COMBINED_PATTERN;
}
else
{
pattern = Pattern.compile(patternRegex);
}
//
LineIterator iterator = new LineIterator(file);
while (iterator.hasNext())
{
String line = iterator.next();
try
{
HttpAccessLog log = HttpAccessLogAnalyzer.parseLog(line, pattern);
if (log == null)
{
logger.warn("LINE IS NOT MATCHING [{}]", line);
}
else
{
probeLog(log);
}
}
catch (Exception exception)
{
logger.warn("Error parsing line [{}][{}]", line, exception.getMessage());
exception.printStackTrace();
}
}
}
/**
* Probe log.
*
* @param log
* the log
*/
public void probeLog(final HttpAccessLog log)
{
if (log != null)
{
// logger.info("LINE IS MATCHING [{}]", log);
// logger.info(log.getHttpUserAgent().toString());
// General HTTP access logs.
String year = log.getYear();
String yearMonth = log.getYearMonth();
String yearWeek = log.getYearWeek();
String date = log.getDate();
// metrics.service.users
// metrics.service.users.ipv4
// metrics.service.users.ipv6
if (StringUtils.startsWithAny(log.getRequest(), "POST ", "GET /?pasteid="))
{
String key = String.format("%s---%s", log.getIp(), log.getUserAgent());
this.users.put(key, year, yearMonth, yearWeek, date);
if (log.isIPv4())
{
this.ipv4Users.put(key, year, yearMonth, yearWeek, date);
}
else
{
this.ipv6Users.put(key, year, yearMonth, yearWeek, date);
}
}
// metrics.pastebins.created
// metrics.pastebins.read
// metrics.pastebins.deleted
if (StringUtils.startsWith(log.getRequest(), "POST "))
{
this.counters.inc("metrics.pastebins.created", year, yearMonth, yearWeek, date);
}
else if (StringUtils.startsWith(log.getRequest(), "GET /?pasteid="))
{
if (StringUtils.contains(log.getRequest(), "&deletetoken="))
{
this.counters.inc("metrics.pastebins.deleted", year, yearMonth, yearWeek, date);
}
else
{
this.counters.inc("metrics.pastebins.read", year, yearMonth, yearWeek, date);
}
}
}
}
/**
* Probe.
*
* @param httpAccessLogs
* the source
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probe(final String httpAccessLogs, final String httpRegex) throws IOException, StatoolInfosException
{
PathCounters result;
PrivatebinHttpLogAnalyzer analyzer = new PrivatebinHttpLogAnalyzer();
for (File file : FilesUtils.searchByWildcard(httpAccessLogs))
{
analyzer.probe(file, httpRegex);
}
result = analyzer.getCounters();
//
return result;
}
}

View file

@ -1,81 +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.privatebin;
import java.io.File;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.metrics.PathCounters;
/**
* The Class PrivatebinProber.
*/
public class PrivatebinProber
{
private static Logger logger = LoggerFactory.getLogger(PrivatebinProber.class);
/**
* Instantiates a new privatebin prober.
*/
public PrivatebinProber()
{
}
/**
* Probe.
*
* @param httpLogs
* the http logs
* @param httpLogRegex
* the http log regex
* @param dataPath
* the data path
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probe(final String httpLogs, final String httpLogRegex, final File dataPath) throws IOException, StatoolInfosException
{
PathCounters result;
// metrics.service.users
// metrics.service.users.ipv4
// metrics.service.users.ipv6
// metrics.pastebins.created
// metrics.pastebins.read
// metrics.pastebins.deleted
result = PrivatebinHttpLogAnalyzer.probe(httpLogs, httpLogRegex);
// metrics.service.files.bytes
// metrics.pastebins.count
result.putAll(PrivatebinDataAnalyzer.probe(dataPath));
// metrics.pastebins.purged
// purged = count(n-1) - count(n) + created - delete
//
return result;
}
}

View file

@ -18,7 +18,6 @@
*/ */
package fr.devinsy.statoolinfos.properties; package fr.devinsy.statoolinfos.properties;
import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.time.Year; import java.time.Year;
@ -172,32 +171,6 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
return result; return result;
} }
/**
* Gets the as file.
*
* @param path
* the path
* @return the as file
*/
public File getAsFile(final String path)
{
File result;
String value = get(path);
if (value == null)
{
result = null;
}
else
{
result = new File(value);
}
//
return result;
}
/** /**
* Gets the by pattern. * Gets the by pattern.
* *

View file

@ -289,7 +289,7 @@ public class PathPropertyUtils
PrintWriter out = null; PrintWriter out = null;
try try
{ {
out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
write(out, source); write(out, source);
} }
finally finally

View file

@ -158,7 +158,7 @@ public class UptimeJournalFile
PrintWriter out = null; PrintWriter out = null;
try try
{ {
out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)); out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
write(out, source); write(out, source);
} }
finally finally

View file

@ -162,21 +162,6 @@ public class BuildInformation
return this.productName; return this.productName;
} }
/**
* Version name.
*
* @return the string
*/
public String protocol()
{
String result;
result = String.format("%s %s.%s.%s", this.productName, this.majorRevision, this.minorRevision, this.buildNumber);
//
return result;
}
/** /**
* Snapshot revision. * Snapshot revision.
* *

View file

@ -65,6 +65,23 @@ public class IpUtils
return result; return result;
} }
/**
* Checks if is ipv6.
*
* @param input
* the input
* @return true, if is ipv6
*/
public static boolean isIpv6(final String input)
{
boolean result;
result = IPV6_PATTERN.matcher(input).matches();
//
return result;
}
/** /**
* Checks if is ipv6. * Checks if is ipv6.
* *
@ -72,7 +89,7 @@ public class IpUtils
* the value * the value
* @return true, if is ipv6 * @return true, if is ipv6
*/ */
public static boolean isIpv6(final String value) public static boolean isIPv6(final String value)
{ {
boolean result; boolean result;
@ -80,10 +97,6 @@ public class IpUtils
{ {
result = false; result = false;
} }
else if (value.startsWith("::ffff:"))
{
result = false;
}
else else
{ {
result = value.contains(":"); result = value.contains(":");
@ -109,21 +122,4 @@ public class IpUtils
// //
return result; return result;
} }
/**
* Checks if is ipv6.
*
* @param input
* the input
* @return true, if is ipv6
*/
public static boolean isValidIpv6(final String input)
{
boolean result;
result = IPV6_PATTERN.matcher(input).matches();
//
return result;
}
} }

View file

@ -23,7 +23,6 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -37,6 +36,8 @@ public class LineIterator
{ {
private static Logger logger = LoggerFactory.getLogger(LineIterator.class); private static Logger logger = LoggerFactory.getLogger(LineIterator.class);
public static final String DEFAULT_CHARSET_NAME = "UTF-8";
private BufferedReader in; private BufferedReader in;
private String nextLine; private String nextLine;
private boolean ready; private boolean ready;
@ -57,7 +58,7 @@ public class LineIterator
} }
else else
{ {
this.in = new BufferedReader(new InputStreamReader(new FileInputStream(source), StandardCharsets.UTF_8)); this.in = new BufferedReader(new InputStreamReader(new FileInputStream(source), DEFAULT_CHARSET_NAME));
} }
this.nextLine = null; this.nextLine = null;