1
2
3
4
5 package oshi.driver.unix.solaris.disk;
6
7 import java.util.HashMap;
8 import java.util.List;
9 import java.util.Map;
10 import java.util.Set;
11
12 import oshi.annotation.concurrent.ThreadSafe;
13 import oshi.util.ExecutingCommand;
14 import oshi.util.ParseUtil;
15 import oshi.util.tuples.Quintet;
16
17
18
19
20 @ThreadSafe
21 public final class Iostat {
22
23
24 private static final String IOSTAT_ER_DETAIL = "iostat -Er";
25
26
27 private static final String IOSTAT_ER = "iostat -er";
28
29
30
31
32
33
34
35 private static final String IOSTAT_ERN = "iostat -ern";
36
37
38
39
40
41
42 private static final String DEVICE_HEADER = "device";
43
44 private Iostat() {
45 }
46
47
48
49
50
51
52 public static Map<String, String> queryPartitionToMountMap() {
53
54
55 Map<String, String> deviceMap = new HashMap<>();
56
57
58 List<String> mountNames = ExecutingCommand.runNative(IOSTAT_ER);
59
60 List<String> mountPoints = ExecutingCommand.runNative(IOSTAT_ERN);
61
62 String disk;
63 for (int i = 0; i < mountNames.size() && i < mountPoints.size(); i++) {
64
65 disk = mountNames.get(i);
66 String[] diskSplit = disk.split(",");
67 if (diskSplit.length >= 5 && !DEVICE_HEADER.equals(diskSplit[0])) {
68 String mount = mountPoints.get(i);
69 String[] mountSplit = mount.split(",");
70 if (mountSplit.length >= 5 && !DEVICE_HEADER.equals(mountSplit[4])) {
71 deviceMap.put(diskSplit[0], mountSplit[4]);
72 }
73 }
74 }
75 return deviceMap;
76 }
77
78
79
80
81
82
83
84 public static Map<String, Quintet<String, String, String, String, Long>> queryDeviceStrings(Set<String> diskSet) {
85 Map<String, Quintet<String, String, String, String, Long>> deviceParamMap = new HashMap<>();
86
87 List<String> iostat = ExecutingCommand.runNative(IOSTAT_ER_DETAIL);
88
89 String diskName = null;
90 String model = "";
91 String vendor = "";
92 String product = "";
93 String serial = "";
94 long size = 0;
95 for (String line : iostat) {
96
97
98
99 String[] split = line.split(",");
100 for (String keyValue : split) {
101 keyValue = keyValue.trim();
102
103
104 if (diskSet.contains(keyValue)) {
105
106
107 if (diskName != null) {
108 deviceParamMap.put(diskName, new Quintet<>(model, vendor, product, serial, size));
109 }
110
111 diskName = keyValue;
112 model = "";
113 vendor = "";
114 product = "";
115 serial = "";
116 size = 0L;
117 continue;
118 }
119
120 if (keyValue.startsWith("Model:")) {
121 model = keyValue.replace("Model:", "").trim();
122 } else if (keyValue.startsWith("Serial No:")) {
123 serial = keyValue.replace("Serial No:", "").trim();
124 } else if (keyValue.startsWith("Vendor:")) {
125 vendor = keyValue.replace("Vendor:", "").trim();
126 } else if (keyValue.startsWith("Product:")) {
127 product = keyValue.replace("Product:", "").trim();
128 } else if (keyValue.startsWith("Size:")) {
129
130 String[] bytes = keyValue.split("<");
131 if (bytes.length > 1) {
132 bytes = ParseUtil.whitespaces.split(bytes[1]);
133 size = ParseUtil.parseLongOrDefault(bytes[0], 0L);
134 }
135 }
136 }
137
138 if (diskName != null) {
139 deviceParamMap.put(diskName, new Quintet<>(model, vendor, product, serial, size));
140 }
141 }
142 return deviceParamMap;
143 }
144 }