1 diff --git a/src/collectd.c b/src/collectd.c
2 index 6b77d599..f17c19eb 100644
5 @@ -294,7 +294,7 @@ static int do_init (void)
12 ERROR ("sg_init: %s", sg_str_error (sg_get_error ()));
14 diff --git a/src/disk.c b/src/disk.c
15 index 4a78f1bd..5f972aa5 100644
19 static mach_port_t io_master_port = MACH_PORT_NULL;
20 /* #endif HAVE_IOKIT_IOKITLIB_H */
23 -typedef struct diskstats
27 - /* This overflows in roughly 1361 years */
28 - unsigned int poll_count;
30 - counter_t read_sectors;
31 - counter_t write_sectors;
33 - counter_t read_bytes;
34 - counter_t write_bytes;
37 - counter_t write_ops;
38 - counter_t read_time;
39 - counter_t write_time;
41 - counter_t avg_read_time;
42 - counter_t avg_write_time;
44 - struct diskstats *next;
47 -static diskstats_t *disklist;
48 -/* #endif KERNEL_LINUX */
51 #define MAX_NUMDISK 256
52 extern kstat_ctl_t *kc;
53 @@ -182,10 +154,6 @@ static int disk_init (void)
55 /* #endif HAVE_IOKIT_IOKITLIB_H */
59 -/* #endif KERNEL_LINUX */
64 @@ -235,16 +203,6 @@ static void disk_submit (const char *plugin_instance,
65 plugin_dispatch_values (&vl);
66 } /* void disk_submit */
69 -static counter_t disk_calc_time_incr (counter_t delta_time, counter_t delta_ops)
71 - double avg_time = ((double) delta_time) / ((double) delta_ops);
72 - double avg_time_incr = ((double) interval_g) * avg_time;
74 - return ((counter_t) (avg_time_incr + .5));
78 #if HAVE_IOKIT_IOKITLIB_H
79 static signed long long dict_get_value (CFDictionaryRef dict, const char *key)
81 @@ -428,218 +386,6 @@ static int disk_read (void)
82 IOObjectRelease (disk_list);
83 /* #endif HAVE_IOKIT_IOKITLIB_H */
95 - counter_t read_sectors = 0;
96 - counter_t write_sectors = 0;
98 - counter_t read_ops = 0;
99 - counter_t read_merged = 0;
100 - counter_t read_time = 0;
101 - counter_t write_ops = 0;
102 - counter_t write_merged = 0;
103 - counter_t write_time = 0;
106 - diskstats_t *ds, *pre_ds;
108 - if ((fh = fopen ("/proc/diskstats", "r")) == NULL)
110 - fh = fopen ("/proc/partitions", "r");
113 - ERROR ("disk plugin: fopen (/proc/{diskstats,partitions}) failed.");
117 - /* Kernel is 2.4.* */
121 - while (fgets (buffer, sizeof (buffer), fh) != NULL)
125 - numfields = strsplit (buffer, fields, 32);
127 - if ((numfields != (14 + fieldshift)) && (numfields != 7))
130 - minor = atoll (fields[1]);
132 - disk_name = fields[2 + fieldshift];
134 - for (ds = disklist, pre_ds = disklist; ds != NULL; pre_ds = ds, ds = ds->next)
135 - if (strcmp (disk_name, ds->name) == 0)
140 - if ((ds = (diskstats_t *) calloc (1, sizeof (diskstats_t))) == NULL)
143 - if ((ds->name = strdup (disk_name)) == NULL)
149 - if (pre_ds == NULL)
156 - if (numfields == 7)
158 - /* Kernel 2.6, Partition */
159 - read_ops = atoll (fields[3]);
160 - read_sectors = atoll (fields[4]);
161 - write_ops = atoll (fields[5]);
162 - write_sectors = atoll (fields[6]);
164 - else if (numfields == (14 + fieldshift))
166 - read_ops = atoll (fields[3 + fieldshift]);
167 - write_ops = atoll (fields[7 + fieldshift]);
169 - read_sectors = atoll (fields[5 + fieldshift]);
170 - write_sectors = atoll (fields[9 + fieldshift]);
172 - if ((fieldshift == 0) || (minor == 0))
175 - read_merged = atoll (fields[4 + fieldshift]);
176 - read_time = atoll (fields[6 + fieldshift]);
177 - write_merged = atoll (fields[8 + fieldshift]);
178 - write_time = atoll (fields[10+ fieldshift]);
183 - DEBUG ("numfields = %i; => unknown file format.", numfields);
188 - counter_t diff_read_sectors;
189 - counter_t diff_write_sectors;
191 - /* If the counter wraps around, it's only 32 bits.. */
192 - if (read_sectors < ds->read_sectors)
193 - diff_read_sectors = 1 + read_sectors
194 - + (UINT_MAX - ds->read_sectors);
196 - diff_read_sectors = read_sectors - ds->read_sectors;
197 - if (write_sectors < ds->write_sectors)
198 - diff_write_sectors = 1 + write_sectors
199 - + (UINT_MAX - ds->write_sectors);
201 - diff_write_sectors = write_sectors - ds->write_sectors;
203 - ds->read_bytes += 512 * diff_read_sectors;
204 - ds->write_bytes += 512 * diff_write_sectors;
205 - ds->read_sectors = read_sectors;
206 - ds->write_sectors = write_sectors;
209 - /* Calculate the average time an io-op needs to complete */
212 - counter_t diff_read_ops;
213 - counter_t diff_write_ops;
214 - counter_t diff_read_time;
215 - counter_t diff_write_time;
217 - if (read_ops < ds->read_ops)
218 - diff_read_ops = 1 + read_ops
219 - + (UINT_MAX - ds->read_ops);
221 - diff_read_ops = read_ops - ds->read_ops;
222 - DEBUG ("disk plugin: disk_name = %s; read_ops = %llu; "
223 - "ds->read_ops = %llu; diff_read_ops = %llu;",
225 - read_ops, ds->read_ops, diff_read_ops);
227 - if (write_ops < ds->write_ops)
228 - diff_write_ops = 1 + write_ops
229 - + (UINT_MAX - ds->write_ops);
231 - diff_write_ops = write_ops - ds->write_ops;
233 - if (read_time < ds->read_time)
234 - diff_read_time = 1 + read_time
235 - + (UINT_MAX - ds->read_time);
237 - diff_read_time = read_time - ds->read_time;
239 - if (write_time < ds->write_time)
240 - diff_write_time = 1 + write_time
241 - + (UINT_MAX - ds->write_time);
243 - diff_write_time = write_time - ds->write_time;
245 - if (diff_read_ops != 0)
246 - ds->avg_read_time += disk_calc_time_incr (
247 - diff_read_time, diff_read_ops);
248 - if (diff_write_ops != 0)
249 - ds->avg_write_time += disk_calc_time_incr (
250 - diff_write_time, diff_write_ops);
252 - ds->read_ops = read_ops;
253 - ds->read_time = read_time;
254 - ds->write_ops = write_ops;
255 - ds->write_time = write_time;
256 - } /* if (is_disk) */
258 - /* Don't write to the RRDs if we've just started.. */
260 - if (ds->poll_count <= 2)
262 - DEBUG ("disk plugin: (ds->poll_count = %i) <= "
263 - "(min_poll_count = 2); => Not writing.",
268 - if ((read_ops == 0) && (write_ops == 0))
270 - DEBUG ("disk plugin: ((read_ops == 0) && "
271 - "(write_ops == 0)); => Not writing.");
275 - if ((ds->read_bytes != 0) || (ds->write_bytes != 0))
276 - disk_submit (disk_name, "disk_octets",
277 - ds->read_bytes, ds->write_bytes);
279 - if ((ds->read_ops != 0) || (ds->write_ops != 0))
280 - disk_submit (disk_name, "disk_ops",
281 - read_ops, write_ops);
283 - if ((ds->avg_read_time != 0) || (ds->avg_write_time != 0))
284 - disk_submit (disk_name, "disk_time",
285 - ds->avg_read_time, ds->avg_write_time);
289 - disk_submit (disk_name, "disk_merged",
290 - read_merged, write_merged);
291 - } /* if (is_disk) */
292 - } /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
295 -/* #endif defined(KERNEL_LINUX) */
298 # if HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_NWRITES && HAVE_KSTAT_IO_T_WTIME
299 # define KIO_ROCTETS reads