Mercurial > archived > louis > perso > liblxcstats
annotate lxcstats.h @ 9:6f2e13f5fcfd
Add the memory probe
author | Louis Opter <louis@dotcloud.com> |
---|---|
date | Sun, 02 Jan 2011 01:50:27 +0100 |
parents | 8339ab15527d |
children | cff6be97dae1 |
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_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_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 <stdint.h> |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
5 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
6 /** |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
7 * Opaque structure used as a context for all liblxcst functions. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
8 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
9 typedef struct _lxcst_controller lxcst_handle; |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
10 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
11 /** |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
12 * This structure contains available statistics on a container. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
13 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
14 struct lxcst { |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
15 char *name; /*< Name of the container */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
16 char *cgroup_dir;/*< cgroup directory of the container */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
17 struct { |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
18 uint32_t user; /*< CPU time spent in userland */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
19 uint32_t system; /*< CPU time spent in kernelland */ |
3
2cb8a6cbe468
cpuacct: convert per cpu usage from nanoseconds to jiffies
Louis Opter <louis@dotcloud.com>
parents:
0
diff
changeset
|
20 uint32_t *percpu; /*< CPU time per CPU (zero-terminated array or NULL) */ |
2cb8a6cbe468
cpuacct: convert per cpu usage from nanoseconds to jiffies
Louis Opter <louis@dotcloud.com>
parents:
0
diff
changeset
|
21 } cpuacct; /*< CPU accounting in USER_HZ */ |
9 | 22 struct { |
23 uint64_t used; /*< RAM used by applications */ | |
24 uint64_t mapped; /*< RAM used for mapped file (includes tmpfs/shmem) */ | |
25 uint64_t cached; /*< RAM cached by the kernel */ | |
26 uint64_t swapped; /*< SWAP used */ | |
27 } memory; /*< Memory accounting in bytes */ | |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
28 }; |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
29 |
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 * This structure contains globals statistics on LXC. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
32 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
33 * Note: see how lxc-info gets these infos. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
34 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
35 struct lxcst_globals { |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
36 uint16_t running_containers; |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
37 uint16_t stopped_containers; |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
38 }; |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
39 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
40 /** |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
41 * @brief Initialize the library. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
42 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
43 * @return A pointer to an opaque structure which can be free'd with free |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
44 * or NULL on failure with errno set. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
45 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
46 * @see lxcst_close |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
47 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
48 lxcst_handle *lxcst_open(void); |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
49 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
50 /** |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
51 * @brief Close the library. |
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 * @param [in] hdl The pointer returned by lxcst_open. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
54 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
55 * @return 0 on success, -1 if an error occured with errno set. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
56 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
57 int lxcst_close(lxcst_handle *hdl); |
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 /** |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
60 * @brief Collect statistics on all containers. |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
61 * |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
62 * Walk the cgroup pseudo filesystem and get statistics for all found |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
63 * containers. Also refresh the global statistics struture. |
0
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 * @param [in] hdl The pointer returned by lxcst_handle. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
66 * @param [in] cb A function pointer to a callback which takes a pointer to an |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
67 * user context and a pointer to lxcst structure. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
68 * @param [in] ctx A pointer to an user defined variable which will be used as |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
69 * an argument to the callback. If the callback returns non zero |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
70 * lxcst_span_containers stops and return with -1 with errno set to EINTR. |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
71 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
72 * @return 0 on success, -1 on error with errno set. |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
73 * |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
74 * @see lxcst_globals_statistics |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
75 * @see struct lxcst |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
76 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
77 int lxcst_span_containers(lxcst_handle *hdl, int (*cb)(void *, const struct lxcst *), void *ctx); |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
78 |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
79 /** |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
80 * @brief Get a copy of the global LXC statistics object. |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
81 * |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
82 * @param [out] sb A pointer to a struct lxcst_globals. |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
83 * |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
84 * @see struct lxcst_globals |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
85 * @see lxcst_span_containers |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
86 */ |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
87 void lxcst_globals_statistics(struct lxcst_globals *sb); |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
88 |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
89 #endif |