From d4b4782943f79787d0931b24b839e9cc99e81c20 Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Wed, 9 Aug 2017 16:07:35 +0200 Subject: [PATCH] SOLR-11061: Add a spins metric for data directory paths. --- solr/CHANGES.txt | 2 ++ .../org/apache/solr/core/CoreContainer.java | 18 ++++++++++++++++++ .../java/org/apache/solr/core/SolrCore.java | 9 +++++++++ .../metrics/SolrMetricsIntegrationTest.java | 12 ++++++++++++ 4 files changed, 41 insertions(+) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 9e401c26352..6962e2f2263 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -134,6 +134,8 @@ Other Changes * SOLR-11090: Add Replica.getProperty accessor. (Christine Poerschke) +* SOLR-11061: Add a spins metric for data directory paths. (ab) + ================== 7.0.0 ================== Versions of Major Components diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.java index 6013b284ca5..bf24db86548 100644 --- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java +++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java @@ -568,12 +568,30 @@ public class CoreContainer { true, "usableSpace", SolrInfoBean.Category.CONTAINER.toString(), "fs"); metricManager.registerGauge(null, registryName, () -> dataHome.toAbsolutePath().toString(), true, "path", SolrInfoBean.Category.CONTAINER.toString(), "fs"); + metricManager.registerGauge(null, registryName, () -> { + try { + return org.apache.lucene.util.IOUtils.spins(dataHome.toAbsolutePath()); + } catch (IOException e) { + // default to spinning + return true; + } + }, + true, "spins", SolrInfoBean.Category.CONTAINER.toString(), "fs"); metricManager.registerGauge(null, registryName, () -> cfg.getCoreRootDirectory().toFile().getTotalSpace(), true, "totalSpace", SolrInfoBean.Category.CONTAINER.toString(), "fs", "coreRoot"); metricManager.registerGauge(null, registryName, () -> cfg.getCoreRootDirectory().toFile().getUsableSpace(), true, "usableSpace", SolrInfoBean.Category.CONTAINER.toString(), "fs", "coreRoot"); metricManager.registerGauge(null, registryName, () -> cfg.getCoreRootDirectory().toAbsolutePath().toString(), true, "path", SolrInfoBean.Category.CONTAINER.toString(), "fs", "coreRoot"); + metricManager.registerGauge(null, registryName, () -> { + try { + return org.apache.lucene.util.IOUtils.spins(cfg.getCoreRootDirectory().toAbsolutePath()); + } catch (IOException e) { + // default to spinning + return true; + } + }, + true, "spins", SolrInfoBean.Category.CONTAINER.toString(), "fs", "coreRoot"); // add version information metricManager.registerGauge(null, registryName, () -> this.getClass().getPackage().getSpecificationVersion(), true, "specification", SolrInfoBean.Category.CONTAINER.toString(), "version"); diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java index cc6a9c28e43..e8f1358fab0 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -1162,6 +1162,15 @@ public final class SolrCore implements SolrInfoBean, SolrMetricProducer, Closeab File dataDirFile = dataDirPath.toFile(); manager.registerGauge(this, registry, () -> dataDirFile.getTotalSpace(), true, "totalSpace", Category.CORE.toString(), "fs"); manager.registerGauge(this, registry, () -> dataDirFile.getUsableSpace(), true, "usableSpace", Category.CORE.toString(), "fs"); + manager.registerGauge(this, registry, () -> dataDirPath.toAbsolutePath().toString(), true, "fs", "dataDir"); + manager.registerGauge(this, registry, () -> { + try { + return org.apache.lucene.util.IOUtils.spins(dataDirPath.toAbsolutePath()); + } catch (IOException e) { + // default to spinning + return true; + } + }, true, "spins", Category.CORE.toString(), "fs", "dataDir"); } private void checkVersionFieldExistsInSchema(IndexSchema schema, CoreDescriptor coreDescriptor) { diff --git a/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java b/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java index 1a8eda80045..1184402cd91 100644 --- a/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java +++ b/solr/core/src/test/org/apache/solr/metrics/SolrMetricsIntegrationTest.java @@ -27,6 +27,7 @@ import com.codahale.metrics.Metric; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import org.apache.commons.io.FileUtils; +import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.TestUtil; import org.apache.solr.SolrTestCaseJ4; import org.apache.solr.core.CoreContainer; @@ -166,12 +167,23 @@ public class SolrMetricsIntegrationTest extends SolrTestCaseJ4 { assertTrue(metrics.containsKey("CONTAINER.fs.totalSpace")); assertTrue(metrics.containsKey("CONTAINER.fs.usableSpace")); assertTrue(metrics.containsKey("CONTAINER.fs.path")); + assertTrue(metrics.containsKey("CONTAINER.fs.spins")); assertTrue(metrics.containsKey("CONTAINER.fs.coreRoot.totalSpace")); assertTrue(metrics.containsKey("CONTAINER.fs.coreRoot.usableSpace")); assertTrue(metrics.containsKey("CONTAINER.fs.coreRoot.path")); + assertTrue(metrics.containsKey("CONTAINER.fs.coreRoot.spins")); assertTrue(metrics.containsKey("CONTAINER.version.specification")); assertTrue(metrics.containsKey("CONTAINER.version.implementation")); Gauge g = (Gauge)metrics.get("CONTAINER.fs.path"); assertEquals(g.getValue(), cc.getResourceLoader().getInstancePath().toAbsolutePath().toString()); + boolean spins = IOUtils.spins(cc.getCoreRootDirectory()); + g = (Gauge)metrics.get("CONTAINER.fs.coreRoot.spins"); + g = (Gauge)metrics.get("CONTAINER.fs.coreRoot.spins"); + assertEquals(spins, g.getValue()); + if (cc.getConfig().getSolrDataHome() != null) { + spins = IOUtils.spins(cc.getConfig().getSolrDataHome()); + g = (Gauge)metrics.get("CONTAINER.fs.spins"); + assertEquals(spins, g.getValue()); + } } }