Coded step in new specific metric probing.

This commit is contained in:
Christian P. MOMON 2021-12-31 23:24:44 +01:00
parent 68bfab5b26
commit b34903fde2
17 changed files with 1035 additions and 128 deletions

View file

@ -16,11 +16,13 @@
* 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;
package fr.devinsy.statoolinfos.metrics;
import java.util.HashMap;
import fr.devinsy.statoolinfos.metrics.PathCounters;
import org.apache.commons.lang3.StringUtils;
import fr.devinsy.statoolinfos.util.IpUtils;
import fr.devinsy.strings.StringSet;
/**
@ -86,14 +88,17 @@ public class IpCounters extends HashMap<String, StringSet>
*/
public void put(final String ip, final String timemark)
{
StringSet set = super.get(timemark);
if (set == null)
if (!StringUtils.isBlank(ip))
{
set = new StringSet();
put(timemark, set);
}
StringSet set = super.get(timemark);
if (set == null)
{
set = new StringSet();
put(timemark, set);
}
set.put(ip);
set.put(ip);
}
}
/**
@ -106,9 +111,44 @@ public class IpCounters extends HashMap<String, StringSet>
*/
public void put(final String ip, final String... timeMarks)
{
for (String timeMark : timeMarks)
if (!StringUtils.isBlank(ip))
{
put(ip, timeMark);
for (String timeMark : timeMarks)
{
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

@ -482,4 +482,44 @@ public class PathCounters extends HashMap<String, PathCounter>
//
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

@ -42,9 +42,11 @@ import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer;
import fr.devinsy.statoolinfos.metrics.http.HttpErrorLogAnalyzer;
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.PathProperty;
import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
import fr.devinsy.statoolinfos.util.BuildInformation;
import fr.devinsy.strings.StringList;
import fr.devinsy.strings.StringsUtils;
@ -161,6 +163,21 @@ public class Prober
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.
logger.info("== Filtering with {}", dayCountFilter);
if (dayCountFilter >= 0)
@ -349,7 +366,8 @@ public class Prober
metrics.appendln("file.class=metrics");
metrics.appendln("file.generator=StatoolInfos");
metrics.appendln("file.datetime=" + LocalDateTime.now().toString());
metrics.appendln("file.protocol=StatoolInfos-0.3.0");
metrics.appendln("file.protocol=" + BuildInformation.instance().protocol());
metrics.appendln();
metrics.appendln("# [Metrics]");

View file

@ -16,24 +16,25 @@
* 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;
package fr.devinsy.statoolinfos.metrics;
import java.util.HashMap;
import fr.devinsy.statoolinfos.metrics.PathCounters;
import org.apache.commons.lang3.StringUtils;
import fr.devinsy.strings.StringSet;
/**
* The Class ActivePlayerCounters.
*/
public class ActivePlayerCounters extends HashMap<String, StringSet>
public class UserCounters extends HashMap<String, StringSet>
{
private static final long serialVersionUID = 8340304752282908677L;
/**
* Instantiates a new active player counters.
*/
public ActivePlayerCounters()
public UserCounters()
{
super();
}
@ -86,14 +87,17 @@ public class ActivePlayerCounters extends HashMap<String, StringSet>
*/
public void put(final String nickname, final String timemark)
{
StringSet set = super.get(timemark);
if (set == null)
if (!StringUtils.isBlank(nickname))
{
set = new StringSet();
put(timemark, set);
}
StringSet set = super.get(timemark);
if (set == null)
{
set = new StringSet();
put(timemark, set);
}
set.put(nickname);
set.put(nickname);
}
}
/**
@ -106,9 +110,12 @@ public class ActivePlayerCounters extends HashMap<String, StringSet>
*/
public void put(final String nickname, final String... timeMarks)
{
for (String timeMark : timeMarks)
if (!StringUtils.isBlank(nickname))
{
put(nickname, timeMark);
for (String timeMark : timeMarks)
{
put(nickname, timeMark);
}
}
}
}

View file

@ -0,0 +1,84 @@
/*
* 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

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

View file

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

View file

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

View file

@ -0,0 +1,63 @@
/*
* 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

@ -0,0 +1,250 @@
/*
* 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

@ -0,0 +1,284 @@
/*
* 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

@ -0,0 +1,72 @@
/*
* 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

@ -0,0 +1,69 @@
/*
* 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

@ -18,6 +18,7 @@
*/
package fr.devinsy.statoolinfos.properties;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Year;
@ -171,6 +172,32 @@ public class PathPropertyList extends ArrayList<PathProperty> implements PathPro
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.
*

View file

@ -162,6 +162,21 @@ public class BuildInformation
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.
*

View file

@ -65,23 +65,6 @@ public class IpUtils
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.
*
@ -89,7 +72,7 @@ public class IpUtils
* the value
* @return true, if is ipv6
*/
public static boolean isIPv6(final String value)
public static boolean isIpv6(final String value)
{
boolean result;
@ -97,6 +80,10 @@ public class IpUtils
{
result = false;
}
else if (value.startsWith("::ffff:"))
{
result = false;
}
else
{
result = value.contains(":");
@ -122,4 +109,21 @@ public class IpUtils
//
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;
}
}