2 * collectd - src/fscache.c
3 * Copyright (C) 2009 Edward "Koko" Konetzko
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 * Edward "Koko" Konetzko <konetzed at quixoticagony.com>
26 #include <stdio.h> /* a header needed for FILE */
27 #include <string.h> /* a header needed for scanf function */
28 #include <stdlib.h> /* used for atoi */
32 # error "This module only supports the Linux implementation of fscache"
38 see /proc/fs/fscache/stats
39 see Documentation/filesystems/caching/fscache.txt in linux kernel >= 2.6.30
41 This shows counts of a number of events that can happen in FS-Cache:
44 ======= ======= =======================================================
45 Cookies idx=N Number of index cookies allocated
46 dat=N Number of data storage cookies allocated
47 spc=N Number of special cookies allocated
48 Objects alc=N Number of objects allocated
49 nal=N Number of object allocation failures
50 avl=N Number of objects that reached the available state
51 ded=N Number of objects that reached the dead state
52 ChkAux non=N Number of objects that didn't have a coherency check
53 ok=N Number of objects that passed a coherency check
54 upd=N Number of objects that needed a coherency data update
55 obs=N Number of objects that were declared obsolete
56 Pages mrk=N Number of pages marked as being cached
57 unc=N Number of uncache page requests seen
58 Acquire n=N Number of acquire cookie requests seen
59 nul=N Number of acq reqs given a NULL parent
60 noc=N Number of acq reqs rejected due to no cache available
61 ok=N Number of acq reqs succeeded
62 nbf=N Number of acq reqs rejected due to error
63 oom=N Number of acq reqs failed on ENOMEM
64 Lookups n=N Number of lookup calls made on cache backends
65 neg=N Number of negative lookups made
66 pos=N Number of positive lookups made
67 crt=N Number of objects created by lookup
68 Updates n=N Number of update cookie requests seen
69 nul=N Number of upd reqs given a NULL parent
70 run=N Number of upd reqs granted CPU time
71 Relinqs n=N Number of relinquish cookie requests seen
72 nul=N Number of rlq reqs given a NULL parent
73 wcr=N Number of rlq reqs waited on completion of creation
74 AttrChg n=N Number of attribute changed requests seen
75 ok=N Number of attr changed requests queued
76 nbf=N Number of attr changed rejected -ENOBUFS
77 oom=N Number of attr changed failed -ENOMEM
78 run=N Number of attr changed ops given CPU time
79 Allocs n=N Number of allocation requests seen
80 ok=N Number of successful alloc reqs
81 wt=N Number of alloc reqs that waited on lookup completion
82 nbf=N Number of alloc reqs rejected -ENOBUFS
83 ops=N Number of alloc reqs submitted
84 owt=N Number of alloc reqs waited for CPU time
85 Retrvls n=N Number of retrieval (read) requests seen
86 ok=N Number of successful retr reqs
87 wt=N Number of retr reqs that waited on lookup completion
88 nod=N Number of retr reqs returned -ENODATA
89 nbf=N Number of retr reqs rejected -ENOBUFS
90 int=N Number of retr reqs aborted -ERESTARTSYS
91 oom=N Number of retr reqs failed -ENOMEM
92 ops=N Number of retr reqs submitted
93 owt=N Number of retr reqs waited for CPU time
94 Stores n=N Number of storage (write) requests seen
95 ok=N Number of successful store reqs
96 agn=N Number of store reqs on a page already pending storage
97 nbf=N Number of store reqs rejected -ENOBUFS
98 oom=N Number of store reqs failed -ENOMEM
99 ops=N Number of store reqs submitted
100 run=N Number of store reqs granted CPU time
101 Ops pend=N Number of times async ops added to pending queues
102 run=N Number of times async ops given CPU time
103 enq=N Number of times async ops queued for processing
104 dfr=N Number of async ops queued for deferred release
105 rel=N Number of async ops released
106 gc=N Number of deferred-release async ops garbage collected
108 63 events to collect in 13 groups
110 static void fscache_submit (const char *section, const char *name,
113 value_list_t vl = VALUE_LIST_INIT;
118 sstrncpy(vl.host, hostname_g, sizeof (vl.host));
119 sstrncpy(vl.plugin, "fscache", sizeof (vl.plugin));
120 sstrncpy(vl.plugin_instance, section, sizeof (vl.plugin_instance));
121 sstrncpy(vl.type, "fscache_stat", sizeof(vl.type));
122 sstrncpy(vl.type_instance, name, sizeof(vl.type_instance));
124 plugin_dispatch_values (&vl);
127 static void fscache_read_stats_file (FILE *fh)
129 char section[DATA_MAX_NAME_LEN];
132 char linebuffer[BUFSIZE];
135 * cat /proc/fs/fscache/stats
136 * FS-Cache statistics
137 * Cookies: idx=2 dat=0 spc=0
138 * Objects: alc=0 nal=0 avl=0 ded=0
139 * ChkAux : non=0 ok=0 upd=0 obs=0
140 * Pages : mrk=0 unc=0
141 * Acquire: n=2 nul=0 noc=0 ok=2 nbf=0 oom=0
142 * Lookups: n=0 neg=0 pos=0 crt=0
143 * Updates: n=0 nul=0 run=0
144 * Relinqs: n=0 nul=0 wcr=0
145 * AttrChg: n=0 ok=0 nbf=0 oom=0 run=0
146 * Allocs : n=0 ok=0 wt=0 nbf=0
147 * Allocs : ops=0 owt=0
148 * Retrvls: n=0 ok=0 wt=0 nod=0 nbf=0 int=0 oom=0
149 * Retrvls: ops=0 owt=0
150 * Stores : n=0 ok=0 agn=0 nbf=0 oom=0
151 * Stores : ops=0 run=0
152 * Ops : pend=0 run=0 enq=0
153 * Ops : dfr=0 rel=0 gc=0
156 /* Read file line by line */
157 while (fgets (linebuffer, sizeof (linebuffer), fh) != NULL)
164 /* Find the colon and replace it with a null byte */
165 lineptr = strchr (linebuffer, ':');
171 /* Copy and clean up the section name */
172 sstrncpy (section, linebuffer, sizeof (section));
173 section_len = strlen (section);
174 while ((section_len > 0) && isspace ((int) section[section_len - 1]))
177 section[section_len] = 0;
179 if (section_len == 0)
182 fields_num = strsplit (lineptr, fields, STATIC_ARRAY_SIZE (fields));
186 for (i = 0; i < fields_num; i++)
189 char *field_value_str;
190 value_t field_value_cnt;
193 field_name = fields[i];
194 assert (field_name != NULL);
196 field_value_str = strchr (field_name, '=');
197 if (field_value_str == NULL)
199 *field_value_str = 0;
202 status = parse_value (field_value_str, &field_value_cnt,
207 fscache_submit (section, field_name, field_value_cnt);
209 } /* while (fgets) */
210 } /* void fscache_read_stats_file */
212 static int fscache_read (void){
214 fh = fopen("/proc/fs/fscache/stats", "r");
216 fscache_read_stats_file(fh);
220 printf("cant open file\n");
226 void module_register (void)
228 plugin_register_read ("fscache", fscache_read);
229 } /* void module_register */
231 /* vim: set sw=4 sts=4 et : */