annotate tests/span_containers.c @ 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 6ce4443e7545
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include <err.h>
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
2 #include <stdio.h>
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
3 #include <stdlib.h>
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
4
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
5 #include "lxcstats.h"
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 unsigned int n = 0;
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 int
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
10 cb(void *ctx, const struct lxcst *container)
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 if (ctx)
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
13 errx(EXIT_FAILURE, "ctx must be NULL");
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 if (!container)
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
16 errx(EXIT_FAILURE, "container must not be NULL");
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
17
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
18 ++n;
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
19
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
20 return (0); /* continue */
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
21 }
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 int
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
24 main(int argc, char *argv[])
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
25 {
7
8339ab15527d Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents: 0
diff changeset
26 lxcst_handle *hdl;
8339ab15527d Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents: 0
diff changeset
27 struct lxcst_globals globals;
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 hdl = lxcst_open();
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
30 if (!hdl)
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
31 err(EXIT_FAILURE, "lxcst_open failed");
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 lxcst_span_containers(hdl, &cb, NULL);
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 lxcst_close(hdl);
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
36
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
37 printf("%s: spanned %d containers.\n", *argv, n);
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
38
7
8339ab15527d Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents: 0
diff changeset
39 lxcst_globals_statistics(&globals);
8339ab15527d Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents: 0
diff changeset
40
8339ab15527d Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents: 0
diff changeset
41 if (globals.running_containers != n)
8339ab15527d Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents: 0
diff changeset
42 errx(EXIT_FAILURE, "running_containers != spanned containers");
8339ab15527d Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents: 0
diff changeset
43
8339ab15527d Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents: 0
diff changeset
44 printf("%s: %d running containers, %d stopped containers.\n", *argv, globals.running_containers, globals.stopped_containers);
8339ab15527d Add running/stopped containers global statistics and refactor some things
Louis Opter <louis@dotcloud.com>
parents: 0
diff changeset
45
0
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
46 return (EXIT_SUCCESS);
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
47 (void)argc;
6ce4443e7545 Add the draft of an API to collect statistics on LXC
Louis Opter <kalessin@kalessin.fr>
parents:
diff changeset
48 }