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>
27 #define MODULE_NAME "tape"
29 #if defined(HAVE_LIBKSTAT)
30 # define TAPE_HAVE_READ 1
32 # define TAPE_HAVE_READ 0
35 static char *tape_filename_template = "tape-%s.rrd";
37 /* 104857600 == 100 MB */
38 static char *tape_ds_def[] =
40 "DS:rcount:COUNTER:"COLLECTD_HEARTBEAT":0:U",
41 "DS:rmerged:COUNTER:"COLLECTD_HEARTBEAT":0:U",
42 "DS:rbytes:COUNTER:"COLLECTD_HEARTBEAT":0:U",
43 "DS:rtime:COUNTER:"COLLECTD_HEARTBEAT":0:U",
44 "DS:wcount:COUNTER:"COLLECTD_HEARTBEAT":0:U",
45 "DS:wmerged:COUNTER:"COLLECTD_HEARTBEAT":0:U",
46 "DS:wbytes:COUNTER:"COLLECTD_HEARTBEAT":0:U",
47 "DS:wtime:COUNTER:"COLLECTD_HEARTBEAT":0:U",
50 static int tape_ds_num = 8;
52 #if defined(HAVE_LIBKSTAT)
53 #define MAX_NUMTAPE 256
54 extern kstat_ctl_t *kc;
55 static kstat_t *ksp[MAX_NUMTAPE];
56 static int numtape = 0;
57 #endif /* HAVE_LIBKSTAT */
59 static void tape_init (void)
69 for (numtape = 0, ksp_chain = kc->kc_chain;
70 (numtape < MAX_NUMTAPE) && (ksp_chain != NULL);
71 ksp_chain = ksp_chain->ks_next)
73 if (strncmp (ksp_chain->ks_class, "tape", 4) )
75 if (ksp_chain->ks_type != KSTAT_TYPE_IO)
77 ksp[numtape++] = ksp_chain;
84 static void tape_write (char *host, char *inst, char *val)
89 status = snprintf (file, 512, tape_filename_template, inst);
92 else if (status >= 512)
95 rrd_update_file (host, file, val, tape_ds_def, tape_ds_num);
101 static void tape_submit (char *tape_name,
102 unsigned long long read_count,
103 unsigned long long read_merged,
104 unsigned long long read_bytes,
105 unsigned long long read_time,
106 unsigned long long write_count,
107 unsigned long long write_merged,
108 unsigned long long write_bytes,
109 unsigned long long write_time)
114 if (snprintf (buf, BUFSIZE, "%u:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
115 (unsigned int) curtime,
116 read_count, read_merged, read_bytes, read_time,
117 write_count, write_merged, write_bytes,
118 write_time) >= BUFSIZE)
121 plugin_submit (MODULE_NAME, tape_name, buf);
126 static void tape_read (void)
129 #if defined(HAVE_LIBKSTAT)
130 static kstat_io_t kio;
136 for (i = 0; i < numtape; i++)
138 if (kstat_read (kc, ksp[i], &kio) == -1)
141 if (strncmp (ksp[i]->ks_class, "tape", 4) == 0)
142 tape_submit (ksp[i]->ks_name,
143 kio.reads, 0LL, kio.nread, kio.rtime,
144 kio.writes, 0LL, kio.nwritten, kio.wtime);
146 #endif /* defined(HAVE_LIBKSTAT) */
149 # define tape_read NULL
150 #endif /* TAPE_HAVE_READ */
152 void module_register (void)
154 plugin_register (MODULE_NAME, tape_init, tape_read, tape_write);