Mercurial > archived > louis > perso > liblxcstats
annotate lxcstats.h @ 11:cff6be97dae1
Add a mainpage for the doxygen documentation
author | Louis Opter <kalessin@kalessin.fr> |
---|---|
date | Fri, 07 Jan 2011 20:53:10 +0100 |
parents | 6f2e13f5fcfd |
children | dbf24a82f625 |
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 /** |
11
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
7 * @mainpage liblxcstats API Reference |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
8 * |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
9 * @section sec_about About |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
10 * |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
11 * The liblxcstats returns resources usage statistics on the LXC Containers |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
12 * found on your system in a convenient data structure. LXC, Linux Containers, |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
13 * are like chroots on steroids. |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
14 * |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
15 * LXC uses the cgroup Linux kernel feature. Unlike other software |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
16 * virtualization technique (such as OpenVZ), LXC works on a vanilla Linux |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
17 * kernel. |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
18 * |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
19 * The code assumes that the cgroup hierarchy has been created by LXC. In the |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
20 * future this library could become a generic cgroup statistics library. |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
21 * |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
22 * This library is used to implement the LXC plugin for Collectd. |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
23 * |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
24 * @section see_also See Also |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
25 * |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
26 * - <a href="http://lxc.sourceforge.net/">LXC Containers</a>; |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
27 * - <a href="http://collectd.org/">Collectd</a>. |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
28 */ |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
29 |
cff6be97dae1
Add a mainpage for the doxygen documentation
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
30 /** |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
31 * 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
|
32 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
33 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
|
34 |
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 * 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
|
37 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
38 struct lxcst { |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
39 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
|
40 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
|
41 struct { |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 } cpuacct; /*< CPU accounting in USER_HZ */ |
9 | 46 struct { |
47 uint64_t used; /*< RAM used by applications */ | |
48 uint64_t mapped; /*< RAM used for mapped file (includes tmpfs/shmem) */ | |
49 uint64_t cached; /*< RAM cached by the kernel */ | |
50 uint64_t swapped; /*< SWAP used */ | |
51 } 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
|
52 }; |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
53 |
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 * 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
|
56 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
57 * 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
|
58 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
59 struct lxcst_globals { |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
60 uint16_t running_containers; |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
61 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
|
62 }; |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
63 |
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 * @brief Initialize the library. |
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 * @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
|
68 * 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
|
69 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
70 * @see lxcst_close |
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 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
|
73 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
74 /** |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
75 * @brief Close the library. |
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 * @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
|
78 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
79 * @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
|
80 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
81 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
|
82 |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
83 /** |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
84 * @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
|
85 * |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
86 * 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
|
87 * 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
|
88 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
89 * @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
|
90 * @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
|
91 * 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
|
92 * @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
|
93 * 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
|
94 * 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
|
95 * |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
96 * @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
|
97 * |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
98 * @see lxcst_globals_statistics |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
99 * @see struct lxcst |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
100 */ |
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
101 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
|
102 |
7
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
103 /** |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
104 * @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
|
105 * |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
106 * @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
|
107 * |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
108 * @see struct lxcst_globals |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
109 * @see lxcst_span_containers |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
110 */ |
8339ab15527d
Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents:
3
diff
changeset
|
111 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
|
112 |
0
6ce4443e7545
Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff
changeset
|
113 #endif |