Add data directory availability/latency metrics
Add metrics that check if the data directory is available and report
the latency of file operations on the data directory.
*/
package com.linkedin.pinot.controller;
+import com.google.common.primitives.Longs;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
import org.apache.helix.PreConnectCallback;
import org.restlet.Application;
import org.restlet.Component;
@@ -47,6 +52,9 @@ import com.yammer.metrics.core.MetricsRegistry;
public class ControllerStarter {
private static final Logger LOGGER = LoggerFactory.getLogger(ControllerStarter.class);
private static final String MetricsRegistryName = "pinot.controller.metrics";
+ private static final Long DATA_DIRECTORY_MISSING_VALUE = 1000000L;
+ private static final Long DATA_DIRECTORY_EXCEPTION_VALUE = 1100000L;
+
private final ControllerConf config;
private final Component component;
@@ -148,6 +156,40 @@ public class ControllerStarter {
}
});
+ controllerMetrics.addCallbackGauge("dataDir.exists", new Callable<Long>() {
+ @Override
+ public Long call() throws Exception {
+ return new File(config.getDataDir()).exists() ? 1L : 0L;
+ }
+ });
+
+ controllerMetrics.addCallbackGauge("dataDir.fileOpLatencyMs", new Callable<Long>() {
+ @Override
+ public Long call() throws Exception {
+ File dataDir = new File(config.getDataDir());
+
+ if (dataDir.exists()) {
+ try {
+ long startTime = System.currentTimeMillis();
+ final File testFile = new File(dataDir, config.getControllerHost());
+ FileOutputStream outputStream = new FileOutputStream(testFile, false);
+ outputStream.write(Longs.toByteArray(System.currentTimeMillis()));
+ outputStream.flush();
+ outputStream.close();
+ FileUtils.deleteQuietly(testFile);
+ long endTime = System.currentTimeMillis();
+
+ return endTime - startTime;
+ } catch (IOException e) {
+ LOGGER.warn("Caught exception while checking the data directory operation latency", e);
+ return DATA_DIRECTORY_EXCEPTION_VALUE;
+ }
+ } else {
+ return DATA_DIRECTORY_MISSING_VALUE;
+ }
+ }
+ });
+
helixResourceManager.getHelixZkManager().addPreConnectCallback(new PreConnectCallback() {
@Override
public void onPreConnect() {
