Lines 43-45
Link Here
|
43 |
#elif HAVE_LIBKSTAT |
43 |
#elif HAVE_LIBKSTAT |
44 |
kstat_t *ksp_chain; |
44 |
kstat_t *ksp_chain; |
45 |
|
45 |
|
|
|
46 |
@@ -505,6 +527,114 @@ static int disk_read (void) |
47 |
IOObjectRelease (disk_list); |
48 |
/* #endif HAVE_IOKIT_IOKITLIB_H */ |
49 |
|
50 |
+#elif KERNEL_FREEBSD |
51 |
+ int retry, dirty; |
52 |
+ |
53 |
+ void *snap = NULL; |
54 |
+ struct devstat *snap_iter; |
55 |
+ |
56 |
+ struct gident *geom_id; |
57 |
+ |
58 |
+ const char *disk_name; |
59 |
+ long double read_time, write_time; |
60 |
+ |
61 |
+ for (retry = 0, dirty = 1; retry < 5 && dirty == 1; retry++) { |
62 |
+ if (snap != NULL) |
63 |
+ geom_stats_snapshot_free(snap); |
64 |
+ |
65 |
+ /* Get a fresh copy of stats snapshot */ |
66 |
+ snap = geom_stats_snapshot_get(); |
67 |
+ if (snap == NULL) { |
68 |
+ ERROR("disk plugin: geom_stats_snapshot_get() failed."); |
69 |
+ return (-1); |
70 |
+ } |
71 |
+ |
72 |
+ /* Check if we have dirty read from this snapshot */ |
73 |
+ dirty = 0; |
74 |
+ geom_stats_snapshot_reset(snap); |
75 |
+ while ((snap_iter = geom_stats_snapshot_next(snap)) != NULL) { |
76 |
+ if (snap_iter->id == NULL) |
77 |
+ continue; |
78 |
+ geom_id = geom_lookupid(&geom_tree, snap_iter->id); |
79 |
+ |
80 |
+ /* New device? refresh GEOM tree */ |
81 |
+ if (geom_id == NULL) { |
82 |
+ geom_deletetree(&geom_tree); |
83 |
+ if (geom_gettree(&geom_tree) != 0) { |
84 |
+ ERROR("disk plugin: geom_gettree() failed"); |
85 |
+ geom_stats_snapshot_free(snap); |
86 |
+ return (-1); |
87 |
+ } |
88 |
+ geom_id = geom_lookupid(&geom_tree, snap_iter->id); |
89 |
+ } |
90 |
+ /* |
91 |
+ * This should be rare: the device come right before we take the |
92 |
+ * snapshot and went away right after it. We will handle this |
93 |
+ * case later, so don't mark dirty but silently ignore it. |
94 |
+ */ |
95 |
+ if (geom_id == NULL) |
96 |
+ continue; |
97 |
+ |
98 |
+ /* Only collect PROVIDER data */ |
99 |
+ if (geom_id->lg_what != ISPROVIDER) |
100 |
+ continue; |
101 |
+ |
102 |
+ /* Only collect data when rank is 1 (physical devices) */ |
103 |
+ if (((struct gprovider *)(geom_id->lg_ptr))->lg_geom->lg_rank != 1) |
104 |
+ continue; |
105 |
+ |
106 |
+ /* Check if this is a dirty read quit for another try */ |
107 |
+ if (snap_iter->sequence0 != snap_iter->sequence1) { |
108 |
+ dirty = 1; |
109 |
+ break; |
110 |
+ } |
111 |
+ } |
112 |
+ } |
113 |
+ |
114 |
+ /* Reset iterator */ |
115 |
+ geom_stats_snapshot_reset(snap); |
116 |
+ for (;;) { |
117 |
+ snap_iter = geom_stats_snapshot_next(snap); |
118 |
+ if (snap_iter == NULL) |
119 |
+ break; |
120 |
+ |
121 |
+ if (snap_iter->id == NULL) |
122 |
+ continue; |
123 |
+ geom_id = geom_lookupid(&geom_tree, snap_iter->id); |
124 |
+ if (geom_id == NULL) |
125 |
+ continue; |
126 |
+ if (geom_id->lg_what != ISPROVIDER) |
127 |
+ continue; |
128 |
+ if (((struct gprovider *)(geom_id->lg_ptr))->lg_geom->lg_rank != 1) |
129 |
+ continue; |
130 |
+ /* Skip dirty reads, if present */ |
131 |
+ if (dirty && (snap_iter->sequence0 != snap_iter->sequence1)) |
132 |
+ continue; |
133 |
+ |
134 |
+ disk_name = ((struct gprovider *)geom_id->lg_ptr)->lg_name; |
135 |
+ |
136 |
+ if ((snap_iter->bytes[1] != 0) || (snap_iter->bytes[2] != 0)) { |
137 |
+ disk_submit(disk_name, "disk_octets", |
138 |
+ (derive_t)snap_iter->bytes[1], |
139 |
+ (derive_t)snap_iter->bytes[2]); |
140 |
+ } |
141 |
+ |
142 |
+ if ((snap_iter->operations[1] != 0) || (snap_iter->operations[2] != 0)) { |
143 |
+ disk_submit(disk_name, "disk_ops", |
144 |
+ (derive_t)snap_iter->operations[1], |
145 |
+ (derive_t)snap_iter->operations[2]); |
146 |
+ } |
147 |
+ |
148 |
+ read_time = devstat_compute_etime(&snap_iter->duration[DEVSTAT_READ], NULL); |
149 |
+ write_time = devstat_compute_etime(&snap_iter->duration[DEVSTAT_WRITE], NULL); |
150 |
+ if ((read_time != 0) || (write_time != 0)) { |
151 |
+ disk_submit (disk_name, "disk_time", |
152 |
+ (derive_t)(read_time*1000), (derive_t)(write_time*1000)); |
153 |
+ } |
154 |
+ } |
155 |
+ geom_stats_snapshot_free(snap); |
156 |
+/* #endif KERNEL_FREEBSD */ |
157 |
+ |
158 |
#elif KERNEL_LINUX |
159 |
FILE *fh; |
160 |
char buffer[1024]; |