18 #include <sys/types.h>
22 #include <boost/algorithm/string.hpp>
23 #include <boost/algorithm/string/join.hpp>
32 using boost::algorithm::is_any_of;
33 using boost::algorithm::split;
34 using boost::algorithm::token_compress_on;
35 using boost::algorithm::trim;
36 using boost::algorithm::trim_right_if;
54 ifstream partitions(
"/proc/partitions", ios::in);
55 while (partitions.good() && !partitions.eof()) {
57 getline(partitions, line);
60 vector<string> fields;
61 split(fields, line, is_any_of(
" "), token_compress_on);
62 if (fields.size() != 4)
continue;
63 string name = fields[3];
64 if (name ==
"name")
continue;
67 trim_right_if(name, is_any_of(
"0123456789"));
70 int major_dev_id = atoi(fields[0].c_str());
71 int minor_dev_id = atoi(fields[1].c_str());
72 dev_t dev = makedev(major_dev_id, minor_dev_id);
88 if (partitions.is_open()) partitions.close();
92 LOG(WARNING) <<
"Could not determine number of disks on this machine.";
98 for (
int i = 0; i <
disks_.size(); ++i) {
103 ss <<
"/sys/block/" <<
disks_[i].name <<
"/queue/rotational";
104 ifstream rotational(ss.str().c_str(), ios::in);
105 if (rotational.good()) {
107 getline(rotational, line);
108 if (line ==
"0")
disks_[i].is_rotational =
false;
110 if (rotational.is_open()) rotational.close();
130 stream <<
"Disk Info: " << endl;
131 stream <<
" Num disks " <<
num_disks() <<
": " << endl;
132 for (
int i = 0; i <
disks_.size(); ++i) {
133 stream <<
" " <<
disks_[i].name
134 <<
" (rotational=" << (
disks_[i].is_rotational ?
"true" :
"false") <<
")\n";
string path("/usr/lib/sasl2:/usr/lib64/sasl2:/usr/local/lib/sasl2:/usr/lib/x86_64-linux-gnu/sasl2")
static int num_disks()
Returns the number of (logical) disks on the system.
static void Init()
Initialize DiskInfo. Just be called before any other functions.
static std::vector< Disk > disks_
All disks.
static std::string DebugString()
static int num_datanode_dirs_
static std::map< dev_t, int > device_id_to_disk_id_
mapping of dev_ts to disk ids
static void GetDeviceNames()
static int disk_id(const char *path)
static std::map< std::string, int > disk_name_to_disk_id_
mapping of devices names to disk ids