-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from xenit-eu/ALFREDOPS-777
Add solr backup metrics
- Loading branch information
Showing
5 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
ext { | ||
solrVersion = '6.6.5' | ||
assVersion = '2.0.1' | ||
solrBaseImage = 'hub.xenit.eu/public/alfresco-solr6-xenit:2.0.1' | ||
solrBaseImage = 'hub.xenit.eu/public/alfresco-solr6:2.0.1' | ||
solrFlavor = 'solr6' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
.../src/main/java/eu/xenit/alfred/telemetry/solr/monitoring/binder/SolrSnapshootMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package eu.xenit.alfred.telemetry.solr.monitoring.binder; | ||
|
||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tags; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
import java.lang.reflect.Field; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Map; | ||
import java.util.TimeZone; | ||
import org.alfresco.solr.AlfrescoCoreAdminHandler; | ||
import org.apache.solr.common.util.NamedList; | ||
import org.apache.solr.core.SolrCore; | ||
import org.apache.solr.handler.ReplicationHandler; | ||
import org.apache.solr.request.SolrRequestHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SolrSnapshootMetrics implements MeterBinder { | ||
|
||
private AlfrescoCoreAdminHandler coreAdminHandler; | ||
private MeterRegistry registry; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(SolrSnapshootMetrics.class); | ||
private static final Map<String,String> statusMapping = Map.of( | ||
"success", "1", | ||
"failed", "0" | ||
); | ||
private SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'UTC' yyyy"); | ||
|
||
public SolrSnapshootMetrics(AlfrescoCoreAdminHandler coreAdminHandler) { | ||
this.coreAdminHandler = coreAdminHandler; | ||
formatter.setTimeZone(TimeZone.getTimeZone("UTC")); | ||
} | ||
|
||
private void registerSnapshootMetrics() { | ||
logger.info("Registering snapshoot metrics"); | ||
SolrCore core = coreAdminHandler.getCoreContainer().getCore("alfresco"); | ||
SolrRequestHandler handler = core.getRequestHandler(ReplicationHandler.PATH); | ||
ReplicationHandler replication = (ReplicationHandler) handler; | ||
Tags tags = Tags.of("core", core.getName()); | ||
Gauge.builder("snapshot.start", replication, x -> getValueFromReport(replication, "startTime")) | ||
.tags(tags) | ||
.register(registry); | ||
Gauge.builder("snapshot.completed", replication, x -> getValueFromReport(replication, "snapshotCompletedAt")) | ||
.tags(tags) | ||
.register(registry); | ||
Gauge.builder("snapshot.file.count", replication, x -> getValueFromReport(replication, "fileCount")) | ||
.tags(tags) | ||
.register(registry); | ||
Gauge.builder("snapshot.status", replication, x -> getValueFromReport(replication, "status")) | ||
.tags(tags) | ||
.register(registry); | ||
|
||
} | ||
|
||
private long getValueFromReport(ReplicationHandler replication, String key) { | ||
Field snapField = null; | ||
try { | ||
snapField = ReplicationHandler.class.getDeclaredField("snapShootDetails"); | ||
} catch (NoSuchFieldException e) { | ||
logger.error("No snapShootDetails field in the ReplicationHandler",e); | ||
return -1; | ||
} | ||
snapField.setAccessible(true); | ||
NamedList<?> snapValue = null; | ||
try { | ||
snapValue = (NamedList<?>) snapField.get(replication); | ||
} catch (IllegalAccessException e) { | ||
logger.info("No backup taken yet",e); | ||
} | ||
if(snapValue==null) | ||
return -1; | ||
|
||
Object value = snapValue.get(key); | ||
if(value instanceof Integer) | ||
return ((Integer)value).longValue(); | ||
if("status".equals(key)) | ||
return Long.parseLong(statusMapping.get(value)); | ||
if("startTime".equals(key) || "snapshotCompletedAt".equals(key)) { | ||
try { | ||
return formatter.parse((String)value).getTime(); | ||
} catch (ParseException e) { | ||
logger.error("Start time or completed time of snapshoot not in correct format",e); | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
|
||
@Override | ||
public void bindTo(MeterRegistry registry) { | ||
this.registry = registry; | ||
registerSnapshootMetrics(); | ||
} | ||
} |