From 4b4eee900b167cfdf17528e70c9c0659eb0329b0 Mon Sep 17 00:00:00 2001 From: Marc Fournier Date: Wed, 21 Aug 2013 16:22:32 +0200 Subject: [PATCH] cgroups: don't fail parsing when colon not found The format of cpuacct.stat seems to not always have a colon as separator. It appears to *not* have the colon at least on debian's kernel 3.2.41 and 3.2.35, as well as on RHEL6 with 2.6.32. All of them have decent support for cgroups/lxc, and the cgroups plugin fails to work with them without this patch. Also, looking at other implementations shows that they *don't* expect a colon: https://bitbucket.org/dotcloud/liblxcstats/src/2558b4fbbf589c609895b0badbfc7d413466d716/probes/cpuacct.c?at=default#cl-71 https://github.com/BrightcoveOS/Diamond/blob/master/src/collectors/cpuacct_cgroup/cpuacct_cgroup.py#L55 --- src/cgroups.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cgroups.c b/src/cgroups.c index ffb1740a..061aa326 100644 --- a/src/cgroups.c +++ b/src/cgroups.c @@ -111,6 +111,11 @@ static int read_cpuacct_procs (const char *dirname, char const *cgroup_name, * * user: 12345 * system: 23456 + * + * Or: + * + * user 12345 + * system 23456 */ strstripnewline (buf); numfields = strsplit (buf, fields, STATIC_ARRAY_SIZE (fields)); @@ -122,10 +127,9 @@ static int read_cpuacct_procs (const char *dirname, char const *cgroup_name, if (key_len < 2) continue; - /* Strip colon off the first column */ - if (key[key_len - 1] != ':') - continue; - key[key_len - 1] = 0; + /* Strip colon off the first column, if found */ + if (key[key_len - 1] == ':') + key[key_len - 1] = 0; status = parse_value (fields[1], &value, DS_TYPE_DERIVE); if (status != 0) -- 2.30.2