2
2
* collectd - src/disk.c
3
* Copyright (C) 2005-2007 Florian octo Forster
3
* Copyright (C) 2005-2008 Florian octo Forster
5
5
* This program is free software; you can redistribute it and/or modify it
6
6
* under the terms of the GNU General Public License as published by the
97
102
static int numdisk = 0;
98
103
/* #endif HAVE_LIBKSTAT */
105
#elif defined(HAVE_LIBSTATGRAB)
106
/* #endif HAVE_LIBKSTATGRAB */
101
109
# error "No applicable input method."
112
static const char *config_keys[] =
117
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
119
static ignorelist_t *ignorelist = NULL;
121
static int disk_config (const char *key, const char *value)
123
if (ignorelist == NULL)
124
ignorelist = ignorelist_create (/* invert = */ 1);
125
if (ignorelist == NULL)
128
if (strcasecmp ("Disk", key) == 0)
130
ignorelist_add (ignorelist, value);
132
else if (strcasecmp ("IgnoreSelected", key) == 0)
135
if ((strcasecmp ("True", value) == 0)
136
|| (strcasecmp ("Yes", value) == 0)
137
|| (strcasecmp ("On", value) == 0))
139
ignorelist_set_invert (ignorelist, invert);
147
} /* int disk_config */
104
149
static int disk_init (void)
106
151
#if HAVE_IOKIT_IOKITLIB_H
158
203
value_t values[2];
159
204
value_list_t vl = VALUE_LIST_INIT;
206
/* Both `ignorelist' and `plugin_instance' may be NULL. */
207
if (ignorelist_match (ignorelist, plugin_instance) != 0)
161
210
values[0].counter = read;
162
211
values[1].counter = write;
617
666
kio.KIO_ROPS, kio.KIO_WOPS);
620
#endif /* defined(HAVE_LIBKSTAT) */
669
/* #endif defined(HAVE_LIBKSTAT) */
671
#elif defined(HAVE_LIBSTATGRAB)
672
sg_disk_io_stats *ds;
674
char name[DATA_MAX_NAME_LEN];
676
if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
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);
685
#endif /* defined(HAVE_LIBSTATGRAB) */
623
688
} /* int disk_read */
625
690
void module_register (void)
627
plugin_register_init ("disk", disk_init);
628
plugin_register_read ("disk", disk_read);
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);
629
696
} /* void module_register */