MetricsManager.java 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package com.gmail.nossr50.util.metrics;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.Locale;
  6. import com.gmail.nossr50.mcMMO;
  7. import com.gmail.nossr50.config.Config;
  8. import com.gmail.nossr50.config.HiddenConfig;
  9. import com.gmail.nossr50.locale.LocaleLoader;
  10. import com.turt2live.metrics.EMetrics;
  11. import com.turt2live.metrics.Metrics;
  12. import com.turt2live.metrics.Metrics.Graph;
  13. public class MetricsManager {
  14. private static boolean setup = false;
  15. public static void setup() {
  16. if (setup) {
  17. return;
  18. }
  19. if (Config.getInstance().getStatsTrackingEnabled()) {
  20. try {
  21. EMetrics emetrics = new EMetrics(mcMMO.p);
  22. Metrics metrics = emetrics.getMetrics();
  23. // Timings Graph
  24. Graph timingsGraph = metrics.createGraph("Percentage of servers using timings");
  25. if (mcMMO.p.getServer().getPluginManager().useTimings()) {
  26. timingsGraph.addPlotter(new Metrics.Plotter("Enabled") {
  27. @Override
  28. public int getValue() {
  29. return 1;
  30. }
  31. });
  32. }
  33. else {
  34. timingsGraph.addPlotter(new Metrics.Plotter("Disabled") {
  35. @Override
  36. public int getValue() {
  37. return 1;
  38. }
  39. });
  40. }
  41. // Donut Version Graph
  42. Graph versionDonutGraph = metrics.createGraph("Donut Version");
  43. boolean haveVersionInformation = false;
  44. boolean isOfficialBuild = false;
  45. String officialKey = "e14cfacdd442a953343ebd8529138680";
  46. String version = mcMMO.p.getDescription().getVersion();
  47. InputStreamReader isr = new InputStreamReader(mcMMO.p.getResource(".jenkins"));
  48. BufferedReader br = new BufferedReader(isr);
  49. char[] key = new char[32];
  50. br.read(key);
  51. if (officialKey.equals(String.valueOf(key))) {
  52. isOfficialBuild = true;
  53. }
  54. if (version.contains("-")) {
  55. String majorVersion = version.substring(0, version.indexOf("-"));
  56. String subVersion = "";
  57. if (isOfficialBuild) {
  58. int startIndex = version.indexOf("-");
  59. if (version.substring(startIndex + 1).contains("-")) {
  60. subVersion = version.substring(startIndex, version.indexOf("-", startIndex + 1));
  61. } else {
  62. subVersion = "-release";
  63. }
  64. } else {
  65. subVersion = "-custom";
  66. }
  67. version = majorVersion + "~=~" + subVersion;
  68. haveVersionInformation = true;
  69. } else {
  70. haveVersionInformation = false;
  71. }
  72. if (haveVersionInformation) {
  73. versionDonutGraph.addPlotter(new Metrics.Plotter(version) {
  74. @Override
  75. public int getValue() {
  76. return 1;
  77. }
  78. });
  79. }
  80. // Official v Custom build Graph
  81. Graph officialGraph = metrics.createGraph("Built by official ci");
  82. if (isOfficialBuild) {
  83. officialGraph.addPlotter(new Metrics.Plotter("Yes") {
  84. @Override
  85. public int getValue() {
  86. return 1;
  87. }
  88. });
  89. }
  90. else {
  91. officialGraph.addPlotter(new Metrics.Plotter("No") {
  92. @Override
  93. public int getValue() {
  94. return 1;
  95. }
  96. });
  97. }
  98. // Chunkmeta enabled Graph
  99. Graph chunkmetaGraph = metrics.createGraph("Uses Chunkmeta");
  100. if (HiddenConfig.getInstance().getChunkletsEnabled()) {
  101. chunkmetaGraph.addPlotter(new Metrics.Plotter("Yes") {
  102. @Override
  103. public int getValue() {
  104. return 1;
  105. }
  106. });
  107. }
  108. else {
  109. chunkmetaGraph.addPlotter(new Metrics.Plotter("No") {
  110. @Override
  111. public int getValue() {
  112. return 1;
  113. }
  114. });
  115. }
  116. // Storage method Graph
  117. Graph storageGraph = metrics.createGraph("Storage method");
  118. if (Config.getInstance().getUseMySQL()) {
  119. storageGraph.addPlotter(new Metrics.Plotter("SQL") {
  120. @Override
  121. public int getValue() {
  122. return 1;
  123. }
  124. });
  125. }
  126. else {
  127. storageGraph.addPlotter(new Metrics.Plotter("Flatfile") {
  128. @Override
  129. public int getValue() {
  130. return 1;
  131. }
  132. });
  133. }
  134. // Locale Graph
  135. Graph localeGraph = metrics.createGraph("Locale");
  136. localeGraph.addPlotter(new Metrics.Plotter(LocaleLoader.getCurrentLocale().getDisplayLanguage(Locale.US)) {
  137. @Override
  138. public int getValue() {
  139. return 1;
  140. }
  141. });
  142. // GlobalMultiplier Graph
  143. Graph globalMultiplierGraph = metrics.createGraph("Global Multiplier Graph");
  144. globalMultiplierGraph.addPlotter(new Metrics.Plotter(Config.getInstance().getExperienceGainsGlobalMultiplier() + "") {
  145. @Override
  146. public int getValue() {
  147. return 1;
  148. }
  149. });
  150. // GlobalCurveModifier Graph
  151. Graph globalCurveModifierGraph = metrics.createGraph("Global Curve Modifier Graph");
  152. globalCurveModifierGraph.addPlotter(new Metrics.Plotter(Config.getInstance().getFormulaMultiplierCurve() + "") {
  153. @Override
  154. public int getValue() {
  155. return 1;
  156. }
  157. });
  158. emetrics.startMetrics();
  159. }
  160. catch (IOException e) {
  161. mcMMO.p.getLogger().warning("Failed to submit stats.");
  162. }
  163. }
  164. }
  165. }