Skip to content

Commit

Permalink
Started working on healthchecks candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
Matus Kasak committed Dec 16, 2024
1 parent 56b4862 commit b1f0978
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health;

public class AdditionalInfoCheck extends Check {

@Override
protected String run(ReportInfo ri) {
String output = "";

output += String.format(
"JVM uptime: %s\n", Info.get_jvm_uptime());
output += String.format(
"Testing build time: %s\n", Info.get_build_time());

output += "\n\n";

output += "Example url 1: https://dev-5.pc:8443/repository/home\n";
output += "Example url 2: https://dev-5.pc:85/repository/home\n";
return output;
}
}
67 changes: 67 additions & 0 deletions dspace-api/src/main/java/org/dspace/health/Info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health;

import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
//import src.main.java.org.dspace.xoai.services.impl.config.DSpaceConfigurationService;


import java.io.FileInputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Scanner;

public class Info {

protected static final ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();

final static public String get_proc_uptime() {
String uptime = "unknown";
try {
//works only on linux
uptime = new Scanner(new FileInputStream("/proc/uptime")).next();
System.out.println("\nUPTIME " + uptime);
float fuptime = Float.parseFloat( uptime );
int seconds = (int) (fuptime % 60);
int minutes = (int) ((fuptime / 60) % 60);
int hours = (int) ((fuptime / (60 * 60)) % 24);
int days = (int) ((fuptime / (60 * 60 * 24)) );
return Integer.toString( days ) + "d " +
Integer.toString( hours ) + "h:" +
Integer.toString( minutes ) + "m." +
Integer.toString( seconds );
} catch (Exception e) {
return uptime;
}
}

final static public String get_jvm_uptime() {
RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
long milliseconds = mxBean.getUptime();
int seconds = (int) (milliseconds / 1000) % 60 ;
int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);
int days = (int) ((milliseconds / (1000 * 60 * 60 * 24)));

return Integer.toString( days ) + "d " +
Integer.toString( hours ) + "h:" +
Integer.toString( minutes ) + "m." +
Integer.toString( seconds );
}

final static public String get_build_time() {
//springacka do nespring triedy, chceme autowired, component
String buildTime = configurationService.getProperty("testing-config");
if (buildTime != null && !buildTime.equals("")) {
return buildTime;
}
return "unknown";
}
}
31 changes: 31 additions & 0 deletions dspace-api/src/main/java/org/dspace/health/OAIPMHCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health;

import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;

public class OAIPMHCheck extends Check {
protected static final ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();

@Override
protected String run(ReportInfo ri) {
String output = "";
String dspace_dir = configurationService.getProperty("dspace.dir");
System.out.println("Dspace dir " + dspace_dir);
String dspace_url = configurationService.getProperty("dspace.server.url");
System.out.println("Dspace url " + dspace_url);
String oaiurl = dspace_url + "/oai/request";
System.out.println("Dspace oai " + oaiurl);
output += String.format("Trying [%s]\n", oaiurl);
//output += IOUtils.run(new File(dspace_dir + "/bin/"), new String[]{
// "python", "./validators/oai_pmh/validate.py", oaiurl});
return output;
}
}
15 changes: 15 additions & 0 deletions dspace-api/src/main/java/org/dspace/health/PIDCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health;

public class PIDCheck extends Check {
@Override
protected String run(ReportInfo ri) {
return "";
}
}
15 changes: 15 additions & 0 deletions dspace-api/src/main/java/org/dspace/health/ShibbolethCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health;

public class ShibbolethCheck extends Check {
@Override
protected String run(ReportInfo ri) {
return "";
}
}
2 changes: 2 additions & 0 deletions dspace/config/clarin-dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,5 @@ autocomplete.custom.separator.solr-dataProvider_ac = \\|\\|\\|
autocomplete.custom.separator.solr-dctype_ac = \\|\\|\\|
autocomplete.custom.separator.solr-author_ac = \\|\\|\\|
autocomplete.custom.allowed = solr-author_ac,solr-publisher_ac,solr-dataProvider_ac,solr-dctype_ac,solr-subject_ac,solr-handle_title_ac,json_static-iso_langs.json

testing-config = TESTINGCONFIG
12 changes: 10 additions & 2 deletions dspace/config/modules/healthcheck.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ healthcheck.checks = General Information,\
Checksum,\
Item summary,\
User summary,\
Log Analyser Check
Log Analyser Check,\
Additional Information,\
OAI-PMH validation,\
PID check,\
Shibboleth Check

plugin.named.org.dspace.health.Check = \
org.dspace.health.InfoCheck = General Information,\
org.dspace.health.ChecksumCheck = Checksum,\
org.dspace.health.EmbargoCheck = Embargo items (Pre-3.0),\
org.dspace.health.ItemCheck = Item summary,\
org.dspace.health.UserCheck = User summary,\
org.dspace.health.LogAnalyserCheck = Log Analyser Check
org.dspace.health.LogAnalyserCheck = Log Analyser Check,\
org.dspace.health.AdditionalInfoCheck = Additional Information,\
org.dspace.health.OAIPMHCheck = OAI-PMH validation,\
org.dspace.health.PIDCheck = PID Check,\
org.dspace.health.ShibbolethCheck = Shibboleth Check

# report from the last N days (where dates are applicable)
healthcheck.last_n_days = 7

0 comments on commit b1f0978

Please sign in to comment.