Initial revision

This commit is contained in:
Doug MacEachern committed 2004-06-21 22:37:04 +00:00
1 parent 1a7957fb1e
commit dffe0da855
207 files changed
+34390

No files matched your search

+489
View File
@@ -0,0 +1,489 @@
#ifndef SIGAR_H
#define SIGAR_H
/* System Information Gatherer And Reporter */
#include <limits.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(WIN32)
typedef unsigned __int64 sigar_uint64_t;
#elif ULONG_MAX > 4294967295UL
typedef unsigned long sigar_uint64_t;
#else
typedef unsigned long long sigar_uint64_t;
#endif
#define SIGAR_OK 0
#define SIGAR_START_ERROR 20000
#define SIGAR_ENOTIMPL (SIGAR_START_ERROR + 1)
#define SIGAR_OS_START_ERROR (SIGAR_START_ERROR*2)
#ifdef WIN32
# define SIGAR_DECLARE(type) \
__declspec(dllexport) type __stdcall
#else
# define SIGAR_DECLARE(type) type
#endif
#if defined(PATH_MAX)
# define SIGAR_PATH_MAX PATH_MAX
#elif defined(MAXPATHLEN)
# define SIGAR_PATH_MAX MAXPATHLEN
#else
# define SIGAR_PATH_MAX 8192
#endif
#ifdef WIN32
typedef sigar_uint64_t sigar_pid_t;
typedef unsigned long sigar_uid_t;
typedef unsigned long sigar_gid_t;
#else
#include <sys/types.h>
typedef pid_t sigar_pid_t;
typedef uid_t sigar_uid_t;
typedef gid_t sigar_gid_t;
#endif
typedef struct sigar_t sigar_t;
SIGAR_DECLARE(int) sigar_open(sigar_t **sigar);
SIGAR_DECLARE(int) sigar_close(sigar_t *sigar);
SIGAR_DECLARE(sigar_pid_t) sigar_pid_get(sigar_t *sigar);
SIGAR_DECLARE(int) sigar_proc_kill(sigar_pid_t pid, int signum);
SIGAR_DECLARE(char *) sigar_strerror(sigar_t *sigar, int err);
/* system memory info */
typedef struct {
sigar_uint64_t
ram,
total,
used,
free,
shared,
buffer,
cached;
} sigar_mem_t;
SIGAR_DECLARE(int) sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem);
typedef struct {
sigar_uint64_t
total,
used,
free;
} sigar_swap_t;
SIGAR_DECLARE(int) sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap);
typedef struct {
sigar_uint64_t
user,
sys,
nice,
idle,
total;
} sigar_cpu_t;
SIGAR_DECLARE(int) sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu);
typedef struct {
unsigned long number;
unsigned long size;
sigar_cpu_t *data;
} sigar_cpu_list_t;
SIGAR_DECLARE(int) sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist);
SIGAR_DECLARE(int) sigar_cpu_list_destroy(sigar_t *sigar,
sigar_cpu_list_t *cpulist);
typedef struct {
char vendor[128];
char model[128];
int mhz;
sigar_uint64_t cache_size;
} sigar_cpu_info_t;
typedef struct {
unsigned long number;
unsigned long size;
sigar_cpu_info_t *data;
} sigar_cpu_infos_t;
SIGAR_DECLARE(int) sigar_cpu_infos_get(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos);
SIGAR_DECLARE(int) sigar_cpu_infos_destroy(sigar_t *sigar,
sigar_cpu_infos_t *cpu_infos);
typedef struct {
double uptime;
double idletime;
} sigar_uptime_t;
SIGAR_DECLARE(int) sigar_uptime_get(sigar_t *sigar,
sigar_uptime_t *uptime);
SIGAR_DECLARE(int) sigar_uptime_string(sigar_t *sigar,
sigar_uptime_t *uptime,
char *buffer,
int buflen);
SIGAR_DECLARE(char *) sigar_format_size(sigar_uint64_t size, char *buf);
typedef struct {
double loadavg[3];
} sigar_loadavg_t;
SIGAR_DECLARE(int) sigar_loadavg_get(sigar_t *sigar,
sigar_loadavg_t *loadavg);
typedef struct {
unsigned long number;
unsigned long size;
sigar_pid_t *data;
} sigar_proc_list_t;
SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist);
SIGAR_DECLARE(int) sigar_proc_list_destroy(sigar_t *sigar,
sigar_proc_list_t *proclist);
typedef struct {
sigar_uint64_t total;
} sigar_proc_stat_t;
SIGAR_DECLARE(int) sigar_proc_stat_get(sigar_t *sigar,
sigar_proc_stat_t *procstat);
typedef struct {
sigar_uint64_t
size,
vsize,
resident,
share,
rss;
} sigar_proc_mem_t;
SIGAR_DECLARE(int) sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_mem_t *procmem);
typedef struct {
sigar_uid_t uid;
sigar_gid_t gid;
sigar_uid_t euid;
sigar_gid_t egid;
} sigar_proc_cred_t;
SIGAR_DECLARE(int) sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_cred_t *proccred);
#define SIGAR_CRED_NAME_MAX 512
typedef struct {
char user[SIGAR_CRED_NAME_MAX];
char group[SIGAR_CRED_NAME_MAX];
} sigar_proc_cred_name_t;
SIGAR_DECLARE(int)
sigar_proc_cred_name_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_cred_name_t *proccredname);
typedef struct {
sigar_uint64_t
start_time,
utime,
stime;
} sigar_proc_time_t;
SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_time_t *proctime);
#define SIGAR_PROC_NAME_LEN 128
typedef struct {
char name[SIGAR_PROC_NAME_LEN];
char state;
sigar_pid_t ppid;
int tty;
int priority;
int nice;
} sigar_proc_state_t;
SIGAR_DECLARE(int) sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_state_t *procstate);
typedef struct {
unsigned long number;
unsigned long size;
char **data;
} sigar_proc_args_t;
SIGAR_DECLARE(int) sigar_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_args_t *procargs);
SIGAR_DECLARE(int) sigar_proc_args_destroy(sigar_t *sigar,
sigar_proc_args_t *procargs);
typedef struct {
void *data; /* user data */
enum {
SIGAR_PROC_ENV_ALL,
SIGAR_PROC_ENV_KEY
} type;
/* used for SIGAR_PROC_ENV_KEY */
const char *key;
int klen;
int (*env_getter)(void *, const char *, int, char *, int);
} sigar_proc_env_t;
SIGAR_DECLARE(int) sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_env_t *procenv);
typedef struct {
sigar_uint64_t total;
/* XXX - which are files, sockets, etc. */
} sigar_proc_fd_t;
SIGAR_DECLARE(int) sigar_proc_fd_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_fd_t *procfd);
typedef struct {
char name[SIGAR_PATH_MAX+1];
char cwd[SIGAR_PATH_MAX+1];
char root[SIGAR_PATH_MAX+1];
} sigar_proc_exe_t;
SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_exe_t *procexe);
typedef enum {
SIGAR_FSTYPE_UNKNOWN,
SIGAR_FSTYPE_NONE,
SIGAR_FSTYPE_LOCAL_DISK,
SIGAR_FSTYPE_NETWORK,
SIGAR_FSTYPE_RAM_DISK,
SIGAR_FSTYPE_CDROM,
SIGAR_FSTYPE_SWAP,
SIGAR_FSTYPE_MAX
} sigar_file_system_type_e;
#define SIGAR_FS_NAME_LEN 64
typedef struct {
char dir_name[SIGAR_FS_NAME_LEN];
char dev_name[SIGAR_FS_NAME_LEN];
char type_name[SIGAR_FS_NAME_LEN]; /* e.g. "local" */
char sys_type_name[SIGAR_FS_NAME_LEN]; /* e.g. "ext3" */
sigar_file_system_type_e type;
unsigned long flags;
} sigar_file_system_t;
typedef struct {
unsigned long number;
unsigned long size;
sigar_file_system_t *data;
} sigar_file_system_list_t;
SIGAR_DECLARE(int)
sigar_file_system_list_get(sigar_t *sigar,
sigar_file_system_list_t *fslist);
SIGAR_DECLARE(int)
sigar_file_system_list_destroy(sigar_t *sigar,
sigar_file_system_list_t *fslist);
typedef struct {
sigar_uint64_t
total,
free,
avail,
files,
free_files;
double use_percent;
} sigar_file_system_usage_t;
SIGAR_DECLARE(int)
sigar_file_system_usage_get(sigar_t *sigar,
const char *dirname,
sigar_file_system_usage_t *fsusage);
typedef struct {
sigar_uint64_t
destination,
gateway,
flags,
refcnt,
use,
metric,
mask,
mtu,
window,
irtt;
char ifname[16];
} sigar_net_route_t;
typedef struct {
unsigned long number;
unsigned long size;
sigar_net_route_t *data;
} sigar_net_route_list_t;
SIGAR_DECLARE(int) sigar_net_route_list_get(sigar_t *sigar,
sigar_net_route_list_t *routelist);
SIGAR_DECLARE(int) sigar_net_route_list_destroy(sigar_t *sigar,
sigar_net_route_list_t *routelist);
/*
* platforms define most of these "standard" flags,
* but of course, with different values in some cases.
*/
#define SIGAR_IFF_UP 0x1
#define SIGAR_IFF_BROADCAST 0x2
#define SIGAR_IFF_DEBUG 0x4
#define SIGAR_IFF_LOOPBACK 0x8
#define SIGAR_IFF_POINTOPOINT 0x10
#define SIGAR_IFF_NOTRAILERS 0x20
#define SIGAR_IFF_RUNNING 0x40
#define SIGAR_IFF_NOARP 0x80
#define SIGAR_IFF_PROMISC 0x100
#define SIGAR_IFF_ALLMULTI 0x200
#define SIGAR_IFF_MULTICAST 0x800
#define SIGAR_NULL_HWADDR "00:00:00:00:00:00"
typedef struct {
char name[16];
char hwaddr[64];
sigar_uint64_t
address,
destination,
broadcast,
netmask,
flags,
mtu,
metric;
} sigar_net_interface_config_t;
SIGAR_DECLARE(int)
sigar_net_interface_config_get(sigar_t *sigar,
const char *name,
sigar_net_interface_config_t *ifconfig);
typedef struct {
sigar_uint64_t
/* received */
rx_packets,
rx_bytes,
rx_errors,
rx_dropped,
rx_overruns,
rx_frame,
/* transmitted */
tx_packets,
tx_bytes,
tx_errors,
tx_dropped,
tx_overruns,
tx_collisions,
tx_carrier;
} sigar_net_interface_stat_t;
SIGAR_DECLARE(int)
sigar_net_interface_stat_get(sigar_t *sigar,
const char *name,
sigar_net_interface_stat_t *ifstat);
typedef struct {
unsigned long number;
unsigned long size;
char **data;
} sigar_net_interface_list_t;
SIGAR_DECLARE(int)
sigar_net_interface_list_get(sigar_t *sigar,
sigar_net_interface_list_t *iflist);
SIGAR_DECLARE(int)
sigar_net_interface_list_destroy(sigar_t *sigar,
sigar_net_interface_list_t *iflist);
#define SIGAR_NETCONN_CLIENT 0x01
#define SIGAR_NETCONN_SERVER 0x02
#define SIGAR_NETCONN_TCP 0x10
#define SIGAR_NETCONN_UDP 0x20
#define SIGAR_NETCONN_RAW 0x40
#define SIGAR_NETCONN_UNIX 0x80
#ifndef INET6_ADDRSTRLEN
# define INET6_ADDRSTRLEN 46
#endif
typedef struct {
unsigned long local_port;
char local_address[INET6_ADDRSTRLEN];
unsigned long remote_port;
char remote_address[INET6_ADDRSTRLEN];
sigar_uid_t uid;
unsigned long inode;
int type;
} sigar_net_connection_t;
typedef struct {
unsigned long number;
unsigned long size;
sigar_net_connection_t *data;
} sigar_net_connection_list_t;
SIGAR_DECLARE(int)
sigar_net_connection_list_get(sigar_t *sigar,
sigar_net_connection_list_t *connlist,
int flags);
SIGAR_DECLARE(int)
sigar_net_connection_list_destroy(sigar_t *sigar,
sigar_net_connection_list_t *connlist);
SIGAR_DECLARE(const char *)sigar_net_connection_type_get(int type);
SIGAR_DECLARE(int) sigar_proc_port_get(sigar_t *sigar, unsigned long port,
sigar_pid_t *pid);
#define SIGAR_INET_ADDR_LEN (3 * 4 + 3 + 1)
SIGAR_DECLARE(int) sigar_inet_ntoa(sigar_t *sigar,
sigar_uint64_t address,
char *addr_str);
#define SIGAR_FQDN_LEN 512
SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen);
SIGAR_DECLARE(char *) sigar_password_get(const char *prompt);
#ifdef __cplusplus
}
#endif
#endif
+134
View File
@@ -0,0 +1,134 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#include "sigar.h"
typedef enum {
SIGAR_FILETYPE_NOFILE = 0, /**< no file type determined */
SIGAR_FILETYPE_REG, /**< a regular file */
SIGAR_FILETYPE_DIR, /**< a directory */
SIGAR_FILETYPE_CHR, /**< a character device */
SIGAR_FILETYPE_BLK, /**< a block device */
SIGAR_FILETYPE_PIPE, /**< a FIFO / pipe */
SIGAR_FILETYPE_LNK, /**< a symbolic link */
SIGAR_FILETYPE_SOCK, /**< a [unix domain] socket */
SIGAR_FILETYPE_UNKFILE /**< a file of some other unknown type */
} sigar_file_type_e;
#define SIGAR_UREAD 0x0400 /**< Read by user */
#define SIGAR_UWRITE 0x0200 /**< Write by user */
#define SIGAR_UEXECUTE 0x0100 /**< Execute by user */
#define SIGAR_GREAD 0x0040 /**< Read by group */
#define SIGAR_GWRITE 0x0020 /**< Write by group */
#define SIGAR_GEXECUTE 0x0010 /**< Execute by group */
#define SIGAR_WREAD 0x0004 /**< Read by others */
#define SIGAR_WWRITE 0x0002 /**< Write by others */
#define SIGAR_WEXECUTE 0x0001 /**< Execute by others */
typedef struct {
/** The access permissions of the file. Mimics Unix access rights. */
sigar_uint64_t permissions;
sigar_file_type_e type;
/** The user id that owns the file */
sigar_uid_t uid;
/** The group id that owns the file */
sigar_gid_t gid;
/** The inode of the file. */
sigar_uint64_t inode;
/** The id of the device the file is on. */
sigar_uint64_t device;
/** The number of hard links to the file. */
sigar_uint64_t nlink;
/** The size of the file */
sigar_uint64_t size;
/** The time the file was last accessed */
sigar_uint64_t atime;
/** The time the file was last modified */
sigar_uint64_t mtime;
/** The time the file was last changed */
sigar_uint64_t ctime;
} sigar_file_attrs_t;
typedef struct {
sigar_uint64_t total;
sigar_uint64_t files;
sigar_uint64_t subdirs;
sigar_uint64_t symlinks;
sigar_uint64_t chrdevs;
sigar_uint64_t blkdevs;
sigar_uint64_t sockets;
} sigar_dir_stat_t;
SIGAR_DECLARE(const char *)
sigar_file_attrs_type_string_get(sigar_file_type_e type);
SIGAR_DECLARE(int) sigar_file_attrs_get(sigar_t *sigar,
const char *file,
sigar_file_attrs_t *fileattrs);
SIGAR_DECLARE(int) sigar_link_attrs_get(sigar_t *sigar,
const char *file,
sigar_file_attrs_t *fileattrs);
SIGAR_DECLARE(int)sigar_file_attrs_mode_get(sigar_uint64_t permissions);
SIGAR_DECLARE(char *)
sigar_file_attrs_permissions_string_get(sigar_uint64_t permissions,
char *str);
SIGAR_DECLARE(int) sigar_dir_stat_get(sigar_t *sigar,
const char *dir,
sigar_dir_stat_t *dirstats);
+18
View File
@@ -0,0 +1,18 @@
#ifndef SIGAR_GETLINE_H
#define SIGAR_GETLINE_H
#include "sigar.h"
typedef int (*sigar_getline_completer_t)(char *, int, int *);
SIGAR_DECLARE(char *) sigar_getline(char *prompt);
SIGAR_DECLARE(void) sigar_getline_setwidth(int width);
SIGAR_DECLARE(void) sigar_getline_redraw(void);
SIGAR_DECLARE(void) sigar_getline_reset(void);
SIGAR_DECLARE(void) sigar_getline_windowchanged();
SIGAR_DECLARE(void) sigar_getline_histinit(char *file);
SIGAR_DECLARE(void) sigar_getline_histadd(char *buf);
SIGAR_DECLARE(int) sigar_getline_eof();
SIGAR_DECLARE(void) sigar_getline_completer_set(sigar_getline_completer_t func);
#endif /* SIGAR_GETLINE_H */
+49
View File
@@ -0,0 +1,49 @@
#ifndef SIGAR_LOG_H
#define SIGAR_LOG_H
#include <stdarg.h>
#define SIGAR_LOG_FATAL 0
#define SIGAR_LOG_ERROR 1
#define SIGAR_LOG_WARN 2
#define SIGAR_LOG_INFO 3
#define SIGAR_LOG_DEBUG 4
#define SIGAR_LOG_TRACE 5
#define SIGAR_LOG_IS_FATAL(sigar) \
(sigar->log_level >= SIGAR_LOG_FATAL)
#define SIGAR_LOG_IS_ERROR(sigar) \
(sigar->log_level >= SIGAR_LOG_ERROR)
#define SIGAR_LOG_IS_WARN(sigar) \
(sigar->log_level >= SIGAR_LOG_WARN)
#define SIGAR_LOG_IS_INFO(sigar) \
(sigar->log_level >= SIGAR_LOG_INFO)
#define SIGAR_LOG_IS_DEBUG(sigar) \
(sigar->log_level >= SIGAR_LOG_DEBUG)
#define SIGAR_LOG_IS_TRACE(sigar) \
(sigar->log_level >= SIGAR_LOG_TRACE)
typedef void (*sigar_log_impl_t)(sigar_t *, void *, int, char *);
SIGAR_DECLARE(void) sigar_log_printf(sigar_t *sigar, int level,
const char *format, ...);
SIGAR_DECLARE(void) sigar_log(sigar_t *sigar, int level, char *message);
SIGAR_DECLARE(void) sigar_log_impl_set(sigar_t *sigar, void *data,
sigar_log_impl_t impl);
SIGAR_DECLARE(void) sigar_log_impl_file(sigar_t *sigar, void *data,
int level, char *message);
SIGAR_DECLARE(int) sigar_log_level_get(sigar_t *sigar);
SIGAR_DECLARE(void) sigar_log_level_set(sigar_t *sigar, int level);
#endif /* SIGAR_LOG_H */
+193
View File
@@ -0,0 +1,193 @@
#ifndef SIGAR_PRIVATE_DOT_H
#define SIGAR_PRIVATE_DOT_H
#include "sigar_log.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifndef WIN32
#include <unistd.h>
#include <strings.h>
#endif
/* common to all os sigar_t's */
/* XXX: this is ugly; but don't want the same stuffs
* duplicated on 4 platforms and am too lazy to change
* sigar_t to the way it was originally where sigar_t was
* common and contained a sigar_os_t.
* feel free trav ;-)
*/
#define SIGAR_T_BASE \
int log_level; \
void *log_data; \
sigar_log_impl_t log_impl; \
unsigned int ncpu; \
unsigned long version; \
unsigned long boot_time; \
int ticks; \
sigar_pid_t pid; \
char errbuf[256]; \
char *ifconf_buf; \
int ifconf_len
#if defined(WIN32)
# define SIGAR_INLINE __inline
#elif defined(__GNUC__)
# define SIGAR_INLINE inline
#else
# define SIGAR_INLINE
#endif
#define SIGAR_ZERO(s) \
memset(s, '\0', sizeof(*(s)))
#define SIGAR_STRNCPY(dest, src, len) \
strncpy(dest, src, len); \
dest[len-1] = '\0'
/* we use fixed size buffers pretty much everywhere */
/* this is strncpy + ensured \0 terminator */
#define SIGAR_SSTRCPY(dest, src) \
SIGAR_STRNCPY(dest, src, sizeof(dest))
#ifndef strEQ
#define strEQ(s1, s2) (strcmp(s1, s2) == 0)
#endif
#ifndef strnEQ
#define strnEQ(s1, s2, n) (strncmp(s1, s2, n) == 0)
#endif
#define SIGAR_LAST_PROC_EXPIRE 2
#define SIGAR_FS_MAX 10
#define SIGAR_CPU_INFO_MAX 4
#define SIGAR_CPU_LIST_MAX 4
#define SIGAR_PROC_LIST_MAX 256
#define SIGAR_PROC_ARGS_MAX 12
#define SIGAR_NET_ROUTE_LIST_MAX 6
#define SIGAR_NET_IFLIST_MAX 20
#define SIGAR_NET_CONNLIST_MAX 20
int sigar_os_open(sigar_t **sigar);
int sigar_os_close(sigar_t *sigar);
char *sigar_os_error_string(int err);
int sigar_proc_list_create(sigar_proc_list_t *proclist);
int sigar_proc_list_grow(sigar_proc_list_t *proclist);
#define SIGAR_PROC_LIST_GROW(proclist) \
if (proclist->number >= proclist->size) { \
sigar_proc_list_grow(proclist); \
}
int sigar_proc_args_create(sigar_proc_args_t *procargs);
int sigar_proc_args_grow(sigar_proc_args_t *procargs);
#define SIGAR_PROC_ARGS_GROW(procargs) \
if (procargs->number >= procargs->size) { \
sigar_proc_args_grow(procargs); \
}
int sigar_file_system_list_create(sigar_file_system_list_t *fslist);
int sigar_file_system_list_grow(sigar_file_system_list_t *fslist);
#define SIGAR_FILE_SYSTEM_LIST_GROW(fslist) \
if (fslist->number >= fslist->size) { \
sigar_file_system_list_grow(fslist); \
}
int sigar_os_fs_type_get(sigar_file_system_t *fsp);
/* os plugins that set fsp->type call fs_type_get directly */
#define sigar_fs_type_init(fsp) \
fsp->type = SIGAR_FSTYPE_UNKNOWN; \
sigar_fs_type_get(fsp)
void sigar_fs_type_get(sigar_file_system_t *fsp);
int sigar_cpu_infos_create(sigar_cpu_infos_t *cpu_infos);
int sigar_cpu_infos_grow(sigar_cpu_infos_t *cpu_infos);
#define SIGAR_CPU_INFOS_GROW(cpu_infos) \
if (cpu_infos->number >= cpu_infos->size) { \
sigar_cpu_infos_grow(cpu_infos); \
}
int sigar_cpu_list_create(sigar_cpu_list_t *cpulist);
int sigar_cpu_list_grow(sigar_cpu_list_t *cpulist);
#define SIGAR_CPU_LIST_GROW(cpulist) \
if (cpulist->number >= cpulist->size) { \
sigar_cpu_list_grow(cpulist); \
}
int sigar_net_route_list_create(sigar_net_route_list_t *routelist);
int sigar_net_route_list_grow(sigar_net_route_list_t *net_routelist);
#define SIGAR_NET_ROUTE_LIST_GROW(routelist) \
if (routelist->number >= routelist->size) { \
sigar_net_route_list_grow(routelist); \
}
int sigar_net_interface_list_create(sigar_net_interface_list_t *iflist);
int sigar_net_interface_list_grow(sigar_net_interface_list_t *iflist);
#define SIGAR_NET_IFLIST_GROW(iflist) \
if (iflist->number >= iflist->size) { \
sigar_net_interface_list_grow(iflist); \
}
int sigar_net_connection_list_create(sigar_net_connection_list_t *connlist);
int sigar_net_connection_list_grow(sigar_net_connection_list_t *connlist);
#define SIGAR_NET_CONNLIST_GROW(connlist) \
if (connlist->number >= connlist->size) { \
sigar_net_connection_list_grow(connlist); \
}
void sigar_hwaddr_format(char *buff, unsigned char *ptr);
#define sigar_hwaddr_set_null(ifconfig) \
memcpy(ifconfig->hwaddr, SIGAR_NULL_HWADDR, sizeof(SIGAR_NULL_HWADDR))
int sigar_user_id_get(sigar_t *sigar, const char *name, int *uid);
int sigar_user_name_get(sigar_t *sigar, int uid, char *buf, int buflen);
int sigar_group_name_get(sigar_t *sigar, int gid, char *buf, int buflen);
#define SIGAR_PROC_ENV_KEY_LOOKUP() \
if ((procenv->type == SIGAR_PROC_ENV_KEY) && \
(pid == sigar->pid)) \
{ \
char *value = getenv(procenv->key); \
if (value != NULL) { \
procenv->env_getter(procenv->data, \
procenv->key, \
procenv->klen, \
value, strlen(value)); \
} \
return SIGAR_OK; \
}
#endif
+70
View File
@@ -0,0 +1,70 @@
#ifndef SIGAR_UTIL_H
#define SIGAR_UTIL_H
/* most of this is crap for dealing with linux /proc */
#define UITOA_BUFFER_SIZE \
(sizeof(int) * 3 + 1)
#define SSTRLEN(s) \
(sizeof(s)-1)
#define sigar_strtoul(ptr) \
strtoul(ptr, &ptr, 10)
#define sigar_isspace(c) \
(isspace(((unsigned char)(c))))
#define sigar_isdigit(c) \
(isdigit(((unsigned char)(c))))
#define sigar_isalpha(c) \
(isalpha(((unsigned char)(c))))
#define PROC_FS_ROOT "/proc/"
char *sigar_uitoa(char *buf, unsigned int n, int *len);
SIGAR_INLINE char *sigar_skip_line(char *buffer, int buflen);
SIGAR_INLINE char *sigar_skip_token(char *p);
SIGAR_INLINE char *sigar_skip_multiple_token(char *p, int count);
int sigar_file2str(const char *fname, char *buffer, int buflen);
int sigar_proc_file2str(char *buffer, int buflen,
sigar_pid_t pid,
const char *fname,
int fname_len);
#define SIGAR_PROC_FILE2STR(buffer, pid, fname) \
sigar_proc_file2str(buffer, sizeof(buffer), \
pid, fname, SSTRLEN(fname))
#define SIGAR_PROC_FILENAME(buffer, pid, fname) \
sigar_proc_filename(buffer, sizeof(buffer), \
pid, fname, SSTRLEN(fname))
#define SIGAR_SKIP_SPACE(ptr) \
while (sigar_isspace(*ptr)) ++ptr
char *sigar_proc_filename(char *buffer, int buflen,
sigar_pid_t pid,
const char *fname, int fname_len);
int sigar_proc_list_procfs_get(sigar_t *sigar,
sigar_proc_list_t *proclist);
int sigar_proc_fd_count(sigar_t *sigar, sigar_pid_t pid,
sigar_uint64_t *total);
/* generic util functions for all platforms */
int sigar_proc_count(sigar_t *sigar, sigar_uint64_t *total);
int sigar_mem_calc_ram(sigar_t *sigar, sigar_mem_t *mem);
double sigar_file_system_usage_calc_used(sigar_t *sigar,
sigar_file_system_usage_t *fs);
#endif /* SIGAR_UTIL_H */