Mercurial > archived > louis > perso > liblxcstats
annotate _lxcstats.h @ 7:8339ab15527d
Add running/stopped containers global statistics and refactor some things
author | Louis Opter <louis@dotcloud.com> |
---|---|
date | Sat, 01 Jan 2011 17:46:40 +0100 |
parents | e2b88f50e136 |
children |
rev | line source |
---|---|
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
1 #ifndef _LXC_STATS_PRIV_H_ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
2 # define _LXC_STATS_PRIV_H_ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
3 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
4 # include "compat/compat.h" |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
5 # include "probes/probes.h" |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
6 |
6
e2b88f50e136
cpuacct: replace strtoll by strtoul and replace sscanf by strsplit + strtoul
Louis Opter <louis@dotcloud.com>
parents:
4
diff
changeset
|
7 # define NSEC_PER_SEC 1000000000L |
e2b88f50e136
cpuacct: replace strtoll by strtoul and replace sscanf by strsplit + strtoul
Louis Opter <louis@dotcloud.com>
parents:
4
diff
changeset
|
8 |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
9 # define LXC_DIR "/var/lib/lxc/" |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
10 |
6
e2b88f50e136
cpuacct: replace strtoll by strtoul and replace sscanf by strsplit + strtoul
Louis Opter <louis@dotcloud.com>
parents:
4
diff
changeset
|
11 # define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) |
3
2cb8a6cbe468
cpuacct: convert per cpu usage from nanoseconds to jiffies
Louis Opter <louis@dotcloud.com>
parents:
0
diff
changeset
|
12 |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
13 struct dirent; |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
14 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
15 /** |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
16 * Store all informations needed to get statistics from a cgroup |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
17 * hierarchy. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
18 */ |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
19 struct _lxcst_controller { |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
20 char *cgroup_dir; /**< Mount point of the cgroup hierarchy. */ |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
21 const char *lxc_dir; /**< LXC configuration directory (LXC_DIR). */ |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
22 }; |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
23 |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
24 extern struct lxcst_globals _lxcst_globals; |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
25 |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
26 /** |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
27 * Allocate a new lxcst structure for the given container. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
28 */ |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
29 struct lxcst *_lxcst_container_new(const struct _lxcst_controller *, const char *); |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
30 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
31 /** |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
32 * Free a lxcst structure. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
33 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
34 void _lxcst_container_delete(struct lxcst *); |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
35 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
36 /** |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
37 * Get the total number of LXC containers on this machine. |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
38 */ |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
39 int _lxcst_container_count(const struct _lxcst_controller *ct); |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
40 |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
41 /** |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
42 * Get statistics on a container. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
43 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
44 int _lxcst_container_read_infos(struct lxcst *); |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
45 |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
46 /** |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
47 * Reset the global statistics structure. |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
48 */ |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
49 void _lxcst_globals_reset(void); |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
50 |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
51 char *_lxcst_join_path(char *, size_t , const char *, const char *); |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
52 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
53 /** |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
54 * @return true if the given path is a directory. |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
55 */ |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
6
diff
changeset
|
56 int _lxcst_isdir(const char *); |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
57 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
58 /** |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
59 * Allocate a buffer and read an entire file in it. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
60 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
61 * @param [in] path Path to the file to read |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
62 * @param [out] content A pointer to a pointer which will hold the allocated |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
63 * buffer. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
64 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
65 * @return The size of the buffer on sucess, -1 with errno set otherwise. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
66 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
67 ssize_t _lxcst_read_file(const char *path, char **content); |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
68 |
4
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
69 /** |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
70 * Split a string around spaces (defined by isspace()). |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
71 * |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
72 * @param [in] str The string to split, spaces are erased with '\0'. |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
73 * @param [out] fields An array of string, each entry will point to a word of |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
74 * the string. |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
75 * @param [in] nfields Number of entries into the fields array. |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
76 * |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
77 * @return The number of fields found. |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
78 */ |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
79 int _lxcst_strsplit(char *str, char **fields, size_t nfields); |
50215911acb3
Add a strsplit() function and stop to build probes into a separate library
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
80 |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
81 #endif |