Added Etherpad probing.
This commit is contained in:
parent
0b44e9629e
commit
5601fe5d54
4 changed files with 318 additions and 1 deletions
|
@ -38,6 +38,7 @@ import fr.devinsy.statoolinfos.core.DatabaseConfig;
|
|||
import fr.devinsy.statoolinfos.core.Factory;
|
||||
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
||||
import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
|
||||
import fr.devinsy.statoolinfos.metrics.etherpad.EtherpadProber;
|
||||
import fr.devinsy.statoolinfos.metrics.gitea.GiteaProber;
|
||||
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogAnalyzer;
|
||||
import fr.devinsy.statoolinfos.metrics.http.HttpErrorLogAnalyzer;
|
||||
|
@ -133,6 +134,21 @@ public class Prober
|
|||
counters.putAll(data);
|
||||
}
|
||||
|
||||
//
|
||||
if (types.containsAnyIgnoreCase("Etherpad"))
|
||||
{
|
||||
logger.info("== Probing Etherpad.");
|
||||
String httpLogs = configuration.getProbeHttpAccessLogSource();
|
||||
logger.info("httpLogs=[{}]", httpLogs);
|
||||
String httpAccessLogRegex = configuration.getProbeHttpAccessLogPattern();
|
||||
logger.info("httpAccessPattern=[{}]", httpAccessLogRegex);
|
||||
DatabaseConfig database = configuration.getDatabaseConfig("conf.probe.gitea");
|
||||
logger.info("database={}", database.toString());
|
||||
|
||||
PathCounters metrics = EtherpadProber.probe(FilesUtils.searchByWildcard(httpLogs), httpAccessLogRegex, database);
|
||||
counters.putAll(metrics);
|
||||
}
|
||||
|
||||
//
|
||||
if (types.containsAnyIgnoreCase("Framadate"))
|
||||
{
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
/*
|
||||
* Copyright (C) 2022 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.etherpad;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
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.HttpAccessLogIterator;
|
||||
import fr.devinsy.statoolinfos.util.Files;
|
||||
|
||||
/**
|
||||
* The Class EtherpadHttpLogAnalyzer.
|
||||
*/
|
||||
public class EtherpadHttpLogAnalyzer
|
||||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(EtherpadHttpLogAnalyzer.class);
|
||||
|
||||
public static final Pattern USE_PATTERN = Pattern.compile("GET /p/\\S+ ");
|
||||
public static final Pattern CREATE_PATTERN = Pattern.compile("POST / .*");
|
||||
|
||||
private PathCounters counters;
|
||||
private UserCounters users;
|
||||
private UserCounters ipv4Users;
|
||||
private UserCounters ipv6Users;
|
||||
|
||||
/**
|
||||
* Instantiates a new http access log prober.
|
||||
*/
|
||||
public EtherpadHttpLogAnalyzer()
|
||||
{
|
||||
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 log.
|
||||
*
|
||||
* @param log
|
||||
* the log
|
||||
*/
|
||||
public void probeLog(final HttpAccessLog log)
|
||||
{
|
||||
if (log != null)
|
||||
{
|
||||
// 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 ((!log.isBot()) && (USE_PATTERN.matcher(log.getRequest()).matches()))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Probe.
|
||||
*
|
||||
* @param httpAccessLogFiles
|
||||
* the http access log files
|
||||
* @param httpRegex
|
||||
* the http regex
|
||||
* @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 Files httpAccessLogFiles, final String httpRegex) throws IOException, StatoolInfosException
|
||||
{
|
||||
PathCounters result;
|
||||
|
||||
EtherpadHttpLogAnalyzer analyzer = new EtherpadHttpLogAnalyzer();
|
||||
|
||||
HttpAccessLogIterator logs = new HttpAccessLogIterator(httpAccessLogFiles, httpRegex);
|
||||
while (logs.hasNext())
|
||||
{
|
||||
analyzer.probeLog(logs.next());
|
||||
}
|
||||
|
||||
result = analyzer.getCounters();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
154
src/fr/devinsy/statoolinfos/metrics/etherpad/EtherpadProber.java
Normal file
154
src/fr/devinsy/statoolinfos/metrics/etherpad/EtherpadProber.java
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Copyright (C) 2022 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.etherpad;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.core.DatabaseConfig;
|
||||
import fr.devinsy.statoolinfos.core.StatoolInfosException;
|
||||
import fr.devinsy.statoolinfos.metrics.PathCounters;
|
||||
import fr.devinsy.statoolinfos.metrics.util.DatabaseProber;
|
||||
import fr.devinsy.statoolinfos.util.Files;
|
||||
import fr.devinsy.statoolinfos.util.sql.SQLDatabase;
|
||||
import fr.devinsy.strings.StringList;
|
||||
|
||||
/**
|
||||
* The Class EtherpadProber.
|
||||
*/
|
||||
public class EtherpadProber
|
||||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(EtherpadProber.class);
|
||||
|
||||
/**
|
||||
* Instantiates a new etherpad prober.
|
||||
*/
|
||||
public EtherpadProber()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Files httpLogs, final String httpLogRegex, final DatabaseConfig databaseConfig) throws IOException, StatoolInfosException
|
||||
{
|
||||
PathCounters result;
|
||||
|
||||
// metrics.service.users
|
||||
// metrics.service.users.ipv4
|
||||
// metrics.service.users.ipv6
|
||||
result = EtherpadHttpLogAnalyzer.probe(httpLogs, httpLogRegex);
|
||||
|
||||
try
|
||||
{
|
||||
if (databaseConfig.isSet())
|
||||
{
|
||||
SQLDatabase database = new SQLDatabase(databaseConfig.getUrl(), databaseConfig.getUser(), databaseConfig.getPassword());
|
||||
database.open();
|
||||
|
||||
// metrics.service.database.bytes
|
||||
result.putAll(DatabaseProber.probe(database));
|
||||
|
||||
// metrics.textprocessors.characters
|
||||
// metrics.textprocessors.words
|
||||
|
||||
// metrics.etherpad.database.pads
|
||||
// metrics.textprocessors.files
|
||||
StringList timemarks = result.getNowTimeMarks();
|
||||
String sql = "select count(*) from store where key like 'pad:%' and key not like 'pad:%:%';";
|
||||
long count = database.queryNumber(sql);
|
||||
result.set(count, "metrics.etherpad.pads", timemarks);
|
||||
result.set(count, "metrics.textprocessors.files", timemarks);
|
||||
|
||||
// metrics.etherpad.database.revs.
|
||||
sql = "SELECT count(*) from store where key like 'pad:%:revs:%';";
|
||||
count = database.queryNumber(sql);
|
||||
result.set(count, "metrics.etherpad.revs", timemarks);
|
||||
|
||||
// metrics.etherpad.database.lines
|
||||
sql = "SELECT count(*) from store;";
|
||||
count = database.queryNumber(sql);
|
||||
result.set(count, "metrics.etherpad.database.lines", timemarks);
|
||||
|
||||
// metrics.etherpad.database.lines.globalAuthor
|
||||
sql = "SELECT count(*) from store where key like 'globalAuthor:%';";
|
||||
count = database.queryNumber(sql);
|
||||
result.set(count, "metrics.etherpad.database.lines.globalAuthor", timemarks);
|
||||
|
||||
// metrics.etherpad.database.lines.pad
|
||||
sql = "SELECT count(*) from store where key like 'pad:%';";
|
||||
count = database.queryNumber(sql);
|
||||
result.set(count, "metrics.etherpad.database.lines.pad", timemarks);
|
||||
|
||||
// metrics.etherpad.database.lines.pad2readonly
|
||||
sql = "SELECT count(*) from store where key like 'pad2readonly:%';";
|
||||
count = database.queryNumber(sql);
|
||||
result.set(count, "metrics.etherpad.database.lines.pad2readonly", timemarks);
|
||||
|
||||
// metrics.etherpad.database.lines.readonly2pad
|
||||
sql = "SELECT count(*) from store where key like 'readonly2pad:%';";
|
||||
count = database.queryNumber(sql);
|
||||
result.set(count, "metrics.etherpad.database.lines.readonly2pad", timemarks);
|
||||
|
||||
// metrics.etherpad.database.lines.sessionstorage
|
||||
sql = "SELECT count(*) from store where key like 'sessionstorage:%';";
|
||||
count = database.queryNumber(sql);
|
||||
result.set(count, "metrics.etherpad.database.lines.sessionstorage", timemarks);
|
||||
|
||||
// metrics.etherpad.database.lines.token2author
|
||||
sql = "SELECT count(*) from store where key like 'token2author:%';";
|
||||
count = database.queryNumber(sql);
|
||||
result.set(count, "metrics.etherpad.database.lines.token2author", timemarks);
|
||||
|
||||
//
|
||||
database.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Etherpad Database undefined.");
|
||||
}
|
||||
}
|
||||
catch (SQLException exception)
|
||||
{
|
||||
logger.error("ERROR with database.", exception);
|
||||
}
|
||||
|
||||
/*
|
||||
* select substring(key, strpos(key, ':')+1, strpos(substring(key, strpos(key, ':')+1), ':')) from store where key like 'pad:%:revs:%';
|
||||
*/
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ public class JitsiProber
|
|||
private static Logger logger = LoggerFactory.getLogger(JitsiProber.class);
|
||||
|
||||
/**
|
||||
* Instantiates a new minetest prober.
|
||||
* Instantiates a new jitsi prober.
|
||||
*/
|
||||
public JitsiProber()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue