001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.fs; 019 020import org.apache.hadoop.classification.InterfaceAudience; 021 022import java.util.Iterator; 023 024/** 025 * StorageStatistics contains statistics data for a FileSystem or FileContext 026 * instance. 027 */ 028@InterfaceAudience.Public 029public abstract class StorageStatistics { 030 031 /** 032 * These are common statistic names. 033 * 034 * The following names are considered general and preserved across different 035 * StorageStatistics classes. When implementing a new StorageStatistics, it is 036 * highly recommended to use the common statistic names. 037 * 038 * When adding new common statistic name constants, please make them unique. 039 * By convention, they are implicitly unique: 040 * - the name of the constants are uppercase, words separated by underscores. 041 * - the value of the constants are lowercase of the constant names. 042 */ 043 public interface CommonStatisticNames { 044 // The following names are for file system operation invocations 045 String OP_APPEND = "op_append"; 046 String OP_COPY_FROM_LOCAL_FILE = "op_copy_from_local_file"; 047 String OP_CREATE = "op_create"; 048 String OP_CREATE_NON_RECURSIVE = "op_create_non_recursive"; 049 String OP_DELETE = "op_delete"; 050 String OP_EXISTS = "op_exists"; 051 String OP_GET_CONTENT_SUMMARY = "op_get_content_summary"; 052 String OP_GET_FILE_CHECKSUM = "op_get_file_checksum"; 053 String OP_GET_FILE_STATUS = "op_get_file_status"; 054 String OP_GET_STATUS = "op_get_status"; 055 String OP_GLOB_STATUS = "op_glob_status"; 056 String OP_IS_FILE = "op_is_file"; 057 String OP_IS_DIRECTORY = "op_is_directory"; 058 String OP_LIST_FILES = "op_list_files"; 059 String OP_LIST_LOCATED_STATUS = "op_list_located_status"; 060 String OP_LIST_STATUS = "op_list_status"; 061 String OP_MKDIRS = "op_mkdirs"; 062 String OP_MODIFY_ACL_ENTRIES = "op_modify_acl_entries"; 063 String OP_OPEN = "op_open"; 064 String OP_REMOVE_ACL = "op_remove_acl"; 065 String OP_REMOVE_ACL_ENTRIES = "op_remove_acl_entries"; 066 String OP_REMOVE_DEFAULT_ACL = "op_remove_default_acl"; 067 String OP_RENAME = "op_rename"; 068 String OP_SET_ACL = "op_set_acl"; 069 String OP_SET_OWNER = "op_set_owner"; 070 String OP_SET_PERMISSION = "op_set_permission"; 071 String OP_SET_TIMES = "op_set_times"; 072 String OP_TRUNCATE = "op_truncate"; 073 } 074 075 /** 076 * A 64-bit storage statistic. 077 */ 078 public static class LongStatistic { 079 private final String name; 080 private final long value; 081 082 public LongStatistic(String name, long value) { 083 this.name = name; 084 this.value = value; 085 } 086 087 /** 088 * @return The name of this statistic. 089 */ 090 public String getName() { 091 return name; 092 } 093 094 /** 095 * @return The value of this statistic. 096 */ 097 public long getValue() { 098 return value; 099 } 100 } 101 102 private final String name; 103 104 public StorageStatistics(String name) { 105 this.name = name; 106 } 107 108 /** 109 * Get the name of this StorageStatistics object. 110 */ 111 public String getName() { 112 return name; 113 } 114 115 /** 116 * @return the associated file system scheme if this is scheme specific, 117 * else return null. 118 */ 119 public String getScheme() { 120 return null; 121 } 122 123 /** 124 * Get an iterator over all the currently tracked long statistics. 125 * 126 * The values returned will depend on the type of FileSystem or FileContext 127 * object. The values do not necessarily reflect a snapshot in time. 128 */ 129 public abstract Iterator<LongStatistic> getLongStatistics(); 130 131 /** 132 * Get the value of a statistic. 133 * 134 * @return null if the statistic is not being tracked or is not a 135 * long statistic. The value of the statistic, otherwise. 136 */ 137 public abstract Long getLong(String key); 138 139 /** 140 * Return true if a statistic is being tracked. 141 * 142 * @return True only if the statistic is being tracked. 143 */ 144 public abstract boolean isTracked(String key); 145 146 /** 147 * Reset all the statistic data. 148 */ 149 public abstract void reset(); 150}