mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-02 08:40:01 +01:00
Fixed Metrics graphs.
This commit is contained in:
parent
dde0f74003
commit
af72986ae8
@ -28,6 +28,7 @@ import fr.neatmonster.nocheatplus.metrics.Metrics;
|
|||||||
import fr.neatmonster.nocheatplus.metrics.Metrics.Graph;
|
import fr.neatmonster.nocheatplus.metrics.Metrics.Graph;
|
||||||
import fr.neatmonster.nocheatplus.metrics.Metrics.Plotter;
|
import fr.neatmonster.nocheatplus.metrics.Metrics.Plotter;
|
||||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||||
|
import fr.neatmonster.nocheatplus.metrics.MetricsData.TicksPlotter;
|
||||||
import fr.neatmonster.nocheatplus.packets.PacketsWorkaround;
|
import fr.neatmonster.nocheatplus.packets.PacketsWorkaround;
|
||||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||||
@ -119,32 +120,33 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return MetricsData.getChecked(type);
|
final int checked = MetricsData.getChecked(type);
|
||||||
|
MetricsData.resetChecked(type);
|
||||||
|
return checked;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
checksFailed.addPlotter(new Plotter(type.name()) {
|
checksFailed.addPlotter(new Plotter(type.name()) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return MetricsData.getFailed(type);
|
final int failed = MetricsData.getFailed(type);
|
||||||
|
MetricsData.resetFailed(type);
|
||||||
|
return failed;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
violationLevels.addPlotter(new Plotter(type.name()) {
|
violationLevels.addPlotter(new Plotter(type.name()) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return (int) MetricsData.getViolationLevel(type);
|
final int violationLevel = (int) MetricsData.getViolationLevel(type);
|
||||||
|
MetricsData.resetViolationLevel(type);
|
||||||
|
return violationLevel;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
final Graph serverTicks = metrics.createGraph("Server Ticks");
|
final Graph serverTicks = metrics.createGraph("Server Ticks");
|
||||||
serverTicks.addPlotter(new Plotter("" + LagMeasureTask.getAverageTicks()) {
|
for (int ticks = 0; ticks < 21; ticks++)
|
||||||
|
serverTicks.addPlotter(new TicksPlotter(ticks));
|
||||||
@Override
|
|
||||||
public int getValue() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
metrics.start();
|
metrics.start();
|
||||||
} catch (final Exception e) {}
|
} catch (final Exception e) {}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||||
|
import fr.neatmonster.nocheatplus.metrics.Metrics.Plotter;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* M"""""`'"""`YM dP oo M""""""'YMM dP
|
* M"""""`'"""`YM dP oo M""""""'YMM dP
|
||||||
@ -20,28 +21,71 @@ import fr.neatmonster.nocheatplus.checks.ViolationData;
|
|||||||
*/
|
*/
|
||||||
public class MetricsData {
|
public class MetricsData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ticks plotter.
|
||||||
|
*/
|
||||||
|
public static class TicksPlotter extends Plotter {
|
||||||
|
|
||||||
|
/** The ticks. */
|
||||||
|
private final int ticks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new ticks plotter.
|
||||||
|
*
|
||||||
|
* @param ticks
|
||||||
|
* the ticks
|
||||||
|
*/
|
||||||
|
public TicksPlotter(final int ticks) {
|
||||||
|
super("" + ticks);
|
||||||
|
this.ticks = ticks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see fr.neatmonster.nocheatplus.metrics.Metrics.Plotter#getValue()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int getValue() {
|
||||||
|
final int ticks = MetricsData.getServerTicks(this.ticks);
|
||||||
|
MetricsData.resetServerTicks(this.ticks);
|
||||||
|
return ticks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** The violation levels. */
|
/** The violation levels. */
|
||||||
private static final Map<CheckType, Double> violationLevels = new HashMap<CheckType, Double>();
|
private static final Map<CheckType, Double> violationLevels = new HashMap<CheckType, Double>();
|
||||||
|
|
||||||
/** The checks fails. */
|
/** The checks failed. */
|
||||||
private static final Map<CheckType, Integer> checksFails = new HashMap<CheckType, Integer>();
|
private static final Map<CheckType, Integer> checksFailed = new HashMap<CheckType, Integer>();
|
||||||
|
|
||||||
/** The events checked. */
|
/** The events checked. */
|
||||||
private static final Map<CheckType, Integer> eventsChecked = new HashMap<CheckType, Integer>();
|
private static final Map<CheckType, Integer> eventsChecked = new HashMap<CheckType, Integer>();
|
||||||
|
|
||||||
|
/** The server ticks. */
|
||||||
|
private static final Map<Integer, Integer> serverTicks = new HashMap<Integer, Integer>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when an event is checked.
|
* Adds the checked.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* the type
|
* the type
|
||||||
*/
|
*/
|
||||||
public static void addChecked(final CheckType type) {
|
public static void addChecked(final CheckType type) {
|
||||||
if (type.getParent() != null)
|
if (type.getParent() != null)
|
||||||
eventsChecked.put(type, getChecked(type));
|
eventsChecked.put(type, getChecked(type) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player fails a check.
|
* Adds the ticks.
|
||||||
|
*
|
||||||
|
* @param ticks
|
||||||
|
* the ticks
|
||||||
|
*/
|
||||||
|
public static void addTicks(final int ticks) {
|
||||||
|
serverTicks.put(ticks, serverTicks.get(ticks) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the violation.
|
||||||
*
|
*
|
||||||
* @param violationData
|
* @param violationData
|
||||||
* the violation data
|
* the violation data
|
||||||
@ -49,17 +93,17 @@ public class MetricsData {
|
|||||||
public static void addViolation(final ViolationData violationData) {
|
public static void addViolation(final ViolationData violationData) {
|
||||||
final CheckType type = violationData.check.getType();
|
final CheckType type = violationData.check.getType();
|
||||||
if (type.getParent() != null) {
|
if (type.getParent() != null) {
|
||||||
|
checksFailed.put(type, getFailed(type) + 1);
|
||||||
violationLevels.put(type, getViolationLevel(type) + violationData.addedVL);
|
violationLevels.put(type, getViolationLevel(type) + violationData.addedVL);
|
||||||
checksFails.put(type, getFailed(type) + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of event checked.
|
* Gets the checked.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* the type
|
* the type
|
||||||
* @return the number of event checked
|
* @return the checked
|
||||||
*/
|
*/
|
||||||
public static int getChecked(final CheckType type) {
|
public static int getChecked(final CheckType type) {
|
||||||
if (type == CheckType.ALL) {
|
if (type == CheckType.ALL) {
|
||||||
@ -69,27 +113,40 @@ public class MetricsData {
|
|||||||
return eventsChecked;
|
return eventsChecked;
|
||||||
}
|
}
|
||||||
if (!eventsChecked.containsKey(type))
|
if (!eventsChecked.containsKey(type))
|
||||||
eventsChecked.put(type, 0);
|
resetChecked(type);
|
||||||
return eventsChecked.get(type);
|
return eventsChecked.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of failed checks.
|
* Gets the failed.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* the type
|
* the type
|
||||||
* @return the number of failed checks
|
* @return the failed
|
||||||
*/
|
*/
|
||||||
public static int getFailed(final CheckType type) {
|
public static int getFailed(final CheckType type) {
|
||||||
if (type == CheckType.ALL) {
|
if (type == CheckType.ALL) {
|
||||||
int checkFails = 0;
|
int checkFails = 0;
|
||||||
for (final double value : checksFails.values())
|
for (final double value : checksFailed.values())
|
||||||
checkFails += value;
|
checkFails += value;
|
||||||
return checkFails;
|
return checkFails;
|
||||||
}
|
}
|
||||||
if (!checksFails.containsKey(type))
|
if (!checksFailed.containsKey(type))
|
||||||
checksFails.put(type, 0);
|
resetFailed(type);
|
||||||
return checksFails.get(type);
|
return checksFailed.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the server ticks.
|
||||||
|
*
|
||||||
|
* @param ticks
|
||||||
|
* the ticks
|
||||||
|
* @return the server ticks
|
||||||
|
*/
|
||||||
|
public static int getServerTicks(final int ticks) {
|
||||||
|
if (!serverTicks.containsKey(ticks))
|
||||||
|
resetServerTicks(ticks);
|
||||||
|
return serverTicks.get(ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +164,47 @@ public class MetricsData {
|
|||||||
return violationLevel;
|
return violationLevel;
|
||||||
}
|
}
|
||||||
if (!violationLevels.containsKey(type))
|
if (!violationLevels.containsKey(type))
|
||||||
violationLevels.put(type, 0D);
|
resetViolationLevel(type);
|
||||||
return violationLevels.get(type);
|
return violationLevels.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset checked.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* the type
|
||||||
|
*/
|
||||||
|
public static void resetChecked(final CheckType type) {
|
||||||
|
eventsChecked.put(type, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset failed.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* the type
|
||||||
|
*/
|
||||||
|
public static void resetFailed(final CheckType type) {
|
||||||
|
checksFailed.put(type, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset server ticks.
|
||||||
|
*
|
||||||
|
* @param ticks
|
||||||
|
* the ticks
|
||||||
|
*/
|
||||||
|
public static void resetServerTicks(final int ticks) {
|
||||||
|
serverTicks.put(ticks, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset violation level.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* the type
|
||||||
|
*/
|
||||||
|
public static void resetViolationLevel(final CheckType type) {
|
||||||
|
violationLevels.put(type, 0D);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.bukkit.Bukkit;
|
|||||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||||
|
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* M""MMMMMMMM M"""""`'"""`YM
|
* M""MMMMMMMM M"""""`'"""`YM
|
||||||
@ -46,18 +47,6 @@ public class LagMeasureTask implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the average ticks.
|
|
||||||
*
|
|
||||||
* @return the average ticks
|
|
||||||
*/
|
|
||||||
public static int getAverageTicks() {
|
|
||||||
final int averageTicks = (int) (instance.totalTicks / instance.numberOfValues);
|
|
||||||
instance.totalTicks = 0L;
|
|
||||||
instance.numberOfValues = 0;
|
|
||||||
return averageTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if checking must be skipped (lag).
|
* Returns if checking must be skipped (lag).
|
||||||
*
|
*
|
||||||
@ -87,15 +76,9 @@ public class LagMeasureTask implements Runnable {
|
|||||||
/** The lag measure task id. */
|
/** The lag measure task id. */
|
||||||
private int lagMeasureTaskId = -1;
|
private int lagMeasureTaskId = -1;
|
||||||
|
|
||||||
/** The number of values. */
|
|
||||||
private int numberOfValues = 0;
|
|
||||||
|
|
||||||
/** The skip check. */
|
/** The skip check. */
|
||||||
private boolean skipCheck = false;
|
private boolean skipCheck = false;
|
||||||
|
|
||||||
/** The total ticks. */
|
|
||||||
private long totalTicks = 0L;
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see java.lang.Runnable#run()
|
* @see java.lang.Runnable#run()
|
||||||
*/
|
*/
|
||||||
@ -106,8 +89,11 @@ public class LagMeasureTask implements Runnable {
|
|||||||
// If the previous second took to long, skip checks during this second.
|
// If the previous second took to long, skip checks during this second.
|
||||||
skipCheck = lastInGameSecondDuration > 2000;
|
skipCheck = lastInGameSecondDuration > 2000;
|
||||||
|
|
||||||
totalTicks += Math.round(20000D / lastInGameSecondDuration);
|
// Metrics data.
|
||||||
numberOfValues++;
|
int ticks = (int) Math.round(20000D / lastInGameSecondDuration);
|
||||||
|
if (ticks > 20)
|
||||||
|
ticks = 20;
|
||||||
|
MetricsData.addTicks(ticks);
|
||||||
|
|
||||||
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_DEBUG))
|
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_DEBUG))
|
||||||
if (oldStatus != skipCheck && skipCheck)
|
if (oldStatus != skipCheck && skipCheck)
|
||||||
|
Loading…
Reference in New Issue
Block a user