2 * collectd - src/zfs_arc.c
3 * Copyright (C) 2009 Anthony Dewhurst
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.
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.
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
19 * Anthony Dewhurst <dewhurst at gmail>
30 extern kstat_ctl_t *kc;
32 static void za_submit (const char* type, const char* type_instance, value_t* values, int values_len)
34 value_list_t vl = VALUE_LIST_INIT;
37 vl.values_len = values_len;
39 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
40 sstrncpy (vl.plugin, "zfs_arc", sizeof (vl.plugin));
41 sstrncpy (vl.type, type, sizeof (vl.type));
42 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
44 plugin_dispatch_values (&vl);
47 static void za_submit_gauge (const char* type, const char* type_instance, gauge_t value)
51 values[0].gauge = value;
53 za_submit (type, type_instance, values, STATIC_ARRAY_SIZE(values));
56 static void za_submit_size (gauge_t size, gauge_t size_target, gauge_t limit_min, gauge_t limit_max)
60 values[0].gauge = size;
61 values[1].gauge = size_target;
62 values[2].gauge = limit_min;
63 values[3].gauge = limit_max;
65 za_submit ("arc_size", "", values, STATIC_ARRAY_SIZE(values));
68 static void za_submit_bytes (counter_t read, counter_t write)
72 values[0].counter = read;
73 values[1].counter = write;
75 za_submit ("arc_l2_bytes", "", values, STATIC_ARRAY_SIZE(values));
78 static void za_submit_counts (char *type_instance, counter_t demand_data, counter_t demand_metadata,
79 counter_t prefetch_data, counter_t prefetch_metadata)
83 values[0].counter = demand_data;
84 values[1].counter = demand_metadata;
85 values[2].counter = prefetch_data;
86 values[3].counter = prefetch_metadata;
88 za_submit ("arc_counts", type_instance, values, STATIC_ARRAY_SIZE(values));
91 static int za_read (void)
93 gauge_t arcsize, targetsize, minlimit, maxlimit, hits, misses, l2_size, l2_hits, l2_misses;
94 counter_t demand_data_hits, demand_metadata_hits, prefetch_data_hits, prefetch_metadata_hits;
95 counter_t demand_data_misses, demand_metadata_misses, prefetch_data_misses, prefetch_metadata_misses;
96 counter_t l2_read_bytes, l2_write_bytes;
98 get_kstat (&ksp, "zfs", 0, "arcstats");
101 ERROR ("zfs_arc plugin: Cannot find zfs:0:arcstats kstat.");
105 arcsize = get_kstat_value(ksp, "size");
106 targetsize = get_kstat_value(ksp, "c");
107 minlimit = get_kstat_value(ksp, "c_min");
108 maxlimit = get_kstat_value(ksp, "c_max");
110 demand_data_hits = get_kstat_value(ksp, "demand_data_hits");
111 demand_metadata_hits = get_kstat_value(ksp, "demand_metadata_hits");
112 prefetch_data_hits = get_kstat_value(ksp, "prefetch_data_hits");
113 prefetch_metadata_hits = get_kstat_value(ksp, "prefetch_metadata_hits");
115 demand_data_misses = get_kstat_value(ksp, "demand_data_misses");
116 demand_metadata_misses = get_kstat_value(ksp, "demand_metadata_misses");
117 prefetch_data_misses = get_kstat_value(ksp, "prefetch_data_misses");
118 prefetch_metadata_misses = get_kstat_value(ksp, "prefetch_metadata_misses");
120 hits = get_kstat_value(ksp, "hits");
121 misses = get_kstat_value(ksp, "misses");
123 l2_size = get_kstat_value(ksp, "l2_size");
124 l2_read_bytes = get_kstat_value(ksp, "l2_read_bytes");
125 l2_write_bytes = get_kstat_value(ksp, "l2_write_bytes");
126 l2_hits = get_kstat_value(ksp, "l2_hits");
127 l2_misses = get_kstat_value(ksp, "l2_misses");
130 za_submit_size (arcsize, targetsize, minlimit, maxlimit);
131 za_submit_gauge ("arc_l2_size", "", l2_size);
133 za_submit_counts ("hits", demand_data_hits, demand_metadata_hits,
134 prefetch_data_hits, prefetch_metadata_hits);
135 za_submit_counts ("misses", demand_data_misses, demand_metadata_misses,
136 prefetch_data_misses, prefetch_metadata_misses);
138 za_submit_gauge ("arc_ratio", "L1", hits / (hits + misses));
139 za_submit_gauge ("arc_ratio", "L2", l2_hits / (l2_hits + l2_misses));
141 za_submit_bytes (l2_read_bytes, l2_write_bytes);
146 static int za_init (void) /* {{{ */
150 /* kstats chain already opened by update_kstat (using *kc), verify everything went fine. */
153 ERROR ("zfs_arc plugin: kstat chain control structure not available.");
158 } /* }}} int za_init */
160 void module_register (void)
162 plugin_register_init ("zfs_arc", za_init);
163 plugin_register_read ("zfs_arc", za_read);
164 } /* void module_register */
166 /* vmi: set sw=8 noexpandtab fdm=marker : */