view lxcstats.h @ 0:6ce4443e7545

Add the draft of an API to collect statistics on LXC
author Louis Opter <kalessin@kalessin.fr>
date Wed, 29 Dec 2010 23:28:14 +0100
parents
children 2cb8a6cbe468
line wrap: on
line source

#ifndef _LXC_STATS_H_
# define _LXC_STATS_H_

# include <stdint.h>

/**
 * Opaque structure used as a context for all liblxcst functions.
 */
typedef struct _lxcst_controller    lxcst_handle;

/**
 * This structure contains available statistics on a container.
 */
struct              lxcst {
    char            *name;      /*< Name of the container                               */
    char            *cgroup_dir;/*< cgroup directory of the container                   */
    struct  {
        uint32_t    user;       /*< CPU time spent in userland                          */
        uint32_t    system;     /*< CPU time spent in kernelland                        */
        uint64_t    *percpu;    /*< CPU time per CPU (zero-terminated array or NULL)    */
    }               cpuacct;
};

/**
 * This structure contains globals statistics on LXC.
 *
 * Note: see how lxc-info gets these infos.
 */
struct          lxcst_globals {
    uint32_t    running_containers;
    uint32_t    stopped_containers;
};

/**
 * @brief Initialize the library.
 *
 * @return A pointer to an opaque structure which can be free'd with free
 * or NULL on failure with errno set.
 *
 * @see lxcst_close
 */
lxcst_handle    *lxcst_open(void);

/**
 * @brief Close the library.
 *
 * @param [in] hdl The pointer returned by lxcst_open.
 *
 * @return 0 on success, -1 if an error occured with errno set.
 */
int             lxcst_close(lxcst_handle *hdl);

/**
 * @brief Collect statistic on all containers.
 *
 * @param [in] hdl The pointer returned by lxcst_handle.
 * @param [in] cb A function pointer to a callback which takes a pointer to an
 * user context and a pointer to lxcst structure.
 * @param [in] ctx A pointer to an user defined variable which will be used as
 * an argument to the callback. If the callback returns non zero
 * lxcst_span_containers stops and return with -1 with errno set to EINTR.
 *
 * @return 0 on success, -1 on error with errno set.
 */
int             lxcst_span_containers(lxcst_handle *hdl, int (*cb)(void *, const struct lxcst *), void *ctx);

#endif