2 * collectd - src/zfs_arc.c
3 * Copyright (C) 2009 Anthony Dewhurst
4 * Copyright (C) 2012 Aurelien Rougemont
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; only version 2 of the License is applicable.
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 * Anthony Dewhurst <dewhurst at gmail>
21 * Aurelien Rougemont <beorn at gandi.net>
32 extern kstat_ctl_t *kc;
34 static void za_submit (const char* type, const char* type_instance, value_t* values, int values_len)
36 value_list_t vl = VALUE_LIST_INIT;
39 vl.values_len = values_len;
41 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
42 sstrncpy (vl.plugin, "zfs_arc", sizeof (vl.plugin));
43 sstrncpy (vl.type, type, sizeof (vl.type));
44 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
46 plugin_dispatch_values (&vl);
49 static void za_submit_gauge (const char* type, const char* type_instance, gauge_t value)
54 za_submit (type, type_instance, &vv, 1);
57 static int za_read_derive (kstat_t *ksp, const char *kstat_value,
58 const char *type, const char *type_instance)
63 tmp = get_kstat_value (ksp, (char *)kstat_value);
66 ERROR ("zfs_arc plugin: Reading kstat value \"%s\" failed.", kstat_value);
70 v.derive = (derive_t) tmp;
71 za_submit (type, type_instance, /* values = */ &v, /* values_num = */ 1);
75 static int za_read_gauge (kstat_t *ksp, const char *kstat_value,
76 const char *type, const char *type_instance)
81 tmp = get_kstat_value (ksp, (char *)kstat_value);
84 ERROR ("zfs_arc plugin: Reading kstat value \"%s\" failed.", kstat_value);
88 v.gauge = (gauge_t) tmp;
89 za_submit (type, type_instance, /* values = */ &v, /* values_num = */ 1);
93 static void za_submit_ratio (const char* type_instance, gauge_t hits, gauge_t misses)
97 if (!isfinite (hits) || (hits < 0.0))
99 if (!isfinite (misses) || (misses < 0.0))
102 if ((hits != 0.0) || (misses != 0.0))
103 ratio = hits / (hits + misses);
105 za_submit_gauge ("cache_ratio", type_instance, ratio);
108 static int za_read (void)
110 gauge_t arc_hits, arc_misses, l2_hits, l2_misses;
114 get_kstat (&ksp, "zfs", 0, "arcstats");
117 ERROR ("zfs_arc plugin: Cannot find zfs:0:arcstats kstat.");
122 za_read_gauge (ksp, "size", "cache_size", "arc");
123 za_read_gauge (ksp, "l2_size", "cache_size", "L2");
126 za_read_derive (ksp, "allocated","cache_operation", "allocated");
127 za_read_derive (ksp, "deleted", "cache_operation", "deleted");
128 za_read_derive (ksp, "stolen", "cache_operation", "stolen");
130 /* Issue indicators */
131 za_read_derive (ksp, "mutex_miss", "mutex_operation", "miss");
132 za_read_derive (ksp, "hash_collisions", "hash_collisions", "");
135 za_read_derive (ksp, "evict_l2_cached", "cache_eviction", "cached");
136 za_read_derive (ksp, "evict_l2_eligible", "cache_eviction", "eligible");
137 za_read_derive (ksp, "evict_l2_ineligible", "cache_eviction", "ineligible");
140 za_read_derive (ksp, "demand_data_hits", "cache_result", "demand_data-hit");
141 za_read_derive (ksp, "demand_metadata_hits", "cache_result", "demand_metadata-hit");
142 za_read_derive (ksp, "prefetch_data_hits", "cache_result", "prefetch_data-hit");
143 za_read_derive (ksp, "prefetch_metadata_hits", "cache_result", "prefetch_metadata-hit");
144 za_read_derive (ksp, "demand_data_misses", "cache_result", "demand_data-miss");
145 za_read_derive (ksp, "demand_metadata_misses", "cache_result", "demand_metadata-miss");
146 za_read_derive (ksp, "prefetch_data_misses", "cache_result", "prefetch_data-miss");
147 za_read_derive (ksp, "prefetch_metadata_misses", "cache_result", "prefetch_metadata-miss");
150 arc_hits = (gauge_t) get_kstat_value(ksp, "hits");
151 arc_misses = (gauge_t) get_kstat_value(ksp, "misses");
152 l2_hits = (gauge_t) get_kstat_value(ksp, "l2_hits");
153 l2_misses = (gauge_t) get_kstat_value(ksp, "l2_misses");
155 za_submit_ratio ("arc", arc_hits, arc_misses);
156 za_submit_ratio ("L2", l2_hits, l2_misses);
159 l2_io[0].derive = get_kstat_value(ksp, "l2_read_bytes");
160 l2_io[1].derive = get_kstat_value(ksp, "l2_write_bytes");
162 za_submit ("io_octets", "L2", l2_io, /* num values = */ 2);
167 static int za_init (void) /* {{{ */
169 /* kstats chain already opened by update_kstat (using *kc), verify everything went fine. */
172 ERROR ("zfs_arc plugin: kstat chain control structure not available.");
177 } /* }}} int za_init */
179 void module_register (void)
181 plugin_register_init ("zfs_arc", za_init);
182 plugin_register_read ("zfs_arc", za_read);
183 } /* void module_register */
185 /* vmi: set sw=8 noexpandtab fdm=marker : */