Merge branch 'ok/disk' into collectd-4.4
[collectd.git] / src / disk.c
1 /**
2  * collectd - src/disk.c
3  * Copyright (C) 2005-2008  Florian octo Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #include "collectd.h"
23 #include "common.h"
24 #include "plugin.h"
25 #include "utils_ignorelist.h"
26
27 #if HAVE_MACH_MACH_TYPES_H
28 #  include <mach/mach_types.h>
29 #endif
30 #if HAVE_MACH_MACH_INIT_H
31 #  include <mach/mach_init.h>
32 #endif
33 #if HAVE_MACH_MACH_ERROR_H
34 #  include <mach/mach_error.h>
35 #endif
36 #if HAVE_MACH_MACH_PORT_H
37 #  include <mach/mach_port.h>
38 #endif
39 #if HAVE_COREFOUNDATION_COREFOUNDATION_H
40 #  include <CoreFoundation/CoreFoundation.h>
41 #endif
42 #if HAVE_IOKIT_IOKITLIB_H
43 #  include <IOKit/IOKitLib.h>
44 #endif
45 #if HAVE_IOKIT_IOTYPES_H
46 #  include <IOKit/IOTypes.h>
47 #endif
48 #if HAVE_IOKIT_STORAGE_IOBLOCKSTORAGEDRIVER_H
49 #  include <IOKit/storage/IOBlockStorageDriver.h>
50 #endif
51 #if HAVE_IOKIT_IOBSD_H
52 #  include <IOKit/IOBSD.h>
53 #endif
54
55 #if HAVE_LIMITS_H
56 # include <limits.h>
57 #endif
58 #ifndef UINT_MAX
59 #  define UINT_MAX 4294967295U
60 #endif
61
62 #if HAVE_STATGRAB_H
63 # include <statgrab.h>
64 #endif
65
66 #if HAVE_IOKIT_IOKITLIB_H
67 static mach_port_t io_master_port = MACH_PORT_NULL;
68 /* #endif HAVE_IOKIT_IOKITLIB_H */
69
70 #elif KERNEL_LINUX
71 typedef struct diskstats
72 {
73         char *name;
74
75         /* This overflows in roughly 1361 years */
76         unsigned int poll_count;
77
78         counter_t read_sectors;
79         counter_t write_sectors;
80
81         counter_t read_bytes;
82         counter_t write_bytes;
83
84         counter_t read_ops;
85         counter_t write_ops;
86         counter_t read_time;
87         counter_t write_time;
88
89         counter_t avg_read_time;
90         counter_t avg_write_time;
91
92         struct diskstats *next;
93 } diskstats_t;
94
95 static diskstats_t *disklist;
96 /* #endif KERNEL_LINUX */
97
98 #elif HAVE_LIBKSTAT
99 #define MAX_NUMDISK 256
100 extern kstat_ctl_t *kc;
101 static kstat_t *ksp[MAX_NUMDISK];
102 static int numdisk = 0;
103 /* #endif HAVE_LIBKSTAT */
104
105 #elif defined(HAVE_LIBSTATGRAB)
106 /* #endif HAVE_LIBKSTATGRAB */
107
108 #else
109 # error "No applicable input method."
110 #endif
111
112 static const char *config_keys[] =
113 {
114         "Disk",
115         "IgnoreSelected"
116 };
117 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
118
119 static ignorelist_t *ignorelist = NULL;
120
121 static int disk_config (const char *key, const char *value)
122 {
123   if (ignorelist == NULL)
124     ignorelist = ignorelist_create (/* invert = */ 1);
125   if (ignorelist == NULL)
126     return (1);
127
128   if (strcasecmp ("Disk", key) == 0)
129   {
130     ignorelist_add (ignorelist, value);
131   }
132   else if (strcasecmp ("IgnoreSelected", key) == 0)
133   {
134     int invert = 1;
135     if ((strcasecmp ("True", value) == 0)
136         || (strcasecmp ("Yes", value) == 0)
137         || (strcasecmp ("On", value) == 0))
138       invert = 0;
139     ignorelist_set_invert (ignorelist, invert);
140   }
141   else
142   {
143     return (-1);
144   }
145
146   return (0);
147 } /* int disk_config */
148
149 static int disk_init (void)
150 {
151 #if HAVE_IOKIT_IOKITLIB_H
152         kern_return_t status;
153         
154         if (io_master_port != MACH_PORT_NULL)
155         {
156                 mach_port_deallocate (mach_task_self (),
157                                 io_master_port);
158                 io_master_port = MACH_PORT_NULL;
159         }
160
161         status = IOMasterPort (MACH_PORT_NULL, &io_master_port);
162         if (status != kIOReturnSuccess)
163         {
164                 ERROR ("IOMasterPort failed: %s",
165                                 mach_error_string (status));
166                 io_master_port = MACH_PORT_NULL;
167                 return (-1);
168         }
169 /* #endif HAVE_IOKIT_IOKITLIB_H */
170
171 #elif KERNEL_LINUX
172         /* do nothing */
173 /* #endif KERNEL_LINUX */
174
175 #elif HAVE_LIBKSTAT
176         kstat_t *ksp_chain;
177
178         numdisk = 0;
179
180         if (kc == NULL)
181                 return (-1);
182
183         for (numdisk = 0, ksp_chain = kc->kc_chain;
184                         (numdisk < MAX_NUMDISK) && (ksp_chain != NULL);
185                         ksp_chain = ksp_chain->ks_next)
186         {
187                 if (strncmp (ksp_chain->ks_class, "disk", 4)
188                                 && strncmp (ksp_chain->ks_class, "partition", 9))
189                         continue;
190                 if (ksp_chain->ks_type != KSTAT_TYPE_IO)
191                         continue;
192                 ksp[numdisk++] = ksp_chain;
193         }
194 #endif /* HAVE_LIBKSTAT */
195
196         return (0);
197 } /* int disk_init */
198
199 static void disk_submit (const char *plugin_instance,
200                 const char *type,
201                 counter_t read, counter_t write)
202 {
203         value_t values[2];
204         value_list_t vl = VALUE_LIST_INIT;
205
206         /* Both `ignorelist' and `plugin_instance' may be NULL. */
207         if (ignorelist_match (ignorelist, plugin_instance) != 0)
208           return;
209
210         values[0].counter = read;
211         values[1].counter = write;
212
213         vl.values = values;
214         vl.values_len = 2;
215         vl.time = time (NULL);
216         strcpy (vl.host, hostname_g);
217         strcpy (vl.plugin, "disk");
218         strncpy (vl.plugin_instance, plugin_instance,
219                         sizeof (vl.plugin_instance));
220
221         plugin_dispatch_values (type, &vl);
222 } /* void disk_submit */
223
224 #if HAVE_IOKIT_IOKITLIB_H
225 static signed long long dict_get_value (CFDictionaryRef dict, const char *key)
226 {
227         signed long long val_int;
228         CFNumberRef      val_obj;
229         CFStringRef      key_obj;
230
231         /* `key_obj' needs to be released. */
232         key_obj = CFStringCreateWithCString (kCFAllocatorDefault, key,
233                         kCFStringEncodingASCII);
234         if (key_obj == NULL)
235         {
236                 DEBUG ("CFStringCreateWithCString (%s) failed.", key);
237                 return (-1LL);
238         }
239         
240         /* get => we don't need to release (== free) the object */
241         val_obj = (CFNumberRef) CFDictionaryGetValue (dict, key_obj);
242
243         CFRelease (key_obj);
244
245         if (val_obj == NULL)
246         {
247                 DEBUG ("CFDictionaryGetValue (%s) failed.", key);
248                 return (-1LL);
249         }
250
251         if (!CFNumberGetValue (val_obj, kCFNumberSInt64Type, &val_int))
252         {
253                 DEBUG ("CFNumberGetValue (%s) failed.", key);
254                 return (-1LL);
255         }
256
257         return (val_int);
258 }
259 #endif /* HAVE_IOKIT_IOKITLIB_H */
260
261 static int disk_read (void)
262 {
263 #if HAVE_IOKIT_IOKITLIB_H
264         io_registry_entry_t     disk;
265         io_registry_entry_t     disk_child;
266         io_iterator_t           disk_list;
267         CFDictionaryRef         props_dict;
268         CFDictionaryRef         stats_dict;
269         CFDictionaryRef         child_dict;
270         kern_return_t           status;
271
272         signed long long read_ops;
273         signed long long read_byt;
274         signed long long read_tme;
275         signed long long write_ops;
276         signed long long write_byt;
277         signed long long write_tme;
278
279         int  disk_major;
280         int  disk_minor;
281         char disk_name[64];
282
283         /* Get the list of all disk objects. */
284         if (IOServiceGetMatchingServices (io_master_port,
285                                 IOServiceMatching (kIOBlockStorageDriverClass),
286                                 &disk_list) != kIOReturnSuccess)
287         {
288                 ERROR ("disk plugin: IOServiceGetMatchingServices failed.");
289                 return (-1);
290         }
291
292         while ((disk = IOIteratorNext (disk_list)) != 0)
293         {
294                 props_dict = NULL;
295                 stats_dict = NULL;
296                 child_dict = NULL;
297
298                 /* `disk_child' must be released */
299                 if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child))
300                                 != kIOReturnSuccess)
301                 {
302                         /* This fails for example for DVD/CD drives.. */
303                         DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status);
304                         IOObjectRelease (disk);
305                         continue;
306                 }
307
308                 /* We create `props_dict' => we need to release it later */
309                 if (IORegistryEntryCreateCFProperties (disk,
310                                         (CFMutableDictionaryRef *) &props_dict,
311                                         kCFAllocatorDefault,
312                                         kNilOptions)
313                                 != kIOReturnSuccess)
314                 {
315                         ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed.");
316                         IOObjectRelease (disk_child);
317                         IOObjectRelease (disk);
318                         continue;
319                 }
320
321                 if (props_dict == NULL)
322                 {
323                         DEBUG ("IORegistryEntryCreateCFProperties (disk) failed.");
324                         IOObjectRelease (disk_child);
325                         IOObjectRelease (disk);
326                         continue;
327                 }
328
329                 stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict,
330                                 CFSTR (kIOBlockStorageDriverStatisticsKey));
331
332                 if (stats_dict == NULL)
333                 {
334                         DEBUG ("CFDictionaryGetValue (%s) failed.",
335                                         kIOBlockStorageDriverStatisticsKey);
336                         CFRelease (props_dict);
337                         IOObjectRelease (disk_child);
338                         IOObjectRelease (disk);
339                         continue;
340                 }
341
342                 if (IORegistryEntryCreateCFProperties (disk_child,
343                                         (CFMutableDictionaryRef *) &child_dict,
344                                         kCFAllocatorDefault,
345                                         kNilOptions)
346                                 != kIOReturnSuccess)
347                 {
348                         DEBUG ("IORegistryEntryCreateCFProperties (disk_child) failed.");
349                         IOObjectRelease (disk_child);
350                         CFRelease (props_dict);
351                         IOObjectRelease (disk);
352                         continue;
353                 }
354
355                 /* kIOBSDNameKey */
356                 disk_major = (int) dict_get_value (child_dict,
357                                 kIOBSDMajorKey);
358                 disk_minor = (int) dict_get_value (child_dict,
359                                 kIOBSDMinorKey);
360                 read_ops  = dict_get_value (stats_dict,
361                                 kIOBlockStorageDriverStatisticsReadsKey);
362                 read_byt  = dict_get_value (stats_dict,
363                                 kIOBlockStorageDriverStatisticsBytesReadKey);
364                 read_tme  = dict_get_value (stats_dict,
365                                 kIOBlockStorageDriverStatisticsTotalReadTimeKey);
366                 write_ops = dict_get_value (stats_dict,
367                                 kIOBlockStorageDriverStatisticsWritesKey);
368                 write_byt = dict_get_value (stats_dict,
369                                 kIOBlockStorageDriverStatisticsBytesWrittenKey);
370                 /* This property describes the number of nanoseconds spent
371                  * performing writes since the block storage driver was
372                  * instantiated. It is one of the statistic entries listed
373                  * under the top-level kIOBlockStorageDriverStatisticsKey
374                  * property table. It has an OSNumber value. */
375                 write_tme = dict_get_value (stats_dict,
376                                 kIOBlockStorageDriverStatisticsTotalWriteTimeKey);
377
378                 if (snprintf (disk_name, 64, "%i-%i", disk_major, disk_minor) >= 64)
379                 {
380                         DEBUG ("snprintf (major, minor) failed.");
381                         CFRelease (child_dict);
382                         IOObjectRelease (disk_child);
383                         CFRelease (props_dict);
384                         IOObjectRelease (disk);
385                         continue;
386                 }
387                 DEBUG ("disk_name = %s", disk_name);
388
389                 if ((read_byt != -1LL) || (write_byt != -1LL))
390                         disk_submit (disk_name, "disk_octets", read_byt, write_byt);
391                 if ((read_ops != -1LL) || (write_ops != -1LL))
392                         disk_submit (disk_name, "disk_ops", read_ops, write_ops);
393                 if ((read_tme != -1LL) || (write_tme != -1LL))
394                         disk_submit (disk_name, "disk_time",
395                                         read_tme / 1000,
396                                         write_tme / 1000);
397
398                 CFRelease (child_dict);
399                 IOObjectRelease (disk_child);
400                 CFRelease (props_dict);
401                 IOObjectRelease (disk);
402         }
403         IOObjectRelease (disk_list);
404 /* #endif HAVE_IOKIT_IOKITLIB_H */
405
406 #elif KERNEL_LINUX
407         FILE *fh;
408         char buffer[1024];
409         
410         char *fields[32];
411         int numfields;
412         int fieldshift = 0;
413
414         int major = 0;
415         int minor = 0;
416
417         counter_t read_sectors  = 0;
418         counter_t write_sectors = 0;
419
420         counter_t read_ops      = 0;
421         counter_t read_merged   = 0;
422         counter_t read_time     = 0;
423         counter_t write_ops     = 0;
424         counter_t write_merged  = 0;
425         counter_t write_time    = 0;
426         int is_disk = 0;
427
428         diskstats_t *ds, *pre_ds;
429
430         if ((fh = fopen ("/proc/diskstats", "r")) == NULL)
431         {
432                 fh = fopen ("/proc/partitions", "r");
433                 if (fh == NULL)
434                 {
435                         ERROR ("disk plugin: fopen (/proc/{diskstats,partitions}) failed.");
436                         return (-1);
437                 }
438
439                 /* Kernel is 2.4.* */
440                 fieldshift = 1;
441         }
442
443         while (fgets (buffer, sizeof (buffer), fh) != NULL)
444         {
445                 char *disk_name;
446
447                 numfields = strsplit (buffer, fields, 32);
448
449                 if ((numfields != (14 + fieldshift)) && (numfields != 7))
450                         continue;
451
452                 major = atoll (fields[0]);
453                 minor = atoll (fields[1]);
454
455                 disk_name = fields[2];
456
457                 for (ds = disklist, pre_ds = disklist; ds != NULL; pre_ds = ds, ds = ds->next)
458                         if (strcmp (disk_name, ds->name) == 0)
459                                 break;
460
461                 if (ds == NULL)
462                 {
463                         if ((ds = (diskstats_t *) calloc (1, sizeof (diskstats_t))) == NULL)
464                                 continue;
465
466                         if ((ds->name = strdup (disk_name)) == NULL)
467                         {
468                                 free (ds);
469                                 continue;
470                         }
471
472                         if (pre_ds == NULL)
473                                 disklist = ds;
474                         else
475                                 pre_ds->next = ds;
476                 }
477
478                 is_disk = 0;
479                 if (numfields == 7)
480                 {
481                         /* Kernel 2.6, Partition */
482                         read_ops      = atoll (fields[3]);
483                         read_sectors  = atoll (fields[4]);
484                         write_ops     = atoll (fields[5]);
485                         write_sectors = atoll (fields[6]);
486                 }
487                 else if (numfields == (14 + fieldshift))
488                 {
489                         read_ops  =  atoll (fields[3 + fieldshift]);
490                         write_ops =  atoll (fields[7 + fieldshift]);
491
492                         read_sectors  = atoll (fields[5 + fieldshift]);
493                         write_sectors = atoll (fields[9 + fieldshift]);
494
495                         if ((fieldshift == 0) || (minor == 0))
496                         {
497                                 is_disk = 1;
498                                 read_merged  = atoll (fields[4 + fieldshift]);
499                                 read_time    = atoll (fields[6 + fieldshift]);
500                                 write_merged = atoll (fields[8 + fieldshift]);
501                                 write_time   = atoll (fields[10+ fieldshift]);
502                         }
503                 }
504                 else
505                 {
506                         DEBUG ("numfields = %i; => unknown file format.", numfields);
507                         continue;
508                 }
509
510                 {
511                         counter_t diff_read_sectors;
512                         counter_t diff_write_sectors;
513
514                 /* If the counter wraps around, it's only 32 bits.. */
515                         if (read_sectors < ds->read_sectors)
516                                 diff_read_sectors = 1 + read_sectors
517                                         + (UINT_MAX - ds->read_sectors);
518                         else
519                                 diff_read_sectors = read_sectors - ds->read_sectors;
520                         if (write_sectors < ds->write_sectors)
521                                 diff_write_sectors = 1 + write_sectors
522                                         + (UINT_MAX - ds->write_sectors);
523                         else
524                                 diff_write_sectors = write_sectors - ds->write_sectors;
525
526                         ds->read_bytes += 512 * diff_read_sectors;
527                         ds->write_bytes += 512 * diff_write_sectors;
528                         ds->read_sectors = read_sectors;
529                         ds->write_sectors = write_sectors;
530                 }
531
532                 /* Calculate the average time an io-op needs to complete */
533                 if (is_disk)
534                 {
535                         counter_t diff_read_ops;
536                         counter_t diff_write_ops;
537                         counter_t diff_read_time;
538                         counter_t diff_write_time;
539
540                         if (read_ops < ds->read_ops)
541                                 diff_read_ops = 1 + read_ops
542                                         + (UINT_MAX - ds->read_ops);
543                         else
544                                 diff_read_ops = read_ops - ds->read_ops;
545                         DEBUG ("disk plugin: disk_name = %s; read_ops = %llu; "
546                                         "ds->read_ops = %llu; diff_read_ops = %llu;",
547                                         disk_name,
548                                         read_ops, ds->read_ops, diff_read_ops);
549
550                         if (write_ops < ds->write_ops)
551                                 diff_write_ops = 1 + write_ops
552                                         + (UINT_MAX - ds->write_ops);
553                         else
554                                 diff_write_ops = write_ops - ds->write_ops;
555
556                         if (read_time < ds->read_time)
557                                 diff_read_time = 1 + read_time
558                                         + (UINT_MAX - ds->read_time);
559                         else
560                                 diff_read_time = read_time - ds->read_time;
561
562                         if (write_time < ds->write_time)
563                                 diff_write_time = 1 + write_time
564                                         + (UINT_MAX - ds->write_time);
565                         else
566                                 diff_write_time = write_time - ds->write_time;
567
568                         if (diff_read_ops != 0)
569                                 ds->avg_read_time += (diff_read_time
570                                                 + (diff_read_ops / 2))
571                                         / diff_read_ops;
572                         if (diff_write_ops != 0)
573                                 ds->avg_write_time += (diff_write_time
574                                                 + (diff_write_ops / 2))
575                                         / diff_write_ops;
576
577                         ds->read_ops = read_ops;
578                         ds->read_time = read_time;
579                         ds->write_ops = write_ops;
580                         ds->write_time = write_time;
581                 } /* if (is_disk) */
582
583                 /* Don't write to the RRDs if we've just started.. */
584                 ds->poll_count++;
585                 if (ds->poll_count <= 2)
586                 {
587                         DEBUG ("disk plugin: (ds->poll_count = %i) <= "
588                                         "(min_poll_count = 2); => Not writing.",
589                                         ds->poll_count);
590                         continue;
591                 }
592
593                 if ((read_ops == 0) && (write_ops == 0))
594                 {
595                         DEBUG ("disk plugin: ((read_ops == 0) && "
596                                         "(write_ops == 0)); => Not writing.");
597                         continue;
598                 }
599
600                 if ((ds->read_bytes != 0) || (ds->write_bytes != 0))
601                         disk_submit (disk_name, "disk_octets",
602                                         ds->read_bytes, ds->write_bytes);
603
604                 if ((ds->read_ops != 0) || (ds->write_ops != 0))
605                         disk_submit (disk_name, "disk_ops",
606                                         read_ops, write_ops);
607
608                 if ((ds->avg_read_time != 0) || (ds->avg_write_time != 0))
609                         disk_submit (disk_name, "disk_time",
610                                         ds->avg_read_time, ds->avg_write_time);
611
612                 if (is_disk)
613                 {
614                         disk_submit (disk_name, "disk_merged",
615                                         read_merged, write_merged);
616                 } /* if (is_disk) */
617         } /* while (fgets (buffer, sizeof (buffer), fh) != NULL) */
618
619         fclose (fh);
620 /* #endif defined(KERNEL_LINUX) */
621
622 #elif HAVE_LIBKSTAT
623 # if HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_NWRITES && HAVE_KSTAT_IO_T_WTIME
624 #  define KIO_ROCTETS reads
625 #  define KIO_WOCTETS writes
626 #  define KIO_ROPS    nreads
627 #  define KIO_WOPS    nwrites
628 #  define KIO_RTIME   rtime
629 #  define KIO_WTIME   wtime
630 # elif HAVE_KSTAT_IO_T_NWRITTEN && HAVE_KSTAT_IO_T_WRITES && HAVE_KSTAT_IO_T_WTIME
631 #  define KIO_ROCTETS nread
632 #  define KIO_WOCTETS nwritten
633 #  define KIO_ROPS    reads
634 #  define KIO_WOPS    writes
635 #  define KIO_RTIME   rtime
636 #  define KIO_WTIME   wtime
637 # else
638 #  error "kstat_io_t does not have the required members"
639 # endif
640         static kstat_io_t kio;
641         int i;
642
643         if (kc == NULL)
644                 return (-1);
645
646         for (i = 0; i < numdisk; i++)
647         {
648                 if (kstat_read (kc, ksp[i], &kio) == -1)
649                         continue;
650
651                 if (strncmp (ksp[i]->ks_class, "disk", 4) == 0)
652                 {
653                         disk_submit (ksp[i]->ks_name, "disk_octets",
654                                         kio.KIO_ROCTETS, kio.KIO_WOCTETS);
655                         disk_submit (ksp[i]->ks_name, "disk_ops",
656                                         kio.KIO_ROPS, kio.KIO_WOPS);
657                         /* FIXME: Convert this to microseconds if necessary */
658                         disk_submit (ksp[i]->ks_name, "disk_time",
659                                         kio.KIO_RTIME, kio.KIO_WTIME);
660                 }
661                 else if (strncmp (ksp[i]->ks_class, "partition", 9) == 0)
662                 {
663                         disk_submit (ksp[i]->ks_name, "disk_octets",
664                                         kio.KIO_ROCTETS, kio.KIO_WOCTETS);
665                         disk_submit (ksp[i]->ks_name, "disk_ops",
666                                         kio.KIO_ROPS, kio.KIO_WOPS);
667                 }
668         }
669 /* #endif defined(HAVE_LIBKSTAT) */
670
671 #elif defined(HAVE_LIBSTATGRAB)
672         sg_disk_io_stats *ds;
673         int disks, counter;
674         char name[DATA_MAX_NAME_LEN];
675         
676         if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
677                 return (0);
678                 
679         for (counter=0; counter < disks; counter++) {
680                 strncpy(name, ds->disk_name, sizeof(name));
681                 name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */
682                 disk_submit (name, "disk_octets", ds->read_bytes, ds->write_bytes);
683                 ds++;
684         }
685 #endif /* defined(HAVE_LIBSTATGRAB) */
686
687         return (0);
688 } /* int disk_read */
689
690 void module_register (void)
691 {
692   plugin_register_config ("disk", disk_config,
693       config_keys, config_keys_num);
694   plugin_register_init ("disk", disk_init);
695   plugin_register_read ("disk", disk_read);
696 } /* void module_register */