Skip to content

Commit

Permalink
Merge pull request #124 from xenit-eu/ALFREDOPS-777
Browse files Browse the repository at this point in the history
Add solr backup metrics
  • Loading branch information
anghelutar authored Sep 7, 2021
2 parents 6879e55 + 2f9c10e commit b197e6f
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Version template:

### Added
* Support more flexible Graphite step duration configuration
* Add metrics for solr backup [#124]

[#124]: https://github.com/xenit-eu/alfred-telemetry/pull/124


## [0.7.1] - 2021-07-12
Expand Down
16 changes: 15 additions & 1 deletion alfred-telemetry-solr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Enabling / disabling metrics can be done via environment variables:
|METRICS_SOLR_FTS_ENABLED | true |
|METRICS_SOLR_TRACKER_ENABLED | true |
|METRICS_SOLR_JMX_ENABLED | true |
|METRICS_SOLR_BACKUP_ENABLED | true |
|METRICS_TOMCAT_ENABLED | false |
|METRICS_TOMCAT_JMX_ENABLED | true |
|METRICS_JETTY_ENABLED | false |
Expand Down Expand Up @@ -139,7 +140,6 @@ At the moment following metrics are included, for each core tracked by solr:
| alfresco.states{core=\<core\>} |



### Solr FTS metrics

At the moment following metrics are included, for each core tracked by solr:
Expand Down Expand Up @@ -195,6 +195,20 @@ At the moment following metrics are included, only for core "alfresco" for \<typ
| solr.alfresco.numDocs{type="searcher"} |
| solr.alfresco.indexVersion{type="searcher"} |


### Solr backup metrics

At the moment following metrics are included, for each core tracked by solr:

| Name |
| ---------------------------------------|
| snapshoot.start{core=\<core\>} |
| snapshoot.completed{core=\<core\>} |
| snapshoot.status{core=\<core\>} |
| snapshoot.file.count{core=\<core\>} |

In case no snapshoot has been taken yet, metrics return -1. Metrics reset at restart / reload of core.

### Tomcat jmx metrics

At the moment following metrics are included:
Expand Down
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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public SolrMetrics(AlfrescoCoreAdminHandler coreAdminHandler, MBeanServer mBeanS

@Override
public void bindTo(MeterRegistry registry) {
if(Util.isEnabled("METRICS_SOLR_BACKUP_ENABLED")) {
new SolrSnapshootMetrics(coreAdminHandler).bindTo(registry);
}
if(Util.isEnabled("METRICS_SOLR_CORESTATS_ENABLED")) {
new SolrCoreStatsMetrics(coreAdminHandler).bindTo(registry);
}
Expand Down
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();
}
}

0 comments on commit b197e6f

Please sign in to comment.