metrics change

This commit is contained in:
Diamantis Tziotzios 2023-08-03 10:28:18 +03:00
parent 09d6528f8f
commit 903026e2c2
6 changed files with 2 additions and 35 deletions

View File

@ -22,22 +22,15 @@ public class AboutController {
private Environment environment;
private MaterialManager materialManager;
private final MetricsManager metricsManager;
@Autowired
public AboutController(Environment environment, MaterialManager materialManager, MetricsManager metricsManager) {
this.environment = environment;
this.materialManager = materialManager;
this.metricsManager = metricsManager;
}
@RequestMapping(path = "{lang}", method = RequestMethod.GET )
public ResponseEntity<byte[]> getAbout(@PathVariable(name = "lang") String lang) throws IOException {
// long files = 0;
// try (Stream<Path> paths = Files.list(Paths.get(Objects.requireNonNull(this.environment.getProperty("about.path"))))) {
// files = paths.count();
// }
// metricsManager.calculateValue(MetricNames.LANGUAGES, (int) files, null);
try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty("about.path"))))) {
return this.materialManager.getResponseEntity(lang, paths);
}

View File

@ -21,22 +21,15 @@ public class FaqController {
private Environment environment;
private MaterialManager materialManager;
private final MetricsManager metricsManager;
@Autowired
public FaqController(Environment environment, MaterialManager materialManager, MetricsManager metricsManager) {
this.environment = environment;
this.materialManager = materialManager;
this.metricsManager = metricsManager;
}
@RequestMapping(path = "{lang}", method = RequestMethod.GET )
public ResponseEntity<byte[]> getFaq(@PathVariable(name = "lang") String lang) throws IOException {
// long files = 0;
// try (Stream<Path> paths = Files.list(Paths.get(Objects.requireNonNull(this.environment.getProperty("faq.path"))))) {
// files = paths.count();
// }
// metricsManager.calculateValue(MetricNames.LANGUAGES, (int) files, null);
try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty("faq.path"))))) {
return this.materialManager.getResponseEntity(lang, paths);
}

View File

@ -21,22 +21,15 @@ public class GlossaryController {
private Environment environment;
private MaterialManager materialManager;
private final MetricsManager metricsManager;
@Autowired
public GlossaryController(Environment environment, MaterialManager materialManager, MetricsManager metricsManager) {
this.environment = environment;
this.materialManager = materialManager;
this.metricsManager = metricsManager;
}
@RequestMapping(path = "{lang}", method = RequestMethod.GET )
public ResponseEntity<byte[]> getGlossary(@PathVariable(name = "lang") String lang) throws IOException {
// long files = 0;
// try (Stream<Path> paths = Files.list(Paths.get(Objects.requireNonNull(this.environment.getProperty("glossary.path"))))) {
// files = paths.count();
// }
// metricsManager.calculateValue(MetricNames.LANGUAGES, (int) files, null);
try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty("glossary.path"))))) {
return this.materialManager.getResponseEntity(lang, paths);
}

View File

@ -21,22 +21,15 @@ public class TermsOfServiceController {
private Environment environment;
private MaterialManager materialManager;
private final MetricsManager metricsManager;
@Autowired
public TermsOfServiceController(Environment environment, MaterialManager materialManager, MetricsManager metricsManager) {
this.environment = environment;
this.materialManager = materialManager;
this.metricsManager = metricsManager;
}
@RequestMapping(path = "{lang}", method = RequestMethod.GET )
public ResponseEntity<byte[]> getTermsOfService(@PathVariable(name = "lang") String lang) throws IOException {
// long files = 0;
// try (Stream<Path> paths = Files.list(Paths.get(Objects.requireNonNull(this.environment.getProperty("termsofservice.path"))))) {
// files = paths.count();
// }
// metricsManager.calculateValue(MetricNames.LANGUAGES, (int) files, null);
try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty("termsofservice.path"))))) {
return this.materialManager.getResponseEntity(lang, paths);
}

View File

@ -34,22 +34,15 @@ public class UserGuideController {
private Environment environment;
private MaterialManager materialManager;
private final MetricsManager metricsManager;
@Autowired
public UserGuideController(Environment environment, MaterialManager materialManager, MetricsManager metricsManager) {
this.environment = environment;
this.materialManager = materialManager;
this.metricsManager = metricsManager;
}
@RequestMapping(path = "{lang}", method = RequestMethod.GET )
public ResponseEntity<byte[]> getUserGuide(@PathVariable(name = "lang") String lang) throws IOException {
long files = 0;
try (Stream<Path> paths = Files.list(Paths.get(Objects.requireNonNull(this.environment.getProperty("userguide.path"))))) {
files = paths.count();
}
metricsManager.calculateValue(MetricNames.LANGUAGES, (int) files, null);
try (Stream<Path> paths = Files.walk(Paths.get(Objects.requireNonNull(this.environment.getProperty("userguide.path"))))) {
return this.materialManager.getResponseEntity(lang, paths);
}

View File

@ -180,6 +180,8 @@ public class MetricsManager {
try (Stream<Path> paths = Files.list(Paths.get(Objects.requireNonNull(this.environment.getProperty("userguide.path"))))) {
long files = paths.count();
calculateValue(MetricNames.LANGUAGES, (int) files, null);
} catch (Exception e) {
logger.error("Could not calculate languages.");
}
calculateValue(MetricNames.INSTALLATIONS, 1, null);