Package org.apache.accumulo.test.metrics
Class MetricsFileTailer
- java.lang.Object
-
- org.apache.accumulo.test.metrics.MetricsFileTailer
-
- All Implemented Interfaces:
AutoCloseable
public class MetricsFileTailer extends Object implements AutoCloseable
This class allows testing of the publishing to the hadoop metrics system by processing a file for metric records (written as a line.) The file should be configured using the hadoop metrics properties as a file based sink with the prefix that is provided on instantiation of the instance. This class will simulate tail-ing a file and is intended to be run in a separate thread. When the underlying file has data written, the value returned by getLastUpdate will change, and the last line can be retrieved with getLast().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MetricsFileTailer.LineUpdate
-
Constructor Summary
Constructors Constructor Description MetricsFileTailer(String metricsPrefix)
Create an instance that will tail a metrics file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
String
getLast()
Get the last line seen in the file.long
getLastUpdate()
Creates a marker value that increases each time a new line is detected.Map<String,String>
parseLine(String prefix)
The hadoop metrics file sink published records as a line with comma separated key=value pairs.void
startDaemonThread()
MetricsFileTailer.LineUpdate
waitForUpdate(long prevUpdate, int maxAttempts, long delay)
-
-
-
Constructor Detail
-
MetricsFileTailer
public MetricsFileTailer(String metricsPrefix)
Create an instance that will tail a metrics file. The filename / path is determined by the hadoop-metrics-accumulo.properties sink configuration for the metrics prefix that is provided.- Parameters:
metricsPrefix
- the prefix in the metrics configuration.
-
-
Method Detail
-
getLastUpdate
public long getLastUpdate()
Creates a marker value that increases each time a new line is detected. Clients can use this to determine if a call to getLast() will return a new value. However, this value is NOT a timestamp and should not be interpreted as such. Furthermore, it does not indicate that the metrics being reported have changed, only that a new metrics poll took place and was written to the file. So, if clients need to observe new metrics from a new event, they need to parse the line themselves to look for changed metrics values.- Returns:
- a marker value set when a new line is available.
-
getLast
public String getLast()
Get the last line seen in the file.- Returns:
- the last line from the file.
-
parseLine
public Map<String,String> parseLine(String prefix)
The hadoop metrics file sink published records as a line with comma separated key=value pairs. This method parses the line and extracts the key, value pair from metrics that start with an optional prefix and returns them in a sort map. If the prefix is null or empty, all keys are accepted.- Parameters:
prefix
- optional filter - include metrics that start with provided value..- Returns:
- a map of the metrics that start with AccGc
-
startDaemonThread
public void startDaemonThread()
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
waitForUpdate
public MetricsFileTailer.LineUpdate waitForUpdate(long prevUpdate, int maxAttempts, long delay)
-
-