2 * collectd - src/tape.c
3 * Copyright (C) 2005,2006 Scott Garrett
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; either version 2 of the License, or (at your
8 * option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Scott Garrett <sgarrett at technomancer.com>
27 #if defined(HAVE_LIBKSTAT)
28 # define TAPE_HAVE_READ 1
30 # define TAPE_HAVE_READ 0
33 /* 2^34 = 17179869184 = ~17.2GByte/s */
34 static data_source_t octets_dsrc[2] =
36 {"read", DS_TYPE_COUNTER, 0, 17179869183.0},
37 {"write", DS_TYPE_COUNTER, 0, 17179869183.0}
40 static data_set_t octets_ds =
42 "tape_octets", 2, octets_dsrc
45 static data_source_t operations_dsrc[2] =
47 {"read", DS_TYPE_COUNTER, 0, 4294967295.0},
48 {"write", DS_TYPE_COUNTER, 0, 4294967295.0}
51 static data_set_t operations_ds =
53 "tape_ops", 2, operations_dsrc
56 static data_source_t merged_dsrc[2] =
58 {"read", DS_TYPE_COUNTER, 0, 4294967295.0},
59 {"write", DS_TYPE_COUNTER, 0, 4294967295.0}
62 static data_set_t merged_ds =
64 "tape_merged", 2, merged_dsrc
67 /* max is 1000000us per second. */
68 static data_source_t time_dsrc[2] =
70 {"read", DS_TYPE_COUNTER, 0, 1000000.0},
71 {"write", DS_TYPE_COUNTER, 0, 1000000.0}
74 static data_set_t time_ds =
76 "tape_time", 2, time_dsrc
80 #if defined(HAVE_LIBKSTAT)
81 #define MAX_NUMTAPE 256
82 extern kstat_ctl_t *kc;
83 static kstat_t *ksp[MAX_NUMTAPE];
84 static int numtape = 0;
85 #endif /* HAVE_LIBKSTAT */
87 static int tape_init (void)
97 for (numtape = 0, ksp_chain = kc->kc_chain;
98 (numtape < MAX_NUMTAPE) && (ksp_chain != NULL);
99 ksp_chain = ksp_chain->ks_next)
101 if (strncmp (ksp_chain->ks_class, "tape", 4) )
103 if (ksp_chain->ks_type != KSTAT_TYPE_IO)
105 ksp[numtape++] = ksp_chain;
112 static void tape_submit (const char *plugin_instance,
114 counter_t read, counter_t write)
117 value_list_t vl = VALUE_LIST_INIT;
119 values[0].counter = read;
120 values[1].counter = write;
124 vl.time = time (NULL);
125 strcpy (vl.host, hostname);
126 strcpy (vl.plugin, "tape");
127 strncpy (vl.plugin_instance, plugin_instance,
128 sizeof (vl.plugin_instance));
130 plugin_dispatch_values (type, &vl);
131 } /* void tape_submit */
133 static int tape_read (void)
136 #if defined(HAVE_LIBKSTAT)
137 static kstat_io_t kio;
146 for (i = 0; i < numtape; i++)
148 if (kstat_read (kc, ksp[i], &kio) == -1)
151 if (strncmp (ksp[i]->ks_class, "tape", 4) == 0)
153 tape_submit (ksp[i]->ks_name, "tape_octets", kio.reads, kio.writes);
154 tape_submit (ksp[i]->ks_name, "tape_ops", kio.nreads, kio.nwrites);
155 /* FIXME: Convert this to microseconds if necessary */
156 tape_submit (ksp[i]->ks_name, "tape_time", kio.rtime, kio.wtime);
159 #endif /* defined(HAVE_LIBKSTAT) */
163 #endif /* TAPE_HAVE_READ */
165 void module_register (void)
167 plugin_register_data_set (&octets_ds);
168 plugin_register_data_set (&operations_ds);
169 plugin_register_data_set (&merged_ds);
170 plugin_register_data_set (&time_ds);
173 plugin_register_init ("tape", tape_init);
174 plugin_register_read ("tape", tape_read);
175 #endif /* TAPE_HAVE_READ */