go bindings
statically build go with sigar using visual studio 2015 IDE
This commit is contained in:
1 parent
7a6aefc7fb
commit
0f0dbe34ce
88 files changed
+17394
No files matched your search
@@ -0,0 +1,985 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2008 Hyperic, Inc.
|
||||
* Copyright (c) 2009 SpringSource, Inc.
|
||||
* Copyright (c) 2009-2010 VMware, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SIGAR_H
|
||||
#define SIGAR_H
|
||||
|
||||
/* System Information Gatherer And Reporter */
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#ifndef MAX_INTERFACE_NAME_LEN
|
||||
#define MAX_INTERFACE_NAME_LEN 256
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(_LP64) || \
|
||||
defined(__LP64__) || \
|
||||
defined(__64BIT__) || \
|
||||
defined(__powerpc64__) || \
|
||||
defined(__osf__)
|
||||
#define SIGAR_64BIT
|
||||
#endif
|
||||
|
||||
/* for printf sigar_uint64_t */
|
||||
#ifdef SIGAR_64BIT
|
||||
# define SIGAR_F_U64 "%lu"
|
||||
#else
|
||||
# define SIGAR_F_U64 "%Lu"
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
typedef unsigned __int32 sigar_uint32_t;
|
||||
|
||||
typedef unsigned __int64 sigar_uint64_t;
|
||||
|
||||
typedef __int32 sigar_int32_t;
|
||||
|
||||
typedef __int64 sigar_int64_t;
|
||||
|
||||
#elif ULONG_MAX > 4294967295UL
|
||||
|
||||
typedef unsigned int sigar_uint32_t;
|
||||
|
||||
typedef unsigned long sigar_uint64_t;
|
||||
|
||||
typedef int sigar_int32_t;
|
||||
|
||||
typedef long sigar_int64_t;
|
||||
|
||||
#else
|
||||
|
||||
typedef unsigned int sigar_uint32_t;
|
||||
|
||||
typedef unsigned long long sigar_uint64_t;
|
||||
|
||||
typedef int sigar_int32_t;
|
||||
|
||||
typedef long long sigar_int64_t;
|
||||
|
||||
#endif
|
||||
|
||||
#define SIGAR_FIELD_NOTIMPL -1
|
||||
|
||||
#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_ENOENT ERROR_FILE_NOT_FOUND
|
||||
# define SIGAR_EACCES ERROR_ACCESS_DENIED
|
||||
# define SIGAR_ENXIO ERROR_BAD_DRIVER_LEVEL
|
||||
#else
|
||||
# define SIGAR_ENOENT ENOENT
|
||||
# define SIGAR_EACCES EACCES
|
||||
# define SIGAR_ENXIO ENXIO
|
||||
#endif
|
||||
|
||||
#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 4096
|
||||
#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(int) sigar_signum_get(char *name);
|
||||
|
||||
SIGAR_DECLARE(char *) sigar_strerror(sigar_t *sigar, int err);
|
||||
|
||||
/* system memory info */
|
||||
|
||||
typedef struct {
|
||||
sigar_uint64_t
|
||||
ram,
|
||||
total,
|
||||
used,
|
||||
free,
|
||||
actual_used,
|
||||
actual_free;
|
||||
double used_percent;
|
||||
double free_percent;
|
||||
} sigar_mem_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem);
|
||||
|
||||
typedef struct {
|
||||
sigar_uint64_t
|
||||
total,
|
||||
used,
|
||||
free,
|
||||
page_in,
|
||||
page_out;
|
||||
} 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,
|
||||
wait,
|
||||
irq,
|
||||
soft_irq,
|
||||
stolen,
|
||||
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;
|
||||
int mhz_max;
|
||||
int mhz_min;
|
||||
sigar_uint64_t cache_size;
|
||||
int total_sockets;
|
||||
int total_cores;
|
||||
int cores_per_socket;
|
||||
} sigar_cpu_info_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned long number;
|
||||
unsigned long size;
|
||||
sigar_cpu_info_t *data;
|
||||
} sigar_cpu_info_list_t;
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_cpu_info_list_get(sigar_t *sigar,
|
||||
sigar_cpu_info_list_t *cpu_infos);
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_cpu_info_list_destroy(sigar_t *sigar,
|
||||
sigar_cpu_info_list_t *cpu_infos);
|
||||
|
||||
typedef struct {
|
||||
double uptime;
|
||||
} sigar_uptime_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_uptime_get(sigar_t *sigar,
|
||||
sigar_uptime_t *uptime);
|
||||
|
||||
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;
|
||||
|
||||
typedef struct {
|
||||
/* RLIMIT_CPU */
|
||||
sigar_uint64_t cpu_cur, cpu_max;
|
||||
/* RLIMIT_FSIZE */
|
||||
sigar_uint64_t file_size_cur, file_size_max;
|
||||
/* PIPE_BUF */
|
||||
sigar_uint64_t pipe_size_cur, pipe_size_max;
|
||||
/* RLIMIT_DATA */
|
||||
sigar_uint64_t data_cur, data_max;
|
||||
/* RLIMIT_STACK */
|
||||
sigar_uint64_t stack_cur, stack_max;
|
||||
/* RLIMIT_CORE */
|
||||
sigar_uint64_t core_cur, core_max;
|
||||
/* RLIMIT_RSS */
|
||||
sigar_uint64_t memory_cur, memory_max;
|
||||
/* RLIMIT_NPROC */
|
||||
sigar_uint64_t processes_cur, processes_max;
|
||||
/* RLIMIT_NOFILE */
|
||||
sigar_uint64_t open_files_cur, open_files_max;
|
||||
/* RLIMIT_AS */
|
||||
sigar_uint64_t virtual_memory_cur, virtual_memory_max;
|
||||
} sigar_resource_limit_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_resource_limit_get(sigar_t *sigar,
|
||||
sigar_resource_limit_t *rlimit);
|
||||
|
||||
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_uint64_t sleeping;
|
||||
sigar_uint64_t running;
|
||||
sigar_uint64_t zombie;
|
||||
sigar_uint64_t stopped;
|
||||
sigar_uint64_t idle;
|
||||
sigar_uint64_t threads;
|
||||
} 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,
|
||||
resident,
|
||||
share,
|
||||
minor_faults,
|
||||
major_faults,
|
||||
page_faults;
|
||||
} 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_uint64_t
|
||||
bytes_read,
|
||||
bytes_written,
|
||||
bytes_total;
|
||||
} sigar_proc_disk_io_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_proc_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_disk_io_t *proc_disk_io);
|
||||
|
||||
typedef struct {
|
||||
sigar_uint64_t
|
||||
bytes_read,
|
||||
bytes_written,
|
||||
bytes_total;
|
||||
sigar_uint64_t last_time;
|
||||
sigar_uint64_t
|
||||
bytes_read_diff,
|
||||
bytes_written_diff,
|
||||
bytes_total_diff;
|
||||
} sigar_cached_proc_disk_io_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
sigar_uint64_t
|
||||
bytes_read,
|
||||
bytes_written,
|
||||
bytes_total;
|
||||
} sigar_proc_cumulative_disk_io_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io);
|
||||
|
||||
|
||||
typedef struct {
|
||||
sigar_uint64_t dummy;
|
||||
}sigar_dump_pid_cache_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_dump_pid_cache_get(sigar_t *sigar, sigar_dump_pid_cache_t *info);
|
||||
|
||||
|
||||
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,
|
||||
user,
|
||||
sys,
|
||||
total;
|
||||
} sigar_proc_time_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_time_t *proctime);
|
||||
|
||||
typedef struct {
|
||||
/* must match sigar_proc_time_t fields */
|
||||
sigar_uint64_t
|
||||
start_time,
|
||||
user,
|
||||
sys,
|
||||
total;
|
||||
sigar_uint64_t last_time;
|
||||
double percent;
|
||||
} sigar_proc_cpu_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_proc_cpu_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_cpu_t *proccpu);
|
||||
|
||||
#define SIGAR_PROC_STATE_SLEEP 'S'
|
||||
#define SIGAR_PROC_STATE_RUN 'R'
|
||||
#define SIGAR_PROC_STATE_STOP 'T'
|
||||
#define SIGAR_PROC_STATE_ZOMBIE 'Z'
|
||||
#define SIGAR_PROC_STATE_IDLE 'D'
|
||||
|
||||
#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;
|
||||
int processor;
|
||||
sigar_uint64_t threads;
|
||||
} 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 struct {
|
||||
void *data; /* user data */
|
||||
|
||||
int (*module_getter)(void *, char *, int);
|
||||
} sigar_proc_modules_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_modules_t *procmods);
|
||||
|
||||
typedef struct {
|
||||
sigar_uint64_t user;
|
||||
sigar_uint64_t sys;
|
||||
sigar_uint64_t total;
|
||||
} sigar_thread_cpu_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_thread_cpu_get(sigar_t *sigar,
|
||||
sigar_uint64_t id,
|
||||
sigar_thread_cpu_t *cpu);
|
||||
|
||||
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 SIGAR_PATH_MAX
|
||||
#define SIGAR_FS_INFO_LEN 256
|
||||
|
||||
typedef struct {
|
||||
char dir_name[SIGAR_FS_NAME_LEN];
|
||||
char dev_name[SIGAR_FS_NAME_LEN];
|
||||
char type_name[SIGAR_FS_INFO_LEN]; /* e.g. "local" */
|
||||
char sys_type_name[SIGAR_FS_INFO_LEN]; /* e.g. "ext3" */
|
||||
char options[SIGAR_FS_INFO_LEN];
|
||||
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 reads;
|
||||
sigar_uint64_t writes;
|
||||
sigar_uint64_t write_bytes;
|
||||
sigar_uint64_t read_bytes;
|
||||
sigar_uint64_t rtime;
|
||||
sigar_uint64_t wtime;
|
||||
sigar_uint64_t qtime;
|
||||
sigar_uint64_t time;
|
||||
sigar_uint64_t snaptime;
|
||||
double service_time;
|
||||
double queue;
|
||||
} sigar_disk_usage_t;
|
||||
|
||||
/* XXX for sigar_file_system_usage_t compat */
|
||||
#define disk_reads disk.reads
|
||||
#define disk_writes disk.writes
|
||||
#define disk_write_bytes disk.write_bytes
|
||||
#define disk_read_bytes disk.read_bytes
|
||||
#define disk_queue disk.queue
|
||||
#define disk_service_time disk.service_time
|
||||
|
||||
typedef struct {
|
||||
sigar_disk_usage_t disk;
|
||||
double use_percent;
|
||||
sigar_uint64_t total;
|
||||
sigar_uint64_t free;
|
||||
sigar_uint64_t used;
|
||||
sigar_uint64_t avail;
|
||||
sigar_uint64_t files;
|
||||
sigar_uint64_t free_files;
|
||||
} sigar_file_system_usage_t;
|
||||
|
||||
#undef SIGAR_DISK_USAGE_T
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_file_system_usage_get(sigar_t *sigar,
|
||||
const char *dirname,
|
||||
sigar_file_system_usage_t *fsusage);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_disk_usage_get(sigar_t *sigar,
|
||||
const char *name,
|
||||
sigar_disk_usage_t *disk);
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_file_system_ping(sigar_t *sigar,
|
||||
sigar_file_system_t *fs);
|
||||
|
||||
typedef struct {
|
||||
enum {
|
||||
SIGAR_AF_UNSPEC,
|
||||
SIGAR_AF_INET,
|
||||
SIGAR_AF_INET6,
|
||||
SIGAR_AF_LINK
|
||||
} family;
|
||||
union {
|
||||
sigar_uint32_t in;
|
||||
sigar_uint32_t in6[4];
|
||||
unsigned char mac[8];
|
||||
} addr;
|
||||
} sigar_net_address_t;
|
||||
|
||||
#define SIGAR_INET6_ADDRSTRLEN 46
|
||||
|
||||
#define SIGAR_MAXDOMAINNAMELEN 256
|
||||
#define SIGAR_MAXHOSTNAMELEN 256
|
||||
|
||||
typedef struct {
|
||||
char default_gateway[SIGAR_INET6_ADDRSTRLEN];
|
||||
char default_gateway_interface[MAX_INTERFACE_NAME_LEN];
|
||||
char host_name[SIGAR_MAXHOSTNAMELEN];
|
||||
char domain_name[SIGAR_MAXDOMAINNAMELEN];
|
||||
char primary_dns[SIGAR_INET6_ADDRSTRLEN];
|
||||
char secondary_dns[SIGAR_INET6_ADDRSTRLEN];
|
||||
} sigar_net_info_t;
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_net_info_get(sigar_t *sigar,
|
||||
sigar_net_info_t *netinfo);
|
||||
|
||||
#define SIGAR_RTF_UP 0x1
|
||||
#define SIGAR_RTF_GATEWAY 0x2
|
||||
#define SIGAR_RTF_HOST 0x4
|
||||
|
||||
typedef struct {
|
||||
sigar_net_address_t destination;
|
||||
sigar_net_address_t gateway;
|
||||
sigar_net_address_t mask;
|
||||
sigar_uint64_t
|
||||
flags,
|
||||
refcnt,
|
||||
use,
|
||||
metric,
|
||||
mtu,
|
||||
window,
|
||||
irtt;
|
||||
char ifname[MAX_INTERFACE_NAME_LEN];
|
||||
} 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_IFF_SLAVE 0x1000
|
||||
#define SIGAR_IFF_MASTER 0x2000
|
||||
#define SIGAR_IFF_DYNAMIC 0x4000
|
||||
|
||||
#define SIGAR_NULL_HWADDR "00:00:00:00:00:00"
|
||||
|
||||
/* scope values from linux-2.6/include/net/ipv6.h */
|
||||
#define SIGAR_IPV6_ADDR_ANY 0x0000
|
||||
#define SIGAR_IPV6_ADDR_UNICAST 0x0001
|
||||
#define SIGAR_IPV6_ADDR_MULTICAST 0x0002
|
||||
#define SIGAR_IPV6_ADDR_LOOPBACK 0x0010
|
||||
#define SIGAR_IPV6_ADDR_LINKLOCAL 0x0020
|
||||
#define SIGAR_IPV6_ADDR_SITELOCAL 0x0040
|
||||
#define SIGAR_IPV6_ADDR_COMPATv4 0x0080
|
||||
|
||||
typedef struct {
|
||||
char name[MAX_INTERFACE_NAME_LEN];
|
||||
char type[64];
|
||||
char description[256];
|
||||
sigar_net_address_t hwaddr;
|
||||
sigar_net_address_t address;
|
||||
sigar_net_address_t destination;
|
||||
sigar_net_address_t broadcast;
|
||||
sigar_net_address_t netmask;
|
||||
sigar_net_address_t address6;
|
||||
int prefix6_length;
|
||||
int scope6;
|
||||
sigar_uint64_t
|
||||
flags,
|
||||
mtu,
|
||||
metric;
|
||||
int tx_queue_len;
|
||||
} 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);
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_net_interface_config_primary_get(sigar_t *sigar,
|
||||
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,
|
||||
speed;
|
||||
} 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
|
||||
|
||||
enum {
|
||||
SIGAR_TCP_ESTABLISHED = 1,
|
||||
SIGAR_TCP_SYN_SENT,
|
||||
SIGAR_TCP_SYN_RECV,
|
||||
SIGAR_TCP_FIN_WAIT1,
|
||||
SIGAR_TCP_FIN_WAIT2,
|
||||
SIGAR_TCP_TIME_WAIT,
|
||||
SIGAR_TCP_CLOSE,
|
||||
SIGAR_TCP_CLOSE_WAIT,
|
||||
SIGAR_TCP_LAST_ACK,
|
||||
SIGAR_TCP_LISTEN,
|
||||
SIGAR_TCP_CLOSING,
|
||||
SIGAR_TCP_IDLE,
|
||||
SIGAR_TCP_BOUND,
|
||||
SIGAR_TCP_UNKNOWN
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
unsigned long local_port;
|
||||
sigar_net_address_t local_address;
|
||||
unsigned long remote_port;
|
||||
sigar_net_address_t remote_address;
|
||||
sigar_uid_t uid;
|
||||
unsigned long inode;
|
||||
int type;
|
||||
int state;
|
||||
unsigned long send_queue;
|
||||
unsigned long receive_queue;
|
||||
} 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);
|
||||
|
||||
typedef struct sigar_net_connection_walker_t sigar_net_connection_walker_t;
|
||||
|
||||
/* alternative to sigar_net_connection_list_get */
|
||||
struct sigar_net_connection_walker_t {
|
||||
sigar_t *sigar;
|
||||
int flags;
|
||||
void *data; /* user data */
|
||||
int (*add_connection)(sigar_net_connection_walker_t *walker,
|
||||
sigar_net_connection_t *connection);
|
||||
};
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_net_connection_walk(sigar_net_connection_walker_t *walker);
|
||||
|
||||
typedef struct {
|
||||
int tcp_states[SIGAR_TCP_UNKNOWN];
|
||||
sigar_uint32_t tcp_inbound_total;
|
||||
sigar_uint32_t tcp_outbound_total;
|
||||
sigar_uint32_t all_inbound_total;
|
||||
sigar_uint32_t all_outbound_total;
|
||||
} sigar_net_stat_t;
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_net_stat_get(sigar_t *sigar,
|
||||
sigar_net_stat_t *netstat,
|
||||
int flags);
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_net_stat_port_get(sigar_t *sigar,
|
||||
sigar_net_stat_t *netstat,
|
||||
int flags,
|
||||
sigar_net_address_t *address,
|
||||
unsigned long port);
|
||||
|
||||
/* TCP-MIB */
|
||||
typedef struct {
|
||||
sigar_uint64_t active_opens;
|
||||
sigar_uint64_t passive_opens;
|
||||
sigar_uint64_t attempt_fails;
|
||||
sigar_uint64_t estab_resets;
|
||||
sigar_uint64_t curr_estab;
|
||||
sigar_uint64_t in_segs;
|
||||
sigar_uint64_t out_segs;
|
||||
sigar_uint64_t retrans_segs;
|
||||
sigar_uint64_t in_errs;
|
||||
sigar_uint64_t out_rsts;
|
||||
} sigar_tcp_t;
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_tcp_get(sigar_t *sigar,
|
||||
sigar_tcp_t *tcp);
|
||||
|
||||
typedef struct {
|
||||
sigar_uint64_t null;
|
||||
sigar_uint64_t getattr;
|
||||
sigar_uint64_t setattr;
|
||||
sigar_uint64_t root;
|
||||
sigar_uint64_t lookup;
|
||||
sigar_uint64_t readlink;
|
||||
sigar_uint64_t read;
|
||||
sigar_uint64_t writecache;
|
||||
sigar_uint64_t write;
|
||||
sigar_uint64_t create;
|
||||
sigar_uint64_t remove;
|
||||
sigar_uint64_t rename;
|
||||
sigar_uint64_t link;
|
||||
sigar_uint64_t symlink;
|
||||
sigar_uint64_t mkdir;
|
||||
sigar_uint64_t rmdir;
|
||||
sigar_uint64_t readdir;
|
||||
sigar_uint64_t fsstat;
|
||||
} sigar_nfs_v2_t;
|
||||
|
||||
typedef sigar_nfs_v2_t sigar_nfs_client_v2_t;
|
||||
typedef sigar_nfs_v2_t sigar_nfs_server_v2_t;
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_nfs_client_v2_get(sigar_t *sigar,
|
||||
sigar_nfs_client_v2_t *nfs);
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_nfs_server_v2_get(sigar_t *sigar,
|
||||
sigar_nfs_server_v2_t *nfs);
|
||||
|
||||
typedef struct {
|
||||
sigar_uint64_t null;
|
||||
sigar_uint64_t getattr;
|
||||
sigar_uint64_t setattr;
|
||||
sigar_uint64_t lookup;
|
||||
sigar_uint64_t access;
|
||||
sigar_uint64_t readlink;
|
||||
sigar_uint64_t read;
|
||||
sigar_uint64_t write;
|
||||
sigar_uint64_t create;
|
||||
sigar_uint64_t mkdir;
|
||||
sigar_uint64_t symlink;
|
||||
sigar_uint64_t mknod;
|
||||
sigar_uint64_t remove;
|
||||
sigar_uint64_t rmdir;
|
||||
sigar_uint64_t rename;
|
||||
sigar_uint64_t link;
|
||||
sigar_uint64_t readdir;
|
||||
sigar_uint64_t readdirplus;
|
||||
sigar_uint64_t fsstat;
|
||||
sigar_uint64_t fsinfo;
|
||||
sigar_uint64_t pathconf;
|
||||
sigar_uint64_t commit;
|
||||
} sigar_nfs_v3_t;
|
||||
|
||||
typedef sigar_nfs_v3_t sigar_nfs_client_v3_t;
|
||||
typedef sigar_nfs_v3_t sigar_nfs_server_v3_t;
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_nfs_client_v3_get(sigar_t *sigar,
|
||||
sigar_nfs_client_v3_t *nfs);
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_nfs_server_v3_get(sigar_t *sigar,
|
||||
sigar_nfs_server_v3_t *nfs);
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_net_listen_address_get(sigar_t *sigar,
|
||||
unsigned long port,
|
||||
sigar_net_address_t *address);
|
||||
|
||||
typedef struct {
|
||||
char ifname[MAX_INTERFACE_NAME_LEN];
|
||||
char type[64];
|
||||
sigar_net_address_t hwaddr;
|
||||
sigar_net_address_t address;
|
||||
sigar_uint64_t flags;
|
||||
} sigar_arp_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned long number;
|
||||
unsigned long size;
|
||||
sigar_arp_t *data;
|
||||
} sigar_arp_list_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_arp_list_get(sigar_t *sigar,
|
||||
sigar_arp_list_t *arplist);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_arp_list_destroy(sigar_t *sigar,
|
||||
sigar_arp_list_t *arplist);
|
||||
|
||||
typedef struct {
|
||||
char user[32];
|
||||
char device[32];
|
||||
char host[256];
|
||||
sigar_uint64_t time;
|
||||
} sigar_who_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned long number;
|
||||
unsigned long size;
|
||||
sigar_who_t *data;
|
||||
} sigar_who_list_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_who_list_get(sigar_t *sigar,
|
||||
sigar_who_list_t *wholist);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_who_list_destroy(sigar_t *sigar,
|
||||
sigar_who_list_t *wholist);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_proc_port_get(sigar_t *sigar,
|
||||
int protocol, unsigned long port,
|
||||
sigar_pid_t *pid);
|
||||
|
||||
typedef struct {
|
||||
const char *build_date;
|
||||
const char *scm_revision;
|
||||
const char *version;
|
||||
const char *archname;
|
||||
const char *archlib;
|
||||
const char *binname;
|
||||
const char *description;
|
||||
int major, minor, maint, build;
|
||||
} sigar_version_t;
|
||||
|
||||
SIGAR_DECLARE(sigar_version_t *) sigar_version_get(void);
|
||||
|
||||
#define SIGAR_SYS_INFO_LEN SIGAR_MAXHOSTNAMELEN /* more than enough */
|
||||
|
||||
typedef struct {
|
||||
char name[SIGAR_SYS_INFO_LEN]; /* canonicalized sysname */
|
||||
char version[SIGAR_SYS_INFO_LEN]; /* utsname.release */
|
||||
char arch[SIGAR_SYS_INFO_LEN];
|
||||
char machine[SIGAR_SYS_INFO_LEN];
|
||||
char description[SIGAR_SYS_INFO_LEN];
|
||||
char patch_level[SIGAR_SYS_INFO_LEN];
|
||||
char vendor[SIGAR_SYS_INFO_LEN];
|
||||
char vendor_version[SIGAR_SYS_INFO_LEN];
|
||||
char vendor_name[SIGAR_SYS_INFO_LEN]; /* utsname.sysname */
|
||||
char vendor_code_name[SIGAR_SYS_INFO_LEN];
|
||||
} sigar_sys_info_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo);
|
||||
|
||||
#define SIGAR_FQDN_LEN 512
|
||||
|
||||
SIGAR_DECLARE(int) sigar_fqdn_get(sigar_t *sigar, char *name, int namelen);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_rpc_ping(char *hostname,
|
||||
int protocol,
|
||||
unsigned long program,
|
||||
unsigned long version);
|
||||
|
||||
SIGAR_DECLARE(char *) sigar_rpc_strerror(int err);
|
||||
|
||||
SIGAR_DECLARE(char *) sigar_password_get(const char *prompt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2005 Hyperic, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* ====================================================================
|
||||
* 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_uint64_t disk_usage;
|
||||
} sigar_dir_stat_t;
|
||||
|
||||
typedef sigar_dir_stat_t sigar_dir_usage_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);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_dir_usage_get(sigar_t *sigar,
|
||||
const char *dir,
|
||||
sigar_dir_usage_t *dirusage);
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2008 Hyperic, Inc.
|
||||
* Copyright (c) 2009 SpringSource, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SIGAR_FORMAT_H
|
||||
#define SIGAR_FORMAT_H
|
||||
|
||||
typedef struct {
|
||||
double user;
|
||||
double sys;
|
||||
double nice;
|
||||
double idle;
|
||||
double wait;
|
||||
double irq;
|
||||
double soft_irq;
|
||||
double stolen;
|
||||
double combined;
|
||||
} sigar_cpu_perc_t;
|
||||
|
||||
SIGAR_DECLARE(int) sigar_cpu_perc_calculate(sigar_cpu_t *prev,
|
||||
sigar_cpu_t *curr,
|
||||
sigar_cpu_perc_t *perc);
|
||||
|
||||
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);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_net_address_equals(sigar_net_address_t *addr1,
|
||||
sigar_net_address_t *addr2);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_net_address_to_string(sigar_t *sigar,
|
||||
sigar_net_address_t *address,
|
||||
char *addr_str);
|
||||
|
||||
SIGAR_DECLARE(const char *)sigar_net_scope_to_string(int type);
|
||||
|
||||
SIGAR_DECLARE(sigar_uint32_t) sigar_net_address_hash(sigar_net_address_t *address);
|
||||
|
||||
SIGAR_DECLARE(const char *)sigar_net_connection_type_get(int type);
|
||||
|
||||
SIGAR_DECLARE(const char *)sigar_net_connection_state_get(int state);
|
||||
|
||||
SIGAR_DECLARE(char *) sigar_net_interface_flags_to_string(sigar_uint64_t flags, char *buf);
|
||||
|
||||
SIGAR_DECLARE(char *)sigar_net_services_name_get(sigar_t *sigar,
|
||||
int protocol, unsigned long port);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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 */
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2006 Hyperic, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#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)
|
||||
|
||||
#define SIGAR_STRINGIFY(n) #n
|
||||
|
||||
#define SIGAR_LOG_FILELINE \
|
||||
__FILE__ ":" SIGAR_STRINGIFY(__LINE__)
|
||||
|
||||
#if defined(__GNUC__)
|
||||
# if (__GNUC__ > 2)
|
||||
# define SIGAR_FUNC __func__
|
||||
# else
|
||||
# define SIGAR_FUNC __FUNCTION__
|
||||
# endif
|
||||
#else
|
||||
# define SIGAR_FUNC SIGAR_LOG_FILELINE
|
||||
#endif
|
||||
|
||||
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 */
|
||||
@@ -0,0 +1,685 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2009 Hyperic, Inc.
|
||||
* Copyright (c) 2009 SpringSource, Inc.
|
||||
* Copyright (c) 2009-2010 VMware, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SIGAR_OS_H
|
||||
#define SIGAR_OS_H
|
||||
|
||||
#if !defined(MSVC) && defined(_MSC_VER)
|
||||
#define MSVC
|
||||
#endif
|
||||
|
||||
#ifdef MSVC
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
//#define snprintf _snprintf fixed by ilan
|
||||
#if _MSC_VER <= 1200
|
||||
#define SIGAR_USING_MSC6 /* Visual Studio version 6 */
|
||||
#define HAVE_MIB_IPADDRROW_WTYPE 0
|
||||
#else
|
||||
#define HAVE_MIB_IPADDRROW_WTYPE 1
|
||||
#endif
|
||||
#else
|
||||
/* Cross compiling */
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <winreg.h>
|
||||
#include <winperf.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <tlhelp32.h>
|
||||
|
||||
#include "sigar_util.h"
|
||||
|
||||
#ifdef MSVC
|
||||
# define INT64_C(val) val##i64
|
||||
# define SIGAR_DLLFUNC(api, name) \
|
||||
struct { \
|
||||
const char *name; \
|
||||
##api##_##name func; \
|
||||
} ##name
|
||||
#else
|
||||
/* The GCC compiler doesn't require/accept the ## prefix */
|
||||
# define INT64_C(val) val##L
|
||||
# define SIGAR_DLLFUNC(api, name) \
|
||||
struct { \
|
||||
const char *name; \
|
||||
api##_##name func; \
|
||||
} name
|
||||
#endif
|
||||
|
||||
/* see apr/include/arch/win32/atime.h */
|
||||
#define EPOCH_DELTA INT64_C(11644473600000000)
|
||||
|
||||
#define SIGAR_CMDLINE_MAX 4096<<2
|
||||
|
||||
/* XXX: support CP_UTF8 ? */
|
||||
|
||||
#define SIGAR_A2W(lpa, lpw, bytes) \
|
||||
(lpw[0] = 0, MultiByteToWideChar(CP_ACP, 0, \
|
||||
lpa, -1, lpw, (bytes/sizeof(WCHAR))))
|
||||
|
||||
#define SIGAR_W2A(lpw, lpa, chars) \
|
||||
(lpa[0] = '\0', WideCharToMultiByte(CP_ACP, 0, \
|
||||
lpw, -1, (LPSTR)lpa, chars, \
|
||||
NULL, NULL))
|
||||
|
||||
/* iptypes.h from vc7, not available in vc6 */
|
||||
/* copy from PSDK if using vc6 */
|
||||
#include "iptypes.h"
|
||||
|
||||
/* from wtsapi32.h not in vs6.0 */
|
||||
typedef enum {
|
||||
WTSInitialProgram,
|
||||
WTSApplicationName,
|
||||
WTSWorkingDirectory,
|
||||
WTSOEMId,
|
||||
WTSSessionId,
|
||||
WTSUserName,
|
||||
WTSWinStationName,
|
||||
WTSDomainName,
|
||||
WTSConnectState,
|
||||
WTSClientBuildNumber,
|
||||
WTSClientName,
|
||||
WTSClientDirectory,
|
||||
WTSClientProductId,
|
||||
WTSClientHardwareId,
|
||||
WTSClientAddress,
|
||||
WTSClientDisplay,
|
||||
WTSClientProtocolType,
|
||||
} WTS_INFO_CLASS;
|
||||
|
||||
typedef enum _WTS_CONNECTSTATE_CLASS {
|
||||
WTSActive,
|
||||
WTSConnected,
|
||||
WTSConnectQuery,
|
||||
WTSShadow,
|
||||
WTSDisconnected,
|
||||
WTSIdle,
|
||||
WTSListen,
|
||||
WTSReset,
|
||||
WTSDown,
|
||||
WTSInit
|
||||
} WTS_CONNECTSTATE_CLASS;
|
||||
|
||||
#define WTS_PROTOCOL_TYPE_CONSOLE 0
|
||||
#define WTS_PROTOCOL_TYPE_ICA 1
|
||||
#define WTS_PROTOCOL_TYPE_RDP 2
|
||||
|
||||
typedef struct _WTS_SESSION_INFO {
|
||||
DWORD SessionId;
|
||||
LPTSTR pWinStationName;
|
||||
DWORD State;
|
||||
} WTS_SESSION_INFO, *PWTS_SESSION_INFO;
|
||||
|
||||
typedef struct _WTS_PROCESS_INFO {
|
||||
DWORD SessionId;
|
||||
DWORD ProcessId;
|
||||
LPSTR pProcessName;
|
||||
PSID pUserSid;
|
||||
} WTS_PROCESS_INFO, *PWTS_PROCESS_INFO;
|
||||
|
||||
typedef struct _WTS_CLIENT_ADDRESS {
|
||||
DWORD AddressFamily;
|
||||
BYTE Address[20];
|
||||
} WTS_CLIENT_ADDRESS, *PWTS_CLIENT_ADDRESS;
|
||||
|
||||
/* the WINSTATION_INFO stuff here is undocumented
|
||||
* got the howto from google groups:
|
||||
* http://redirx.com/?31gy
|
||||
*/
|
||||
typedef enum _WINSTATION_INFO_CLASS {
|
||||
WinStationInformation = 8
|
||||
} WINSTATION_INFO_CLASS;
|
||||
|
||||
typedef struct _WINSTATION_INFO {
|
||||
BYTE Reserved1[72];
|
||||
ULONG SessionId;
|
||||
BYTE Reserved2[4];
|
||||
FILETIME ConnectTime;
|
||||
FILETIME DisconnectTime;
|
||||
FILETIME LastInputTime;
|
||||
FILETIME LoginTime;
|
||||
BYTE Reserved3[1096];
|
||||
FILETIME CurrentTime;
|
||||
} WINSTATION_INFO, *PWINSTATION_INFO;
|
||||
|
||||
/* end wtsapi32.h */
|
||||
|
||||
#ifdef SIGAR_USING_MSC6
|
||||
|
||||
/* from winbase.h not in vs6.0 */
|
||||
typedef struct {
|
||||
DWORD dwLength;
|
||||
DWORD dwMemoryLoad;
|
||||
DWORDLONG ullTotalPhys;
|
||||
DWORDLONG ullAvailPhys;
|
||||
DWORDLONG ullTotalPageFile;
|
||||
DWORDLONG ullAvailPageFile;
|
||||
DWORDLONG ullTotalVirtual;
|
||||
DWORDLONG ullAvailVirtual;
|
||||
DWORDLONG ullAvailExtendedVirtual;
|
||||
} MEMORYSTATUSEX;
|
||||
|
||||
/* service manager stuff not in vs6.0 */
|
||||
typedef struct _SERVICE_STATUS_PROCESS {
|
||||
DWORD dwServiceType;
|
||||
DWORD dwCurrentState;
|
||||
DWORD dwControlsAccepted;
|
||||
DWORD dwWin32ExitCode;
|
||||
DWORD dwServiceSpecificExitCode;
|
||||
DWORD dwCheckPoint;
|
||||
DWORD dwWaitHint;
|
||||
DWORD dwProcessId;
|
||||
DWORD dwServiceFlags;
|
||||
} SERVICE_STATUS_PROCESS;
|
||||
|
||||
typedef enum {
|
||||
SC_STATUS_PROCESS_INFO = 0
|
||||
} SC_STATUS_TYPE;
|
||||
|
||||
#ifndef ERROR_DATATYPE_MISMATCH
|
||||
#define ERROR_DATATYPE_MISMATCH 1629L
|
||||
#endif
|
||||
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
#include <iprtrmib.h>
|
||||
|
||||
/* undocumented structures */
|
||||
typedef struct {
|
||||
DWORD dwState;
|
||||
DWORD dwLocalAddr;
|
||||
DWORD dwLocalPort;
|
||||
DWORD dwRemoteAddr;
|
||||
DWORD dwRemotePort;
|
||||
DWORD dwProcessId;
|
||||
} MIB_TCPEXROW, *PMIB_TCPEXROW;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwNumEntries;
|
||||
MIB_TCPEXROW table[ANY_SIZE];
|
||||
} MIB_TCPEXTABLE, *PMIB_TCPEXTABLE;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwLocalAddr;
|
||||
DWORD dwLocalPort;
|
||||
DWORD dwProcessId;
|
||||
} MIB_UDPEXROW, *PMIB_UDPEXROW;
|
||||
|
||||
typedef struct {
|
||||
DWORD dwNumEntries;
|
||||
MIB_UDPEXROW table[ANY_SIZE];
|
||||
} MIB_UDPEXTABLE, *PMIB_UDPEXTABLE;
|
||||
|
||||
/* end undocumented structures */
|
||||
|
||||
/* no longer in the standard header files */
|
||||
typedef struct {
|
||||
LARGE_INTEGER IdleTime;
|
||||
LARGE_INTEGER KernelTime;
|
||||
LARGE_INTEGER UserTime;
|
||||
LARGE_INTEGER DpcTime;
|
||||
LARGE_INTEGER InterruptTime;
|
||||
ULONG InterruptCount;
|
||||
} SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
|
||||
|
||||
#define SystemProcessorPerformanceInformation 8
|
||||
|
||||
/* PEB decls from msdn docs w/ slight mods */
|
||||
#define ProcessBasicInformation 0
|
||||
|
||||
typedef struct _UNICODE_STRING {
|
||||
USHORT Length;
|
||||
USHORT MaximumLength;
|
||||
PWSTR Buffer;
|
||||
} UNICODE_STRING, *PUNICODE_STRING;
|
||||
|
||||
typedef struct _PEB_LDR_DATA {
|
||||
BYTE Reserved1[8];
|
||||
PVOID Reserved2[3];
|
||||
LIST_ENTRY InMemoryOrderModuleList;
|
||||
} PEB_LDR_DATA, *PPEB_LDR_DATA;
|
||||
|
||||
typedef struct RTL_DRIVE_LETTER_CURDIR {
|
||||
USHORT Flags;
|
||||
USHORT Length;
|
||||
ULONG TimeStamp;
|
||||
UNICODE_STRING DosPath;
|
||||
} RTL_DRIVE_LETTER_CURDIR, *PRTL_DRIVE_LETTER_CURDIR;
|
||||
|
||||
/* from: http://source.winehq.org/source/include/winternl.h */
|
||||
typedef struct _RTL_USER_PROCESS_PARAMETERS {
|
||||
ULONG AllocationSize;
|
||||
ULONG Size;
|
||||
ULONG Flags;
|
||||
ULONG DebugFlags;
|
||||
HANDLE hConsole;
|
||||
ULONG ProcessGroup;
|
||||
HANDLE hStdInput;
|
||||
HANDLE hStdOutput;
|
||||
HANDLE hStdError;
|
||||
UNICODE_STRING CurrentDirectoryName;
|
||||
HANDLE CurrentDirectoryHandle;
|
||||
UNICODE_STRING DllPath;
|
||||
UNICODE_STRING ImagePathName;
|
||||
UNICODE_STRING CommandLine;
|
||||
PWSTR Environment;
|
||||
ULONG dwX;
|
||||
ULONG dwY;
|
||||
ULONG dwXSize;
|
||||
ULONG dwYSize;
|
||||
ULONG dwXCountChars;
|
||||
ULONG dwYCountChars;
|
||||
ULONG dwFillAttribute;
|
||||
ULONG dwFlags;
|
||||
ULONG wShowWindow;
|
||||
UNICODE_STRING WindowTitle;
|
||||
UNICODE_STRING Desktop;
|
||||
UNICODE_STRING ShellInfo;
|
||||
UNICODE_STRING RuntimeInfo;
|
||||
RTL_DRIVE_LETTER_CURDIR DLCurrentDirectory[0x20];
|
||||
} RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
|
||||
|
||||
/* from msdn docs
|
||||
typedef struct _RTL_USER_PROCESS_PARAMETERS {
|
||||
BYTE Reserved1[16];
|
||||
PVOID Reserved2[10];
|
||||
UNICODE_STRING ImagePathName;
|
||||
UNICODE_STRING CommandLine;
|
||||
} RTL_USER_PROCESS_PARAMETERS, *PRTL_USER_PROCESS_PARAMETERS;
|
||||
*/
|
||||
|
||||
typedef struct _PEB {
|
||||
BYTE Reserved1[2];
|
||||
BYTE BeingDebugged;
|
||||
BYTE Reserved2[1];
|
||||
PVOID Reserved3[2];
|
||||
PPEB_LDR_DATA Ldr;
|
||||
PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
|
||||
BYTE Reserved4[104];
|
||||
PVOID Reserved5[52];
|
||||
/*PPS_POST_PROCESS_INIT_ROUTINE*/ PVOID PostProcessInitRoutine;
|
||||
BYTE Reserved6[128];
|
||||
PVOID Reserved7[1];
|
||||
ULONG SessionId;
|
||||
} PEB, *PPEB;
|
||||
|
||||
typedef struct _PROCESS_BASIC_INFORMATION {
|
||||
PVOID Reserved1;
|
||||
PPEB PebBaseAddress;
|
||||
PVOID Reserved2[2];
|
||||
/*ULONG_PTR*/ UINT_PTR UniqueProcessId;
|
||||
PVOID Reserved3;
|
||||
} PROCESS_BASIC_INFORMATION;
|
||||
|
||||
typedef struct {
|
||||
sigar_pid_t pid;
|
||||
int ppid;
|
||||
int priority;
|
||||
time_t mtime;
|
||||
sigar_uint64_t size;
|
||||
sigar_uint64_t resident;
|
||||
char name[SIGAR_PROC_NAME_LEN];
|
||||
char state;
|
||||
sigar_uint64_t handles;
|
||||
sigar_uint64_t threads;
|
||||
sigar_uint64_t page_faults;
|
||||
sigar_uint64_t bytes_read;
|
||||
sigar_uint64_t bytes_written;
|
||||
} sigar_win32_pinfo_t;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
HINSTANCE handle;
|
||||
} sigar_dll_handle_t;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
FARPROC func;
|
||||
} sigar_dll_func_t;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
HINSTANCE handle;
|
||||
sigar_dll_func_t funcs[12];
|
||||
} sigar_dll_module_t;
|
||||
|
||||
/* wtsapi.dll */
|
||||
typedef BOOL (CALLBACK *wtsapi_enum_sessions)(HANDLE,
|
||||
DWORD,
|
||||
DWORD,
|
||||
PWTS_SESSION_INFO *,
|
||||
DWORD *);
|
||||
|
||||
typedef void (CALLBACK *wtsapi_free_mem)(PVOID);
|
||||
|
||||
typedef BOOL (CALLBACK *wtsapi_query_session)(HANDLE,
|
||||
DWORD,
|
||||
WTS_INFO_CLASS,
|
||||
LPSTR *, DWORD *);
|
||||
/* iphlpapi.dll */
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_ipforward_table)(PMIB_IPFORWARDTABLE,
|
||||
PULONG,
|
||||
BOOL);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_ipaddr_table)(PMIB_IPADDRTABLE,
|
||||
PULONG,
|
||||
BOOL);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_if_table)(PMIB_IFTABLE,
|
||||
PULONG,
|
||||
BOOL);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_if_entry)(PMIB_IFROW);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_num_if)(PDWORD);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_tcp_table)(PMIB_TCPTABLE,
|
||||
PDWORD,
|
||||
BOOL);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_udp_table)(PMIB_UDPTABLE,
|
||||
PDWORD,
|
||||
BOOL);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_tcpx_table)(PMIB_TCPEXTABLE *,
|
||||
BOOL,
|
||||
HANDLE,
|
||||
DWORD,
|
||||
DWORD);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_udpx_table)(PMIB_UDPEXTABLE *,
|
||||
BOOL,
|
||||
HANDLE,
|
||||
DWORD,
|
||||
DWORD);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_tcp_stats)(PMIB_TCPSTATS);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_net_params)(PFIXED_INFO,
|
||||
PULONG);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_adapters_info)(PIP_ADAPTER_INFO,
|
||||
PULONG);
|
||||
|
||||
typedef ULONG (CALLBACK *iphlpapi_get_adapters_addrs)(ULONG,
|
||||
ULONG,
|
||||
PVOID,
|
||||
PIP_ADAPTER_ADDRESSES,
|
||||
PULONG);
|
||||
|
||||
/* advapi32.dll */
|
||||
typedef BOOL (CALLBACK *advapi_convert_string_sid)(LPCSTR,
|
||||
PSID *);
|
||||
|
||||
typedef BOOL (CALLBACK *advapi_query_service_status)(SC_HANDLE,
|
||||
SC_STATUS_TYPE,
|
||||
LPBYTE,
|
||||
DWORD,
|
||||
LPDWORD);
|
||||
|
||||
typedef DWORD (CALLBACK *iphlpapi_get_ipnet_table)(PMIB_IPNETTABLE,
|
||||
PDWORD,
|
||||
BOOL);
|
||||
|
||||
/* ntdll.dll */
|
||||
typedef DWORD (CALLBACK *ntdll_query_sys_info)(DWORD,
|
||||
PVOID,
|
||||
ULONG,
|
||||
PULONG);
|
||||
|
||||
typedef DWORD (CALLBACK *ntdll_query_proc_info)(HANDLE,
|
||||
DWORD,
|
||||
PVOID,
|
||||
ULONG,
|
||||
PULONG);
|
||||
|
||||
/* psapi.dll */
|
||||
typedef BOOL (CALLBACK *psapi_enum_modules)(HANDLE,
|
||||
HMODULE *,
|
||||
DWORD,
|
||||
LPDWORD);
|
||||
|
||||
typedef DWORD (CALLBACK *psapi_get_module_name)(HANDLE,
|
||||
HMODULE,
|
||||
LPTSTR,
|
||||
DWORD);
|
||||
|
||||
typedef BOOL (CALLBACK *psapi_enum_processes)(DWORD *,
|
||||
DWORD,
|
||||
DWORD *);
|
||||
|
||||
/* winsta.dll */
|
||||
typedef BOOLEAN (CALLBACK *winsta_query_info)(HANDLE,
|
||||
ULONG,
|
||||
WINSTATION_INFO_CLASS,
|
||||
PVOID,
|
||||
ULONG,
|
||||
PULONG);
|
||||
|
||||
/* kernel32.dll */
|
||||
typedef BOOL (CALLBACK *kernel_memory_status)(MEMORYSTATUSEX *);
|
||||
|
||||
/* mpr.dll */
|
||||
typedef BOOL (CALLBACK *mpr_get_net_connection)(LPCTSTR,
|
||||
LPTSTR,
|
||||
LPDWORD);
|
||||
|
||||
typedef struct {
|
||||
sigar_dll_handle_t handle;
|
||||
|
||||
SIGAR_DLLFUNC(wtsapi, enum_sessions);
|
||||
SIGAR_DLLFUNC(wtsapi, free_mem);
|
||||
SIGAR_DLLFUNC(wtsapi, query_session);
|
||||
|
||||
sigar_dll_func_t end;
|
||||
} sigar_wtsapi_t;
|
||||
|
||||
typedef struct {
|
||||
sigar_dll_handle_t handle;
|
||||
|
||||
SIGAR_DLLFUNC(iphlpapi, get_ipforward_table);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_ipaddr_table);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_if_table);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_if_entry);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_num_if);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_tcp_table);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_udp_table);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_tcpx_table);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_udpx_table);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_tcp_stats);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_net_params);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_adapters_info);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_adapters_addrs);
|
||||
SIGAR_DLLFUNC(iphlpapi, get_ipnet_table);
|
||||
|
||||
sigar_dll_func_t end;
|
||||
} sigar_iphlpapi_t;
|
||||
|
||||
typedef struct {
|
||||
sigar_dll_handle_t handle;
|
||||
|
||||
SIGAR_DLLFUNC(advapi, convert_string_sid);
|
||||
SIGAR_DLLFUNC(advapi, query_service_status);
|
||||
|
||||
sigar_dll_func_t end;
|
||||
} sigar_advapi_t;
|
||||
|
||||
typedef struct {
|
||||
sigar_dll_handle_t handle;
|
||||
|
||||
SIGAR_DLLFUNC(ntdll, query_sys_info);
|
||||
SIGAR_DLLFUNC(ntdll, query_proc_info);
|
||||
|
||||
sigar_dll_func_t end;
|
||||
} sigar_ntdll_t;
|
||||
|
||||
typedef struct {
|
||||
sigar_dll_handle_t handle;
|
||||
|
||||
SIGAR_DLLFUNC(psapi, enum_modules);
|
||||
SIGAR_DLLFUNC(psapi, enum_processes);
|
||||
SIGAR_DLLFUNC(psapi, get_module_name);
|
||||
|
||||
sigar_dll_func_t end;
|
||||
} sigar_psapi_t;
|
||||
|
||||
typedef struct {
|
||||
sigar_dll_handle_t handle;
|
||||
|
||||
SIGAR_DLLFUNC(winsta, query_info);
|
||||
|
||||
sigar_dll_func_t end;
|
||||
} sigar_winsta_t;
|
||||
|
||||
typedef struct {
|
||||
sigar_dll_handle_t handle;
|
||||
|
||||
SIGAR_DLLFUNC(kernel, memory_status);
|
||||
|
||||
sigar_dll_func_t end;
|
||||
} sigar_kernel_t;
|
||||
|
||||
typedef struct {
|
||||
sigar_dll_handle_t handle;
|
||||
|
||||
SIGAR_DLLFUNC(mpr, get_net_connection);
|
||||
|
||||
sigar_dll_func_t end;
|
||||
} sigar_mpr_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *buffer;
|
||||
DWORD size;
|
||||
time_t create_time;
|
||||
} buffer_t;
|
||||
|
||||
struct sigar_t {
|
||||
SIGAR_T_BASE;
|
||||
char *machine;
|
||||
int using_wide;
|
||||
long pagesize;
|
||||
HKEY handle;
|
||||
buffer_t** performanceBuffers;
|
||||
buffer_t* processesBuffer;
|
||||
sigar_wtsapi_t wtsapi;
|
||||
sigar_iphlpapi_t iphlpapi;
|
||||
sigar_advapi_t advapi;
|
||||
sigar_ntdll_t ntdll;
|
||||
sigar_psapi_t psapi;
|
||||
sigar_winsta_t winsta;
|
||||
sigar_kernel_t kernel;
|
||||
sigar_mpr_t mpr;
|
||||
sigar_win32_pinfo_t pinfo;
|
||||
sigar_cache_t *netif_adapters;
|
||||
sigar_cache_t *netif_mib_rows;
|
||||
sigar_cache_t *netif_addr_rows;
|
||||
sigar_cache_t *netif_names; /* dwIndex -> net_interface_config.name */
|
||||
int netif_name_short;
|
||||
|
||||
WORD ws_version;
|
||||
int ws_error;
|
||||
int ht_enabled;
|
||||
int lcpu; //number of logical cpus
|
||||
int winnt;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
sigar_uint64_t sigar_FileTimeToTime(FILETIME *ft);
|
||||
|
||||
int sigar_wsa_init(sigar_t *sigar);
|
||||
|
||||
int sigar_proc_exe_peb_get(sigar_t *sigar, HANDLE proc,
|
||||
sigar_proc_exe_t *procexe);
|
||||
|
||||
int sigar_proc_args_peb_get(sigar_t *sigar, HANDLE proc,
|
||||
sigar_proc_args_t *procargs);
|
||||
|
||||
int sigar_proc_env_peb_get(sigar_t *sigar, HANDLE proc,
|
||||
WCHAR *env, DWORD envlen);
|
||||
|
||||
int sigar_proc_args_wmi_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_args_t *procargs);
|
||||
|
||||
int sigar_proc_exe_wmi_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_exe_t *procexe);
|
||||
|
||||
int sigar_parse_proc_args(sigar_t *sigar, WCHAR *buf,
|
||||
sigar_proc_args_t *procargs);
|
||||
|
||||
int sigar_service_pid_get(sigar_t *sigar, char *name, sigar_pid_t *pid);
|
||||
|
||||
typedef struct {
|
||||
DWORD size;
|
||||
DWORD count;
|
||||
ENUM_SERVICE_STATUS *services;
|
||||
SC_HANDLE handle;
|
||||
} sigar_services_status_t;
|
||||
|
||||
int sigar_services_status_get(sigar_services_status_t *ss, DWORD state);
|
||||
|
||||
void sigar_services_status_close(sigar_services_status_t *ss);
|
||||
|
||||
typedef struct sigar_services_walker_t sigar_services_walker_t;
|
||||
|
||||
struct sigar_services_walker_t {
|
||||
sigar_t *sigar;
|
||||
int flags;
|
||||
void *data; /* user data */
|
||||
int (*add_service)(sigar_services_walker_t *walker, char *name);
|
||||
};
|
||||
|
||||
int sigar_services_query(char *ptql,
|
||||
sigar_ptql_error_t *error,
|
||||
sigar_services_walker_t *walker);
|
||||
|
||||
char *sigar_service_exe_get(char *path, char *buffer, int basename);
|
||||
|
||||
typedef struct {
|
||||
WORD product_major;
|
||||
WORD product_minor;
|
||||
WORD product_build;
|
||||
WORD product_revision;
|
||||
WORD file_major;
|
||||
WORD file_minor;
|
||||
WORD file_build;
|
||||
WORD file_revision;
|
||||
} sigar_file_version_t;
|
||||
|
||||
int sigar_file_version_get(sigar_file_version_t *version,
|
||||
char *name,
|
||||
sigar_proc_env_t *infocb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define SIGAR_NO_SUCH_PROCESS (SIGAR_OS_START_ERROR+1)
|
||||
|
||||
#endif /* SIGAR_OS_H */
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2004, 2006 Hyperic, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SIGAR_PDH_H
|
||||
#define SIGAR_PDH_H
|
||||
|
||||
/* performance data helpers */
|
||||
|
||||
#define PdhFirstObject(block) \
|
||||
((PERF_OBJECT_TYPE *)((BYTE *) block + block->HeaderLength))
|
||||
|
||||
#define PdhNextObject(object) \
|
||||
((PERF_OBJECT_TYPE *)((BYTE *) object + object->TotalByteLength))
|
||||
|
||||
#define PdhFirstCounter(object) \
|
||||
((PERF_COUNTER_DEFINITION *)((BYTE *) object + object->HeaderLength))
|
||||
|
||||
#define PdhNextCounter(counter) \
|
||||
((PERF_COUNTER_DEFINITION *)((BYTE *) counter + counter->ByteLength))
|
||||
|
||||
#define PdhGetCounterBlock(inst) \
|
||||
((PERF_COUNTER_BLOCK *)((BYTE *) inst + inst->ByteLength))
|
||||
|
||||
#define PdhFirstInstance(object) \
|
||||
((PERF_INSTANCE_DEFINITION *)((BYTE *) object + object->DefinitionLength))
|
||||
|
||||
#define PdhNextInstance(inst) \
|
||||
((PERF_INSTANCE_DEFINITION *)((BYTE *)inst + inst->ByteLength + \
|
||||
PdhGetCounterBlock(inst)->ByteLength))
|
||||
|
||||
#define PdhInstanceName(inst) \
|
||||
((wchar_t *)((BYTE *)inst + inst->NameOffset))
|
||||
|
||||
#endif /* SIGAR_PDH_H */
|
||||
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2008 Hyperic, Inc.
|
||||
* Copyright (c) 2009 SpringSource, Inc.
|
||||
* Copyright (c) 2009-2010 VMware, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SIGAR_PRIVATE_DOT_H
|
||||
#define SIGAR_PRIVATE_DOT_H
|
||||
|
||||
#include "sigar_log.h"
|
||||
#include "sigar_ptql.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#ifndef DARWIN
|
||||
#include <strings.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DMALLOC
|
||||
#define _MEMORY_H /* exclude memory.h on solaris */
|
||||
#define DMALLOC_FUNC_CHECK
|
||||
#include <dmalloc.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 cpu_list_cores; \
|
||||
int log_level; \
|
||||
void *log_data; \
|
||||
sigar_log_impl_t log_impl; \
|
||||
void *ptql_re_data; \
|
||||
sigar_ptql_re_impl_t ptql_re_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; \
|
||||
char *self_path; \
|
||||
sigar_proc_list_t *pids; \
|
||||
sigar_cache_t *fsdev; \
|
||||
sigar_cache_t *proc_cpu; \
|
||||
sigar_cache_t *net_listen; \
|
||||
sigar_cache_t *net_services_tcp; \
|
||||
sigar_cache_t *net_services_udp;\
|
||||
sigar_cache_t *proc_io
|
||||
|
||||
#if defined(WIN32)
|
||||
# define SIGAR_INLINE __inline
|
||||
#elif defined(__GNUC__)
|
||||
# define SIGAR_INLINE inline
|
||||
#else
|
||||
# define SIGAR_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef DMALLOC
|
||||
/* linux has its own strdup macro, make sure we use dmalloc's */
|
||||
#define sigar_strdup(s) \
|
||||
dmalloc_strndup(__FILE__, __LINE__, (s), -1, 0)
|
||||
#else
|
||||
# ifdef WIN32
|
||||
# define sigar_strdup(s) _strdup(s)
|
||||
# else
|
||||
# define sigar_strdup(s) strdup(s)
|
||||
# endif
|
||||
#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
|
||||
|
||||
#ifdef WIN32
|
||||
#define strcasecmp stricmp
|
||||
#define strncasecmp strnicmp
|
||||
#endif
|
||||
|
||||
#ifndef strcaseEQ
|
||||
#define strcaseEQ(s1, s2) (strcasecmp(s1, s2) == 0)
|
||||
#endif
|
||||
|
||||
#ifndef strncaseEQ
|
||||
#define strncaseEQ(s1, s2, n) (strncasecmp(s1, s2, n) == 0)
|
||||
#endif
|
||||
|
||||
#ifdef offsetof
|
||||
#define sigar_offsetof offsetof
|
||||
#else
|
||||
#define sigar_offsetof(type, field) ((size_t)(&((type *)0)->field))
|
||||
#endif
|
||||
|
||||
#define SIGAR_MSEC 1000L
|
||||
#define SIGAR_USEC 1000000L
|
||||
#define SIGAR_NSEC 1000000000L
|
||||
|
||||
#define SIGAR_SEC2NANO(s) \
|
||||
((sigar_uint64_t)(s) * (sigar_uint64_t)SIGAR_NSEC)
|
||||
|
||||
/* cpu ticks to milliseconds */
|
||||
#define SIGAR_TICK2MSEC(s) \
|
||||
((sigar_uint64_t)(s) * ((sigar_uint64_t)SIGAR_MSEC / (double)sigar->ticks))
|
||||
|
||||
#define SIGAR_TICK2NSEC(s) \
|
||||
((sigar_uint64_t)(s) * ((sigar_uint64_t)SIGAR_NSEC / (double)sigar->ticks))
|
||||
|
||||
/* nanoseconds to milliseconds */
|
||||
#define SIGAR_NSEC2MSEC(s) \
|
||||
((sigar_uint64_t)(s) / ((sigar_uint64_t)1000000L))
|
||||
|
||||
#define IFTYPE_LO 2
|
||||
#define IFTYPE_ETH 3
|
||||
|
||||
#define SIGAR_LAST_PROC_EXPIRE 2
|
||||
|
||||
#define SIGAR_BUFFER_EXPIRE 1000
|
||||
|
||||
#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
|
||||
|
||||
#define SIGAR_ARP_LIST_MAX 12
|
||||
|
||||
#define SIGAR_WHO_LIST_MAX 12
|
||||
|
||||
int sigar_os_open(sigar_t **sigar);
|
||||
|
||||
int sigar_os_close(sigar_t *sigar);
|
||||
|
||||
char *sigar_os_error_string(sigar_t *sigar, int err);
|
||||
|
||||
char *sigar_strerror_get(int err, char *errbuf, int buflen);
|
||||
|
||||
void sigar_strerror_set(sigar_t *sigar, char *msg);
|
||||
|
||||
void sigar_strerror_printf(sigar_t *sigar, const char *format, ...);
|
||||
|
||||
int sigar_sys_info_get_uname(sigar_sys_info_t *sysinfo);
|
||||
|
||||
int sigar_os_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo);
|
||||
|
||||
int sigar_os_proc_list_get(sigar_t *sigar,
|
||||
sigar_proc_list_t *proclist);
|
||||
|
||||
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 *proclist);
|
||||
|
||||
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_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_args_t *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_info_list_create(sigar_cpu_info_list_t *cpu_infos);
|
||||
|
||||
int sigar_cpu_info_list_grow(sigar_cpu_info_list_t *cpu_infos);
|
||||
|
||||
#define SIGAR_CPU_INFO_LIST_GROW(cpu_infos) \
|
||||
if (cpu_infos->number >= cpu_infos->size) { \
|
||||
sigar_cpu_info_list_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); \
|
||||
}
|
||||
|
||||
#define sigar_net_address_set(a, val) \
|
||||
(a).addr.in = val; \
|
||||
(a).family = SIGAR_AF_INET
|
||||
|
||||
#define sigar_net_address6_set(a, val) \
|
||||
memcpy(&((a).addr.in6), val, sizeof((a).addr.in6)); \
|
||||
(a).family = SIGAR_AF_INET6
|
||||
|
||||
#define SIGAR_IFHWADDRLEN 6
|
||||
|
||||
#define sigar_net_address_mac_set(a, val, len) \
|
||||
memcpy(&((a).addr.mac), val, len); \
|
||||
(a).family = SIGAR_AF_LINK
|
||||
|
||||
#define sigar_hwaddr_set_null(ifconfig) \
|
||||
SIGAR_ZERO(&ifconfig->hwaddr.addr.mac); \
|
||||
ifconfig->hwaddr.family = SIGAR_AF_LINK
|
||||
|
||||
int sigar_net_interface_ipv6_config_get(sigar_t *sigar, const char *name,
|
||||
sigar_net_interface_config_t *ifconfig);
|
||||
|
||||
#define sigar_net_interface_ipv6_config_init(ifconfig) \
|
||||
ifconfig->address6.family = SIGAR_AF_INET6; \
|
||||
ifconfig->prefix6_length = 0; \
|
||||
ifconfig->scope6 = 0
|
||||
|
||||
#define SIGAR_SIN6(s) ((struct sockaddr_in6 *)(s))
|
||||
|
||||
#define SIGAR_SIN6_ADDR(s) &SIGAR_SIN6(s)->sin6_addr
|
||||
|
||||
#define sigar_net_interface_scope6_set(ifconfig, addr) \
|
||||
if (IN6_IS_ADDR_LINKLOCAL(addr)) \
|
||||
ifconfig->scope6 = SIGAR_IPV6_ADDR_LINKLOCAL; \
|
||||
else if (IN6_IS_ADDR_SITELOCAL(addr)) \
|
||||
ifconfig->scope6 = SIGAR_IPV6_ADDR_SITELOCAL; \
|
||||
else if (IN6_IS_ADDR_V4COMPAT(addr)) \
|
||||
ifconfig->scope6 = SIGAR_IPV6_ADDR_COMPATv4; \
|
||||
else if (IN6_IS_ADDR_LOOPBACK(addr)) \
|
||||
ifconfig->scope6 = SIGAR_IPV6_ADDR_LOOPBACK; \
|
||||
else \
|
||||
ifconfig->scope6 = SIGAR_IPV6_ADDR_ANY
|
||||
|
||||
int sigar_tcp_curr_estab(sigar_t *sigar, sigar_tcp_t *tcp);
|
||||
|
||||
int sigar_arp_list_create(sigar_arp_list_t *arplist);
|
||||
|
||||
int sigar_arp_list_grow(sigar_arp_list_t *arplist);
|
||||
|
||||
#define SIGAR_ARP_LIST_GROW(arplist) \
|
||||
if (arplist->number >= arplist->size) { \
|
||||
sigar_arp_list_grow(arplist); \
|
||||
}
|
||||
|
||||
int sigar_who_list_create(sigar_who_list_t *wholist);
|
||||
|
||||
int sigar_who_list_grow(sigar_who_list_t *wholist);
|
||||
|
||||
#define SIGAR_WHO_LIST_GROW(wholist) \
|
||||
if (wholist->number >= wholist->size) { \
|
||||
sigar_who_list_grow(wholist); \
|
||||
}
|
||||
|
||||
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; \
|
||||
}
|
||||
|
||||
#define SIGAR_DISK_STATS_INIT(disk) \
|
||||
(disk)->reads = (disk)->writes = \
|
||||
(disk)->read_bytes = (disk)->write_bytes = \
|
||||
(disk)->rtime = (disk)->wtime = (disk)->qtime = (disk)->time = \
|
||||
(disk)->queue = (disk)->service_time = SIGAR_FIELD_NOTIMPL; \
|
||||
(disk)->snaptime = 0
|
||||
|
||||
/* key used for filesystem (/) -> device (/dev/hda1) mapping */
|
||||
/* and disk_usage cache for service_time */
|
||||
#define SIGAR_FSDEV_ID(sb) \
|
||||
(S_ISBLK((sb).st_mode) ? (sb).st_rdev : ((sb).st_ino + (sb).st_dev))
|
||||
|
||||
#if defined(WIN32) || defined(NETWARE)
|
||||
int sigar_get_iftype(const char *name, int *type, int *inst);
|
||||
#endif
|
||||
|
||||
#define SIGAR_NIC_LOOPBACK "Local Loopback"
|
||||
#define SIGAR_NIC_UNSPEC "UNSPEC"
|
||||
#define SIGAR_NIC_SLIP "Serial Line IP"
|
||||
#define SIGAR_NIC_CSLIP "VJ Serial Line IP"
|
||||
#define SIGAR_NIC_SLIP6 "6-bit Serial Line IP"
|
||||
#define SIGAR_NIC_CSLIP6 "VJ 6-bit Serial Line IP"
|
||||
#define SIGAR_NIC_ADAPTIVE "Adaptive Serial Line IP"
|
||||
#define SIGAR_NIC_ETHERNET "Ethernet"
|
||||
#define SIGAR_NIC_ASH "Ash"
|
||||
#define SIGAR_NIC_FDDI "Fiber Distributed Data Interface"
|
||||
#define SIGAR_NIC_HIPPI "HIPPI"
|
||||
#define SIGAR_NIC_AX25 "AMPR AX.25"
|
||||
#define SIGAR_NIC_ROSE "AMPR ROSE"
|
||||
#define SIGAR_NIC_NETROM "AMPR NET/ROM"
|
||||
#define SIGAR_NIC_X25 "generic X.25"
|
||||
#define SIGAR_NIC_TUNNEL "IPIP Tunnel"
|
||||
#define SIGAR_NIC_PPP "Point-to-Point Protocol"
|
||||
#define SIGAR_NIC_HDLC "(Cisco)-HDLC"
|
||||
#define SIGAR_NIC_LAPB "LAPB"
|
||||
#define SIGAR_NIC_ARCNET "ARCnet"
|
||||
#define SIGAR_NIC_DLCI "Frame Relay DLCI"
|
||||
#define SIGAR_NIC_FRAD "Frame Relay Access Device"
|
||||
#define SIGAR_NIC_SIT "IPv6-in-IPv4"
|
||||
#define SIGAR_NIC_IRDA "IrLAP"
|
||||
#define SIGAR_NIC_EC "Econet"
|
||||
#define PID_CACHE_CLEANUP_PERIOD 1000*60*10 /* 10 minutes */
|
||||
#define PID_CACHE_ENTRY_EXPIRE_PERIOD 1000*60*20 /* 20 minutes */
|
||||
#ifndef WIN32
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#define PROC_PID_CPU_CACHE 1
|
||||
#define PROC_PID_IO_CACHE 2
|
||||
|
||||
#define SIGAR_HOSTENT_LEN 1024
|
||||
#if defined(_AIX)
|
||||
#define SIGAR_HAS_HOSTENT_DATA
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char buffer[SIGAR_HOSTENT_LEN];
|
||||
int error;
|
||||
#ifndef WIN32
|
||||
struct hostent hs;
|
||||
#endif
|
||||
#ifdef SIGAR_HAS_HOSTENT_DATA
|
||||
struct hostent_data hd;
|
||||
#endif
|
||||
} sigar_hostent_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2007 Hyperic, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SIGAR_PTQL_H
|
||||
#define SIGAR_PTQL_H
|
||||
|
||||
#define SIGAR_PTQL_MALFORMED_QUERY -1
|
||||
|
||||
typedef struct sigar_ptql_query_t sigar_ptql_query_t;
|
||||
|
||||
#define SIGAR_PTQL_ERRMSG_SIZE 1024
|
||||
|
||||
typedef struct {
|
||||
char message[SIGAR_PTQL_ERRMSG_SIZE];
|
||||
} sigar_ptql_error_t;
|
||||
|
||||
typedef int (*sigar_ptql_re_impl_t)(void *, char *, char *);
|
||||
|
||||
SIGAR_DECLARE(void) sigar_ptql_re_impl_set(sigar_t *sigar, void *data,
|
||||
sigar_ptql_re_impl_t impl);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_ptql_query_create(sigar_ptql_query_t **query,
|
||||
char *ptql,
|
||||
sigar_ptql_error_t *error);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_ptql_query_match(sigar_t *sigar,
|
||||
sigar_ptql_query_t *query,
|
||||
sigar_pid_t pid);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_ptql_query_destroy(sigar_ptql_query_t *query);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_ptql_query_find_process(sigar_t *sigar,
|
||||
sigar_ptql_query_t *query,
|
||||
sigar_pid_t *pid);
|
||||
|
||||
SIGAR_DECLARE(int) sigar_ptql_query_find(sigar_t *sigar,
|
||||
sigar_ptql_query_t *query,
|
||||
sigar_proc_list_t *proclist);
|
||||
|
||||
#endif /*SIGAR_PTQL_H*/
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2008 Hyperic, Inc.
|
||||
* Copyright (c) 2009 SpringSource, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#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_strtoull(ptr) \
|
||||
strtoull(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 sigar_isupper(c) \
|
||||
(isupper(((unsigned char)(c))))
|
||||
|
||||
#define sigar_tolower(c) \
|
||||
(tolower(((unsigned char)(c))))
|
||||
|
||||
#ifdef WIN32
|
||||
#define sigar_fileno _fileno
|
||||
#define sigar_isatty _isatty
|
||||
#define sigar_write _write
|
||||
#else
|
||||
#define sigar_fileno fileno
|
||||
#define sigar_isatty isatty
|
||||
#define sigar_write write
|
||||
#endif
|
||||
|
||||
#ifndef PROC_FS_ROOT
|
||||
#define PROC_FS_ROOT "/proc/"
|
||||
#endif
|
||||
|
||||
#ifndef PROCP_FS_ROOT
|
||||
#define PROCP_FS_ROOT "/proc/"
|
||||
#endif
|
||||
|
||||
sigar_int64_t sigar_time_now_millis(void);
|
||||
|
||||
char *sigar_uitoa(char *buf, unsigned int n, int *len);
|
||||
|
||||
int sigar_inet_ntoa(sigar_t *sigar,
|
||||
sigar_uint32_t address,
|
||||
char *addr_str);
|
||||
|
||||
struct hostent *sigar_gethostbyname(const char *name,
|
||||
sigar_hostent_t *data);
|
||||
|
||||
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);
|
||||
|
||||
char *sigar_getword(char **line, char stop);
|
||||
|
||||
char *sigar_strcasestr(const char *s1, const char *s2);
|
||||
|
||||
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);
|
||||
|
||||
/* linux + freebsd */
|
||||
int sigar_procfs_args_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_args_t *procargs);
|
||||
|
||||
int sigar_mem_calc_ram(sigar_t *sigar, sigar_mem_t *mem);
|
||||
|
||||
int sigar_statvfs(sigar_t *sigar,
|
||||
const char *dirname,
|
||||
sigar_file_system_usage_t *fsusage);
|
||||
|
||||
double sigar_file_system_usage_calc_used(sigar_t *sigar,
|
||||
sigar_file_system_usage_t *fs);
|
||||
|
||||
#define SIGAR_DEV_PREFIX "/dev/"
|
||||
|
||||
#define SIGAR_NAME_IS_DEV(dev) \
|
||||
strnEQ(dev, SIGAR_DEV_PREFIX, SSTRLEN(SIGAR_DEV_PREFIX))
|
||||
|
||||
typedef struct {
|
||||
char name[256];
|
||||
int is_partition;
|
||||
sigar_disk_usage_t disk;
|
||||
} sigar_iodev_t;
|
||||
|
||||
sigar_iodev_t *sigar_iodev_get(sigar_t *sigar,
|
||||
const char *dirname);
|
||||
|
||||
int sigar_cpu_core_count(sigar_t *sigar);
|
||||
|
||||
/* e.g. VM guest may have 1 virtual ncpu on multicore hosts */
|
||||
#define sigar_cpu_socket_count(sigar) \
|
||||
(sigar->ncpu < sigar->lcpu) ? sigar->ncpu : \
|
||||
(sigar->ncpu / sigar->lcpu)
|
||||
|
||||
int sigar_cpu_core_rollup(sigar_t *sigar);
|
||||
|
||||
void sigar_cpu_model_adjust(sigar_t *sigar, sigar_cpu_info_t *info);
|
||||
|
||||
int sigar_cpu_mhz_from_model(char *model);
|
||||
|
||||
char *sigar_get_self_path(sigar_t *sigar);
|
||||
|
||||
#if defined(__sun) || defined(__FreeBSD__)
|
||||
|
||||
#define SIGAR_HAS_DLINFO_MODULES
|
||||
#include <dlfcn.h>
|
||||
#include <link.h>
|
||||
|
||||
int sigar_dlinfo_modules(sigar_t *sigar, sigar_proc_modules_t *procmods);
|
||||
#endif
|
||||
|
||||
typedef struct sigar_cache_entry_t sigar_cache_entry_t;
|
||||
|
||||
struct sigar_cache_entry_t {
|
||||
sigar_cache_entry_t *next;
|
||||
sigar_uint64_t id;
|
||||
void *value;
|
||||
sigar_uint64_t last_access_time;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
sigar_cache_entry_t **entries;
|
||||
unsigned int count, size;
|
||||
void (*free_value)(void *ptr);
|
||||
sigar_uint64_t entry_expire_period;
|
||||
sigar_uint64_t cleanup_period_millis;
|
||||
sigar_uint64_t last_cleanup_time;
|
||||
} sigar_cache_t;
|
||||
|
||||
sigar_cache_t *sigar_cache_new(int size);
|
||||
sigar_cache_t *sigar_expired_cache_new(int size, sigar_uint64_t cleanup_period_millis, sigar_uint64_t entry_expire_period);
|
||||
void sigar_cache_dump(sigar_cache_t *table);
|
||||
|
||||
sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
|
||||
sigar_uint64_t key);
|
||||
|
||||
sigar_cache_entry_t *sigar_cache_find(sigar_cache_t *table,
|
||||
sigar_uint64_t key);
|
||||
|
||||
void sigar_cache_destroy(sigar_cache_t *table);
|
||||
|
||||
#endif /* SIGAR_UTIL_H */
|
||||
Reference in new issue
Block a user