use of alluxio.metrics.MetricKey in project alluxio by Alluxio.
the class UfsFallbackBlockWriteHandler method createUfsBlock.
/**
* Creates a UFS block and initialize it with bytes read from block store.
*
* @param context context of this request
*/
private void createUfsBlock(BlockWriteRequestContext context) throws Exception {
BlockWriteRequest request = context.getRequest();
Protocol.CreateUfsBlockOptions createUfsBlockOptions = request.getCreateUfsBlockOptions();
UfsManager.UfsClient ufsClient = mUfsManager.get(createUfsBlockOptions.getMountId());
alluxio.resource.CloseableResource<UnderFileSystem> ufsResource = ufsClient.acquireUfsResource();
context.setUfsResource(ufsResource);
String ufsString = MetricsSystem.escape(ufsClient.getUfsMountPointUri());
String ufsPath = BlockUtils.getUfsBlockPath(ufsClient, request.getId());
UnderFileSystem ufs = ufsResource.get();
// Set the atomic flag to be true to ensure only the creation of this file is atomic on close.
OutputStream ufsOutputStream = ufs.createNonexistingFile(ufsPath, CreateOptions.defaults(ServerConfiguration.global()).setEnsureAtomic(true).setCreateParent(true));
context.setOutputStream(ufsOutputStream);
context.setUfsPath(ufsPath);
MetricKey counterKey = MetricKey.WORKER_BYTES_WRITTEN_UFS;
MetricKey meterKey = MetricKey.WORKER_BYTES_WRITTEN_UFS_THROUGHPUT;
context.setCounter(MetricsSystem.counterWithTags(counterKey.getName(), counterKey.isClusterAggregated(), MetricInfo.TAG_UFS, ufsString));
context.setMeter(MetricsSystem.meterWithTags(meterKey.getName(), meterKey.isClusterAggregated(), MetricInfo.TAG_UFS, ufsString));
}
use of alluxio.metrics.MetricKey in project alluxio by Alluxio.
the class MetricsDocGenerator method generate.
/**
* Writes the supported files for metrics system docs.
*/
public static void generate() throws IOException {
// Gets and sorts the metric keys
List<MetricKey> defaultKeys = new ArrayList<>(MetricKey.allMetricKeys());
Collections.sort(defaultKeys);
String homeDir = new InstancedConfiguration(ConfigurationUtils.defaults()).getString(PropertyKey.HOME);
// Map from metric key prefix to metric category
Map<String, String> metricTypeMap = new HashMap<>();
for (MetricsSystem.InstanceType type : MetricsSystem.InstanceType.values()) {
String typeStr = type.toString();
String category = typeStr.toLowerCase();
metricTypeMap.put(typeStr, category);
}
try (Closer closer = Closer.create()) {
Map<FileWriterKey, FileWriter> fileWriterMap = new HashMap<>();
String csvFolder = PathUtils.concatPath(homeDir, CSV_FILE_DIR);
String ymlFolder = PathUtils.concatPath(homeDir, YML_FILE_DIR);
FileWriter csvFileWriter;
FileWriter ymlFileWriter;
for (String category : CATEGORIES) {
csvFileWriter = new FileWriter(PathUtils.concatPath(csvFolder, category + "-metrics." + CSV_SUFFIX));
csvFileWriter.append(CSV_FILE_HEADER + "\n");
ymlFileWriter = new FileWriter(PathUtils.concatPath(ymlFolder, category + "-metrics." + YML_SUFFIX));
fileWriterMap.put(new FileWriterKey(category, CSV_SUFFIX), csvFileWriter);
fileWriterMap.put(new FileWriterKey(category, YML_SUFFIX), ymlFileWriter);
// register file writer
closer.register(csvFileWriter);
closer.register(ymlFileWriter);
}
for (MetricKey metricKey : defaultKeys) {
String key = metricKey.toString();
String[] components = key.split("\\.");
if (components.length < 2) {
throw new IOException(String.format("The given metric key %s doesn't have two or more components", key));
}
if (!metricTypeMap.containsKey(components[0])) {
throw new IOException(String.format("The metric key %s starts with invalid instance type %s", key, components[0]));
}
csvFileWriter = fileWriterMap.get(new FileWriterKey(metricTypeMap.get(components[0]), CSV_SUFFIX));
ymlFileWriter = fileWriterMap.get(new FileWriterKey(metricTypeMap.get(components[0]), YML_SUFFIX));
csvFileWriter.append(String.format("%s,%s%n", key, metricKey.getMetricType().toString()));
ymlFileWriter.append(String.format("%s:%n '%s'%n", key, StringEscapeUtils.escapeHtml4(metricKey.getDescription().replace("'", "''"))));
}
}
LOG.info("Metrics CSV/YML files were created successfully.");
}
use of alluxio.metrics.MetricKey in project alluxio by Alluxio.
the class UfsFileWriteHandler method createUfsFile.
private void createUfsFile(UfsFileWriteRequestContext context) throws IOException {
UfsFileWriteRequest request = context.getRequest();
Preconditions.checkState(request != null);
Protocol.CreateUfsFileOptions createUfsFileOptions = request.getCreateUfsFileOptions();
UfsManager.UfsClient ufsClient = mUfsManager.get(createUfsFileOptions.getMountId());
CloseableResource<UnderFileSystem> ufsResource = ufsClient.acquireUfsResource();
context.setUfsResource(ufsResource);
UnderFileSystem ufs = ufsResource.get();
CreateOptions createOptions = CreateOptions.defaults(ServerConfiguration.global()).setCreateParent(true).setOwner(createUfsFileOptions.getOwner()).setGroup(createUfsFileOptions.getGroup()).setMode(new Mode((short) createUfsFileOptions.getMode()));
if (createUfsFileOptions.hasAcl()) {
// This acl information will be ignored by all but HDFS implementations
createOptions.setAcl(ProtoUtils.fromProto(createUfsFileOptions.getAcl()));
}
context.setOutputStream(ufs.createNonexistingFile(request.getUfsPath(), createOptions));
context.setCreateOptions(createOptions);
String ufsString = MetricsSystem.escape(ufsClient.getUfsMountPointUri());
MetricKey counterKey = MetricKey.WORKER_BYTES_WRITTEN_UFS;
MetricKey meterKey = MetricKey.WORKER_BYTES_WRITTEN_UFS_THROUGHPUT;
context.setCounter(MetricsSystem.counterWithTags(counterKey.getName(), counterKey.isClusterAggregated(), MetricInfo.TAG_UFS, ufsString));
context.setMeter(MetricsSystem.meterWithTags(meterKey.getName(), meterKey.isClusterAggregated(), MetricInfo.TAG_UFS, ufsString));
}
Aggregations