2 * collectd - src/tape.c
3 * Copyright (C) 2005 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>
26 #define MODULE_NAME "tape"
31 #if defined(HAVE_LIBKSTAT)
32 #define MAX_NUMTAPE 256
33 extern kstat_ctl_t *kc;
34 static kstat_t *ksp[MAX_NUMTAPE];
35 static int numtape = 0;
36 #endif /* HAVE_LIBKSTAT */
38 static char *tape_filename_template = "tape-%s.rrd";
40 /* 104857600 == 100 MB */
41 static char *tape_ds_def[] =
43 "DS:rcount:COUNTER:25:0:U",
44 "DS:rmerged:COUNTER:25:0:U",
45 "DS:rbytes:COUNTER:25:0:U",
46 "DS:rtime:COUNTER:25:0:U",
47 "DS:wcount:COUNTER:25:0:U",
48 "DS:wmerged:COUNTER:25:0:U",
49 "DS:wbytes:COUNTER:25:0:U",
50 "DS:wtime:COUNTER:25:0:U",
53 static int tape_ds_num = 8;
65 for (numtape = 0, ksp_chain = kc->kc_chain;
66 (numtape < MAX_NUMTAPE) && (ksp_chain != NULL);
67 ksp_chain = ksp_chain->ks_next)
69 if (strncmp (ksp_chain->ks_class, "tape", 4) )
71 if (ksp_chain->ks_type != KSTAT_TYPE_IO)
73 ksp[numtape++] = ksp_chain;
80 void tape_write (char *host, char *inst, char *val)
85 status = snprintf (file, 512, tape_filename_template, inst);
88 else if (status >= 512)
91 rrd_update_file (host, file, val, tape_ds_def, tape_ds_num);
96 void tape_submit (char *tape_name,
97 unsigned long long read_count,
98 unsigned long long read_merged,
99 unsigned long long read_bytes,
100 unsigned long long read_time,
101 unsigned long long write_count,
102 unsigned long long write_merged,
103 unsigned long long write_bytes,
104 unsigned long long write_time)
109 if (snprintf (buf, BUFSIZE, "%u:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
110 (unsigned int) curtime,
111 read_count, read_merged, read_bytes, read_time,
112 write_count, write_merged, write_bytes,
113 write_time) >= BUFSIZE)
116 plugin_submit (MODULE_NAME, tape_name, buf);
121 void tape_read (void)
124 #if defined(HAVE_LIBKSTAT)
125 static kstat_io_t kio;
131 for (i = 0; i < numtape; i++)
133 if (kstat_read (kc, ksp[i], &kio) == -1)
136 if (strncmp (ksp[i]->ks_class, "tape", 4) == 0)
137 tape_submit (ksp[i]->ks_name,
138 kio.reads, 0LL, kio.nread, kio.rtime,
139 kio.writes, 0LL, kio.nwritten, kio.wtime);
141 #endif /* defined(HAVE_LIBKSTAT) */
144 void module_register (void)
146 plugin_register (MODULE_NAME, tape_init, tape_read, tape_write);
150 #endif /* COLLECT_TAPE */