|
|
package com.platform.glusterfs;
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
import org.apache.log4j.PropertyConfigurator;
|
|
|
|
|
|
import com.platform.utils.Constant;
|
|
|
|
|
|
public class SizeInfo {
|
|
|
public static Logger log = Logger.getLogger(ClusterInfo.class);
|
|
|
VolumeInfo volumeInfo = new VolumeInfo();
|
|
|
|
|
|
/**
|
|
|
* 获取集群<E99B86>?<3F><>volume size
|
|
|
* 返回值:-1:错<EFBC9A>? 0:没有volume long:size大小
|
|
|
* @return
|
|
|
*/
|
|
|
public long showAllSize() {
|
|
|
// log.info("get AllSize ");
|
|
|
List<String> volumeNames = volumeInfo.showAllVolumeName();
|
|
|
if (volumeNames == null) {
|
|
|
log.error("1201 showAllVolumeName error");
|
|
|
return -1;
|
|
|
}
|
|
|
if (volumeNames.size() == 0) {
|
|
|
log.error("1202 It is not exist any volume");
|
|
|
return 0;
|
|
|
}
|
|
|
List<String> reStrings = null;
|
|
|
long size = 0L;
|
|
|
|
|
|
for (String str : volumeNames) {
|
|
|
String command = "df |grep " + str + "|awk \'{print $2}\'";
|
|
|
reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port,
|
|
|
command);
|
|
|
if (reStrings.isEmpty()) {
|
|
|
log.error("1203 The brick is unmount");
|
|
|
} else {
|
|
|
size += Long.parseLong(reStrings.get(0));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return size;
|
|
|
}
|
|
|
/**
|
|
|
* 返回集群已用大小
|
|
|
* @return
|
|
|
* 返回值:-1:错<EFBC9A>? 0:没有volume long:size大小
|
|
|
*/
|
|
|
public long showUseSize() {
|
|
|
log.info("get UseSize ");
|
|
|
|
|
|
List<String> volumeNames = volumeInfo.showAllVolumeName();
|
|
|
List<String> reStrings = null;
|
|
|
long size = 0L;
|
|
|
if (volumeNames == null) {
|
|
|
log.error("1201 showAllVolumeName error");
|
|
|
return -1;
|
|
|
}
|
|
|
if (volumeNames.size() == 0) {
|
|
|
log.error("1202 It is not exist any volume");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
for (String str : volumeNames) {
|
|
|
String command = "df |grep " + str + "|awk \'{print $3}\'";
|
|
|
reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
|
|
Constant.port, command);
|
|
|
if (reStrings.isEmpty()) {
|
|
|
log.error("1202 The brick is unmount");
|
|
|
} else {
|
|
|
size += Integer.valueOf(reStrings.get(0));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return size;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
PropertyConfigurator.configure("log4j.properties");
|
|
|
System.out.println(new SizeInfo().showAllSize());
|
|
|
System.out.println(new SizeInfo().showUseSize());
|
|
|
}
|
|
|
} |