sigar 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +2 -0
- data/Rakefile +105 -0
- data/bindings/SigarBuild.pm +310 -0
- data/bindings/SigarWrapper.pm +2978 -0
- data/bindings/ruby/examples/arp.rb +24 -0
- data/bindings/ruby/examples/cpu_info.rb +35 -0
- data/bindings/ruby/examples/df.rb +49 -0
- data/bindings/ruby/examples/free.rb +36 -0
- data/bindings/ruby/examples/ifconfig.rb +101 -0
- data/bindings/ruby/examples/logging.rb +58 -0
- data/bindings/ruby/examples/net_info.rb +31 -0
- data/bindings/ruby/examples/netstat.rb +71 -0
- data/bindings/ruby/examples/pargs.rb +35 -0
- data/bindings/ruby/examples/penv.rb +31 -0
- data/bindings/ruby/examples/route.rb +48 -0
- data/bindings/ruby/examples/version.rb +40 -0
- data/bindings/ruby/examples/who.rb +30 -0
- data/bindings/ruby/extconf.rb +128 -0
- data/bindings/ruby/rbsigar.c +888 -0
- data/bindings/ruby/test/cpu_test.rb +40 -0
- data/bindings/ruby/test/file_system_test.rb +43 -0
- data/bindings/ruby/test/helper.rb +57 -0
- data/bindings/ruby/test/loadavg_test.rb +30 -0
- data/bindings/ruby/test/mem_test.rb +45 -0
- data/bindings/ruby/test/swap_test.rb +36 -0
- data/bindings/ruby/test/uptime_test.rb +26 -0
- data/include/sigar.h +939 -0
- data/include/sigar_fileinfo.h +157 -0
- data/include/sigar_format.h +65 -0
- data/include/sigar_getline.h +18 -0
- data/include/sigar_log.h +80 -0
- data/include/sigar_private.h +422 -0
- data/include/sigar_ptql.h +53 -0
- data/include/sigar_util.h +191 -0
- data/src/os/aix/aix_sigar.c +2151 -0
- data/src/os/aix/sigar_os.h +73 -0
- data/src/os/darwin/Info.plist.in +27 -0
- data/src/os/darwin/darwin_sigar.c +3709 -0
- data/src/os/darwin/sigar_os.h +80 -0
- data/src/os/hpux/hpux_sigar.c +1342 -0
- data/src/os/hpux/sigar_os.h +49 -0
- data/src/os/linux/linux_sigar.c +2782 -0
- data/src/os/linux/sigar_os.h +82 -0
- data/src/os/solaris/get_mib2.c +321 -0
- data/src/os/solaris/get_mib2.h +127 -0
- data/src/os/solaris/kstats.c +181 -0
- data/src/os/solaris/procfs.c +97 -0
- data/src/os/solaris/sigar_os.h +224 -0
- data/src/os/solaris/solaris_sigar.c +2717 -0
- data/src/os/win32/peb.c +212 -0
- data/src/os/win32/sigar.rc.in +40 -0
- data/src/os/win32/sigar_os.h +653 -0
- data/src/os/win32/sigar_pdh.h +47 -0
- data/src/os/win32/win32_sigar.c +3911 -0
- data/src/sigar.c +2428 -0
- data/src/sigar_cache.c +179 -0
- data/src/sigar_fileinfo.c +815 -0
- data/src/sigar_format.c +696 -0
- data/src/sigar_getline.c +1849 -0
- data/src/sigar_ptql.c +1967 -0
- data/src/sigar_signal.c +216 -0
- data/src/sigar_util.c +1060 -0
- data/src/sigar_version.c.in +22 -0
- data/src/sigar_version_autoconf.c.in +22 -0
- data/version.properties +11 -0
- metadata +131 -0
@@ -0,0 +1,157 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2004-2005 Hyperic, Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
/* ====================================================================
|
18
|
+
* The Apache Software License, Version 1.1
|
19
|
+
*
|
20
|
+
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
|
21
|
+
* reserved.
|
22
|
+
*
|
23
|
+
* Redistribution and use in source and binary forms, with or without
|
24
|
+
* modification, are permitted provided that the following conditions
|
25
|
+
* are met:
|
26
|
+
*
|
27
|
+
* 1. Redistributions of source code must retain the above copyright
|
28
|
+
* notice, this list of conditions and the following disclaimer.
|
29
|
+
*
|
30
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
31
|
+
* notice, this list of conditions and the following disclaimer in
|
32
|
+
* the documentation and/or other materials provided with the
|
33
|
+
* distribution.
|
34
|
+
*
|
35
|
+
* 3. The end-user documentation included with the redistribution,
|
36
|
+
* if any, must include the following acknowledgment:
|
37
|
+
* "This product includes software developed by the
|
38
|
+
* Apache Software Foundation (http://www.apache.org/)."
|
39
|
+
* Alternately, this acknowledgment may appear in the software itself,
|
40
|
+
* if and wherever such third-party acknowledgments normally appear.
|
41
|
+
*
|
42
|
+
* 4. The names "Apache" and "Apache Software Foundation" must
|
43
|
+
* not be used to endorse or promote products derived from this
|
44
|
+
* software without prior written permission. For written
|
45
|
+
* permission, please contact apache@apache.org.
|
46
|
+
*
|
47
|
+
* 5. Products derived from this software may not be called "Apache",
|
48
|
+
* nor may "Apache" appear in their name, without prior written
|
49
|
+
* permission of the Apache Software Foundation.
|
50
|
+
*
|
51
|
+
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
52
|
+
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
53
|
+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
54
|
+
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
55
|
+
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
56
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
57
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
58
|
+
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
59
|
+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
60
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
61
|
+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
62
|
+
* SUCH DAMAGE.
|
63
|
+
* ====================================================================
|
64
|
+
*
|
65
|
+
* This software consists of voluntary contributions made by many
|
66
|
+
* individuals on behalf of the Apache Software Foundation. For more
|
67
|
+
* information on the Apache Software Foundation, please see
|
68
|
+
* <http://www.apache.org/>.
|
69
|
+
*/
|
70
|
+
|
71
|
+
#include "sigar.h"
|
72
|
+
|
73
|
+
typedef enum {
|
74
|
+
SIGAR_FILETYPE_NOFILE = 0, /**< no file type determined */
|
75
|
+
SIGAR_FILETYPE_REG, /**< a regular file */
|
76
|
+
SIGAR_FILETYPE_DIR, /**< a directory */
|
77
|
+
SIGAR_FILETYPE_CHR, /**< a character device */
|
78
|
+
SIGAR_FILETYPE_BLK, /**< a block device */
|
79
|
+
SIGAR_FILETYPE_PIPE, /**< a FIFO / pipe */
|
80
|
+
SIGAR_FILETYPE_LNK, /**< a symbolic link */
|
81
|
+
SIGAR_FILETYPE_SOCK, /**< a [unix domain] socket */
|
82
|
+
SIGAR_FILETYPE_UNKFILE /**< a file of some other unknown type */
|
83
|
+
} sigar_file_type_e;
|
84
|
+
|
85
|
+
#define SIGAR_UREAD 0x0400 /**< Read by user */
|
86
|
+
#define SIGAR_UWRITE 0x0200 /**< Write by user */
|
87
|
+
#define SIGAR_UEXECUTE 0x0100 /**< Execute by user */
|
88
|
+
|
89
|
+
#define SIGAR_GREAD 0x0040 /**< Read by group */
|
90
|
+
#define SIGAR_GWRITE 0x0020 /**< Write by group */
|
91
|
+
#define SIGAR_GEXECUTE 0x0010 /**< Execute by group */
|
92
|
+
|
93
|
+
#define SIGAR_WREAD 0x0004 /**< Read by others */
|
94
|
+
#define SIGAR_WWRITE 0x0002 /**< Write by others */
|
95
|
+
#define SIGAR_WEXECUTE 0x0001 /**< Execute by others */
|
96
|
+
|
97
|
+
typedef struct {
|
98
|
+
/** The access permissions of the file. Mimics Unix access rights. */
|
99
|
+
sigar_uint64_t permissions;
|
100
|
+
sigar_file_type_e type;
|
101
|
+
/** The user id that owns the file */
|
102
|
+
sigar_uid_t uid;
|
103
|
+
/** The group id that owns the file */
|
104
|
+
sigar_gid_t gid;
|
105
|
+
/** The inode of the file. */
|
106
|
+
sigar_uint64_t inode;
|
107
|
+
/** The id of the device the file is on. */
|
108
|
+
sigar_uint64_t device;
|
109
|
+
/** The number of hard links to the file. */
|
110
|
+
sigar_uint64_t nlink;
|
111
|
+
/** The size of the file */
|
112
|
+
sigar_uint64_t size;
|
113
|
+
/** The time the file was last accessed */
|
114
|
+
sigar_uint64_t atime;
|
115
|
+
/** The time the file was last modified */
|
116
|
+
sigar_uint64_t mtime;
|
117
|
+
/** The time the file was last changed */
|
118
|
+
sigar_uint64_t ctime;
|
119
|
+
} sigar_file_attrs_t;
|
120
|
+
|
121
|
+
typedef struct {
|
122
|
+
sigar_uint64_t total;
|
123
|
+
sigar_uint64_t files;
|
124
|
+
sigar_uint64_t subdirs;
|
125
|
+
sigar_uint64_t symlinks;
|
126
|
+
sigar_uint64_t chrdevs;
|
127
|
+
sigar_uint64_t blkdevs;
|
128
|
+
sigar_uint64_t sockets;
|
129
|
+
sigar_uint64_t disk_usage;
|
130
|
+
} sigar_dir_stat_t;
|
131
|
+
|
132
|
+
typedef sigar_dir_stat_t sigar_dir_usage_t;
|
133
|
+
|
134
|
+
SIGAR_DECLARE(const char *)
|
135
|
+
sigar_file_attrs_type_string_get(sigar_file_type_e type);
|
136
|
+
|
137
|
+
SIGAR_DECLARE(int) sigar_file_attrs_get(sigar_t *sigar,
|
138
|
+
const char *file,
|
139
|
+
sigar_file_attrs_t *fileattrs);
|
140
|
+
|
141
|
+
SIGAR_DECLARE(int) sigar_link_attrs_get(sigar_t *sigar,
|
142
|
+
const char *file,
|
143
|
+
sigar_file_attrs_t *fileattrs);
|
144
|
+
|
145
|
+
SIGAR_DECLARE(int)sigar_file_attrs_mode_get(sigar_uint64_t permissions);
|
146
|
+
|
147
|
+
SIGAR_DECLARE(char *)
|
148
|
+
sigar_file_attrs_permissions_string_get(sigar_uint64_t permissions,
|
149
|
+
char *str);
|
150
|
+
|
151
|
+
SIGAR_DECLARE(int) sigar_dir_stat_get(sigar_t *sigar,
|
152
|
+
const char *dir,
|
153
|
+
sigar_dir_stat_t *dirstats);
|
154
|
+
|
155
|
+
SIGAR_DECLARE(int) sigar_dir_usage_get(sigar_t *sigar,
|
156
|
+
const char *dir,
|
157
|
+
sigar_dir_usage_t *dirusage);
|
@@ -0,0 +1,65 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007-2008 Hyperic, Inc.
|
3
|
+
* Copyright (c) 2009 SpringSource, Inc.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#ifndef SIGAR_FORMAT_H
|
19
|
+
#define SIGAR_FORMAT_H
|
20
|
+
|
21
|
+
typedef struct {
|
22
|
+
double user;
|
23
|
+
double sys;
|
24
|
+
double nice;
|
25
|
+
double idle;
|
26
|
+
double wait;
|
27
|
+
double irq;
|
28
|
+
double soft_irq;
|
29
|
+
double stolen;
|
30
|
+
double combined;
|
31
|
+
} sigar_cpu_perc_t;
|
32
|
+
|
33
|
+
SIGAR_DECLARE(int) sigar_cpu_perc_calculate(sigar_cpu_t *prev,
|
34
|
+
sigar_cpu_t *curr,
|
35
|
+
sigar_cpu_perc_t *perc);
|
36
|
+
|
37
|
+
SIGAR_DECLARE(int) sigar_uptime_string(sigar_t *sigar,
|
38
|
+
sigar_uptime_t *uptime,
|
39
|
+
char *buffer,
|
40
|
+
int buflen);
|
41
|
+
|
42
|
+
SIGAR_DECLARE(char *) sigar_format_size(sigar_uint64_t size, char *buf);
|
43
|
+
|
44
|
+
SIGAR_DECLARE(int) sigar_net_address_equals(sigar_net_address_t *addr1,
|
45
|
+
sigar_net_address_t *addr2);
|
46
|
+
|
47
|
+
SIGAR_DECLARE(int) sigar_net_address_to_string(sigar_t *sigar,
|
48
|
+
sigar_net_address_t *address,
|
49
|
+
char *addr_str);
|
50
|
+
|
51
|
+
SIGAR_DECLARE(const char *)sigar_net_scope_to_string(int type);
|
52
|
+
|
53
|
+
SIGAR_DECLARE(sigar_uint32_t) sigar_net_address_hash(sigar_net_address_t *address);
|
54
|
+
|
55
|
+
SIGAR_DECLARE(const char *)sigar_net_connection_type_get(int type);
|
56
|
+
|
57
|
+
SIGAR_DECLARE(const char *)sigar_net_connection_state_get(int state);
|
58
|
+
|
59
|
+
SIGAR_DECLARE(char *) sigar_net_interface_flags_to_string(sigar_uint64_t flags, char *buf);
|
60
|
+
|
61
|
+
SIGAR_DECLARE(char *)sigar_net_services_name_get(sigar_t *sigar,
|
62
|
+
int protocol, unsigned long port);
|
63
|
+
|
64
|
+
#endif
|
65
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#ifndef SIGAR_GETLINE_H
|
2
|
+
#define SIGAR_GETLINE_H
|
3
|
+
|
4
|
+
#include "sigar.h"
|
5
|
+
|
6
|
+
typedef int (*sigar_getline_completer_t)(char *, int, int *);
|
7
|
+
|
8
|
+
SIGAR_DECLARE(char *) sigar_getline(char *prompt);
|
9
|
+
SIGAR_DECLARE(void) sigar_getline_setwidth(int width);
|
10
|
+
SIGAR_DECLARE(void) sigar_getline_redraw(void);
|
11
|
+
SIGAR_DECLARE(void) sigar_getline_reset(void);
|
12
|
+
SIGAR_DECLARE(void) sigar_getline_windowchanged();
|
13
|
+
SIGAR_DECLARE(void) sigar_getline_histinit(char *file);
|
14
|
+
SIGAR_DECLARE(void) sigar_getline_histadd(char *buf);
|
15
|
+
SIGAR_DECLARE(int) sigar_getline_eof();
|
16
|
+
SIGAR_DECLARE(void) sigar_getline_completer_set(sigar_getline_completer_t func);
|
17
|
+
|
18
|
+
#endif /* SIGAR_GETLINE_H */
|
data/include/sigar_log.h
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2004, 2006 Hyperic, Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#ifndef SIGAR_LOG_H
|
18
|
+
#define SIGAR_LOG_H
|
19
|
+
|
20
|
+
#include <stdarg.h>
|
21
|
+
|
22
|
+
#define SIGAR_LOG_FATAL 0
|
23
|
+
#define SIGAR_LOG_ERROR 1
|
24
|
+
#define SIGAR_LOG_WARN 2
|
25
|
+
#define SIGAR_LOG_INFO 3
|
26
|
+
#define SIGAR_LOG_DEBUG 4
|
27
|
+
#define SIGAR_LOG_TRACE 5
|
28
|
+
|
29
|
+
#define SIGAR_LOG_IS_FATAL(sigar) \
|
30
|
+
(sigar->log_level >= SIGAR_LOG_FATAL)
|
31
|
+
|
32
|
+
#define SIGAR_LOG_IS_ERROR(sigar) \
|
33
|
+
(sigar->log_level >= SIGAR_LOG_ERROR)
|
34
|
+
|
35
|
+
#define SIGAR_LOG_IS_WARN(sigar) \
|
36
|
+
(sigar->log_level >= SIGAR_LOG_WARN)
|
37
|
+
|
38
|
+
#define SIGAR_LOG_IS_INFO(sigar) \
|
39
|
+
(sigar->log_level >= SIGAR_LOG_INFO)
|
40
|
+
|
41
|
+
#define SIGAR_LOG_IS_DEBUG(sigar) \
|
42
|
+
(sigar->log_level >= SIGAR_LOG_DEBUG)
|
43
|
+
|
44
|
+
#define SIGAR_LOG_IS_TRACE(sigar) \
|
45
|
+
(sigar->log_level >= SIGAR_LOG_TRACE)
|
46
|
+
|
47
|
+
#define SIGAR_STRINGIFY(n) #n
|
48
|
+
|
49
|
+
#define SIGAR_LOG_FILELINE \
|
50
|
+
__FILE__ ":" SIGAR_STRINGIFY(__LINE__)
|
51
|
+
|
52
|
+
#if defined(__GNUC__)
|
53
|
+
# if (__GNUC__ > 2)
|
54
|
+
# define SIGAR_FUNC __func__
|
55
|
+
# else
|
56
|
+
# define SIGAR_FUNC __FUNCTION__
|
57
|
+
# endif
|
58
|
+
#else
|
59
|
+
# define SIGAR_FUNC SIGAR_LOG_FILELINE
|
60
|
+
#endif
|
61
|
+
|
62
|
+
typedef void (*sigar_log_impl_t)(sigar_t *, void *, int, char *);
|
63
|
+
|
64
|
+
SIGAR_DECLARE(void) sigar_log_printf(sigar_t *sigar, int level,
|
65
|
+
const char *format, ...);
|
66
|
+
|
67
|
+
SIGAR_DECLARE(void) sigar_log(sigar_t *sigar, int level, char *message);
|
68
|
+
|
69
|
+
SIGAR_DECLARE(void) sigar_log_impl_set(sigar_t *sigar, void *data,
|
70
|
+
sigar_log_impl_t impl);
|
71
|
+
|
72
|
+
SIGAR_DECLARE(void) sigar_log_impl_file(sigar_t *sigar, void *data,
|
73
|
+
int level, char *message);
|
74
|
+
|
75
|
+
SIGAR_DECLARE(int) sigar_log_level_get(sigar_t *sigar);
|
76
|
+
|
77
|
+
SIGAR_DECLARE(void) sigar_log_level_set(sigar_t *sigar, int level);
|
78
|
+
|
79
|
+
|
80
|
+
#endif /* SIGAR_LOG_H */
|
@@ -0,0 +1,422 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2004-2008 Hyperic, Inc.
|
3
|
+
* Copyright (c) 2009 SpringSource, Inc.
|
4
|
+
* Copyright (c) 2009-2010 VMware, Inc.
|
5
|
+
*
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
* you may not use this file except in compliance with the License.
|
8
|
+
* You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
* See the License for the specific language governing permissions and
|
16
|
+
* limitations under the License.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef SIGAR_PRIVATE_DOT_H
|
20
|
+
#define SIGAR_PRIVATE_DOT_H
|
21
|
+
|
22
|
+
#include "sigar_log.h"
|
23
|
+
#include "sigar_ptql.h"
|
24
|
+
|
25
|
+
#include <stdlib.h>
|
26
|
+
#include <string.h>
|
27
|
+
#include <ctype.h>
|
28
|
+
|
29
|
+
#ifndef WIN32
|
30
|
+
#include <unistd.h>
|
31
|
+
#include <stddef.h>
|
32
|
+
#ifndef DARWIN
|
33
|
+
#include <strings.h>
|
34
|
+
#endif
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#ifdef DMALLOC
|
38
|
+
#define _MEMORY_H /* exclude memory.h on solaris */
|
39
|
+
#define DMALLOC_FUNC_CHECK
|
40
|
+
#include <dmalloc.h>
|
41
|
+
#endif
|
42
|
+
|
43
|
+
/* common to all os sigar_t's */
|
44
|
+
/* XXX: this is ugly; but don't want the same stuffs
|
45
|
+
* duplicated on 4 platforms and am too lazy to change
|
46
|
+
* sigar_t to the way it was originally where sigar_t was
|
47
|
+
* common and contained a sigar_os_t.
|
48
|
+
* feel free trav ;-)
|
49
|
+
*/
|
50
|
+
#define SIGAR_T_BASE \
|
51
|
+
int cpu_list_cores; \
|
52
|
+
int log_level; \
|
53
|
+
void *log_data; \
|
54
|
+
sigar_log_impl_t log_impl; \
|
55
|
+
void *ptql_re_data; \
|
56
|
+
sigar_ptql_re_impl_t ptql_re_impl; \
|
57
|
+
unsigned int ncpu; \
|
58
|
+
unsigned long version; \
|
59
|
+
unsigned long boot_time; \
|
60
|
+
int ticks; \
|
61
|
+
sigar_pid_t pid; \
|
62
|
+
char errbuf[256]; \
|
63
|
+
char *ifconf_buf; \
|
64
|
+
int ifconf_len; \
|
65
|
+
char *self_path; \
|
66
|
+
sigar_proc_list_t *pids; \
|
67
|
+
sigar_cache_t *fsdev; \
|
68
|
+
sigar_cache_t *proc_cpu; \
|
69
|
+
sigar_cache_t *net_listen; \
|
70
|
+
sigar_cache_t *net_services_tcp; \
|
71
|
+
sigar_cache_t *net_services_udp
|
72
|
+
|
73
|
+
#if defined(WIN32)
|
74
|
+
# define SIGAR_INLINE __inline
|
75
|
+
#elif defined(__GNUC__)
|
76
|
+
# define SIGAR_INLINE inline
|
77
|
+
#else
|
78
|
+
# define SIGAR_INLINE
|
79
|
+
#endif
|
80
|
+
|
81
|
+
#ifdef DMALLOC
|
82
|
+
/* linux has its own strdup macro, make sure we use dmalloc's */
|
83
|
+
#define sigar_strdup(s) \
|
84
|
+
dmalloc_strndup(__FILE__, __LINE__, (s), -1, 0)
|
85
|
+
#else
|
86
|
+
# ifdef WIN32
|
87
|
+
# define sigar_strdup(s) _strdup(s)
|
88
|
+
# else
|
89
|
+
# define sigar_strdup(s) strdup(s)
|
90
|
+
# endif
|
91
|
+
#endif
|
92
|
+
|
93
|
+
#define SIGAR_ZERO(s) \
|
94
|
+
memset(s, '\0', sizeof(*(s)))
|
95
|
+
|
96
|
+
#define SIGAR_STRNCPY(dest, src, len) \
|
97
|
+
strncpy(dest, src, len); \
|
98
|
+
dest[len-1] = '\0'
|
99
|
+
|
100
|
+
/* we use fixed size buffers pretty much everywhere */
|
101
|
+
/* this is strncpy + ensured \0 terminator */
|
102
|
+
#define SIGAR_SSTRCPY(dest, src) \
|
103
|
+
SIGAR_STRNCPY(dest, src, sizeof(dest))
|
104
|
+
|
105
|
+
#ifndef strEQ
|
106
|
+
#define strEQ(s1, s2) (strcmp(s1, s2) == 0)
|
107
|
+
#endif
|
108
|
+
|
109
|
+
#ifndef strnEQ
|
110
|
+
#define strnEQ(s1, s2, n) (strncmp(s1, s2, n) == 0)
|
111
|
+
#endif
|
112
|
+
|
113
|
+
#ifdef WIN32
|
114
|
+
#define strcasecmp stricmp
|
115
|
+
#define strncasecmp strnicmp
|
116
|
+
#endif
|
117
|
+
|
118
|
+
#ifndef strcaseEQ
|
119
|
+
#define strcaseEQ(s1, s2) (strcasecmp(s1, s2) == 0)
|
120
|
+
#endif
|
121
|
+
|
122
|
+
#ifndef strncaseEQ
|
123
|
+
#define strncaseEQ(s1, s2, n) (strncasecmp(s1, s2, n) == 0)
|
124
|
+
#endif
|
125
|
+
|
126
|
+
#ifdef offsetof
|
127
|
+
#define sigar_offsetof offsetof
|
128
|
+
#else
|
129
|
+
#define sigar_offsetof(type, field) ((size_t)(&((type *)0)->field))
|
130
|
+
#endif
|
131
|
+
|
132
|
+
#define SIGAR_MSEC 1000L
|
133
|
+
#define SIGAR_USEC 1000000L
|
134
|
+
#define SIGAR_NSEC 1000000000L
|
135
|
+
|
136
|
+
#define SIGAR_SEC2NANO(s) \
|
137
|
+
((sigar_uint64_t)(s) * (sigar_uint64_t)SIGAR_NSEC)
|
138
|
+
|
139
|
+
/* cpu ticks to milliseconds */
|
140
|
+
#define SIGAR_TICK2MSEC(s) \
|
141
|
+
((sigar_uint64_t)(s) * ((sigar_uint64_t)SIGAR_MSEC / (double)sigar->ticks))
|
142
|
+
|
143
|
+
#define SIGAR_TICK2NSEC(s) \
|
144
|
+
((sigar_uint64_t)(s) * ((sigar_uint64_t)SIGAR_NSEC / (double)sigar->ticks))
|
145
|
+
|
146
|
+
/* nanoseconds to milliseconds */
|
147
|
+
#define SIGAR_NSEC2MSEC(s) \
|
148
|
+
((sigar_uint64_t)(s) / ((sigar_uint64_t)1000000L))
|
149
|
+
|
150
|
+
#define IFTYPE_LO 2
|
151
|
+
#define IFTYPE_ETH 3
|
152
|
+
|
153
|
+
#define SIGAR_LAST_PROC_EXPIRE 2
|
154
|
+
|
155
|
+
#define SIGAR_FS_MAX 10
|
156
|
+
|
157
|
+
#define SIGAR_CPU_INFO_MAX 4
|
158
|
+
|
159
|
+
#define SIGAR_CPU_LIST_MAX 4
|
160
|
+
|
161
|
+
#define SIGAR_PROC_LIST_MAX 256
|
162
|
+
|
163
|
+
#define SIGAR_PROC_ARGS_MAX 12
|
164
|
+
|
165
|
+
#define SIGAR_NET_ROUTE_LIST_MAX 6
|
166
|
+
|
167
|
+
#define SIGAR_NET_IFLIST_MAX 20
|
168
|
+
|
169
|
+
#define SIGAR_NET_CONNLIST_MAX 20
|
170
|
+
|
171
|
+
#define SIGAR_ARP_LIST_MAX 12
|
172
|
+
|
173
|
+
#define SIGAR_WHO_LIST_MAX 12
|
174
|
+
|
175
|
+
int sigar_os_open(sigar_t **sigar);
|
176
|
+
|
177
|
+
int sigar_os_close(sigar_t *sigar);
|
178
|
+
|
179
|
+
char *sigar_os_error_string(sigar_t *sigar, int err);
|
180
|
+
|
181
|
+
char *sigar_strerror_get(int err, char *errbuf, int buflen);
|
182
|
+
|
183
|
+
void sigar_strerror_set(sigar_t *sigar, char *msg);
|
184
|
+
|
185
|
+
void sigar_strerror_printf(sigar_t *sigar, const char *format, ...);
|
186
|
+
|
187
|
+
int sigar_sys_info_get_uname(sigar_sys_info_t *sysinfo);
|
188
|
+
|
189
|
+
int sigar_os_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo);
|
190
|
+
|
191
|
+
int sigar_os_proc_list_get(sigar_t *sigar,
|
192
|
+
sigar_proc_list_t *proclist);
|
193
|
+
|
194
|
+
int sigar_proc_list_create(sigar_proc_list_t *proclist);
|
195
|
+
|
196
|
+
int sigar_proc_list_grow(sigar_proc_list_t *proclist);
|
197
|
+
|
198
|
+
#define SIGAR_PROC_LIST_GROW(proclist) \
|
199
|
+
if (proclist->number >= proclist->size) { \
|
200
|
+
sigar_proc_list_grow(proclist); \
|
201
|
+
}
|
202
|
+
|
203
|
+
int sigar_proc_args_create(sigar_proc_args_t *proclist);
|
204
|
+
|
205
|
+
int sigar_proc_args_grow(sigar_proc_args_t *procargs);
|
206
|
+
|
207
|
+
#define SIGAR_PROC_ARGS_GROW(procargs) \
|
208
|
+
if (procargs->number >= procargs->size) { \
|
209
|
+
sigar_proc_args_grow(procargs); \
|
210
|
+
}
|
211
|
+
|
212
|
+
int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
213
|
+
sigar_proc_args_t *procargs);
|
214
|
+
|
215
|
+
int sigar_file_system_list_create(sigar_file_system_list_t *fslist);
|
216
|
+
|
217
|
+
int sigar_file_system_list_grow(sigar_file_system_list_t *fslist);
|
218
|
+
|
219
|
+
#define SIGAR_FILE_SYSTEM_LIST_GROW(fslist) \
|
220
|
+
if (fslist->number >= fslist->size) { \
|
221
|
+
sigar_file_system_list_grow(fslist); \
|
222
|
+
}
|
223
|
+
|
224
|
+
int sigar_os_fs_type_get(sigar_file_system_t *fsp);
|
225
|
+
|
226
|
+
/* os plugins that set fsp->type call fs_type_get directly */
|
227
|
+
#define sigar_fs_type_init(fsp) \
|
228
|
+
fsp->type = SIGAR_FSTYPE_UNKNOWN; \
|
229
|
+
sigar_fs_type_get(fsp)
|
230
|
+
|
231
|
+
void sigar_fs_type_get(sigar_file_system_t *fsp);
|
232
|
+
|
233
|
+
int sigar_cpu_info_list_create(sigar_cpu_info_list_t *cpu_infos);
|
234
|
+
|
235
|
+
int sigar_cpu_info_list_grow(sigar_cpu_info_list_t *cpu_infos);
|
236
|
+
|
237
|
+
#define SIGAR_CPU_INFO_LIST_GROW(cpu_infos) \
|
238
|
+
if (cpu_infos->number >= cpu_infos->size) { \
|
239
|
+
sigar_cpu_info_list_grow(cpu_infos); \
|
240
|
+
}
|
241
|
+
|
242
|
+
int sigar_cpu_list_create(sigar_cpu_list_t *cpulist);
|
243
|
+
|
244
|
+
int sigar_cpu_list_grow(sigar_cpu_list_t *cpulist);
|
245
|
+
|
246
|
+
#define SIGAR_CPU_LIST_GROW(cpulist) \
|
247
|
+
if (cpulist->number >= cpulist->size) { \
|
248
|
+
sigar_cpu_list_grow(cpulist); \
|
249
|
+
}
|
250
|
+
|
251
|
+
int sigar_net_route_list_create(sigar_net_route_list_t *routelist);
|
252
|
+
|
253
|
+
int sigar_net_route_list_grow(sigar_net_route_list_t *net_routelist);
|
254
|
+
|
255
|
+
#define SIGAR_NET_ROUTE_LIST_GROW(routelist) \
|
256
|
+
if (routelist->number >= routelist->size) { \
|
257
|
+
sigar_net_route_list_grow(routelist); \
|
258
|
+
}
|
259
|
+
|
260
|
+
int sigar_net_interface_list_create(sigar_net_interface_list_t *iflist);
|
261
|
+
|
262
|
+
int sigar_net_interface_list_grow(sigar_net_interface_list_t *iflist);
|
263
|
+
|
264
|
+
#define SIGAR_NET_IFLIST_GROW(iflist) \
|
265
|
+
if (iflist->number >= iflist->size) { \
|
266
|
+
sigar_net_interface_list_grow(iflist); \
|
267
|
+
}
|
268
|
+
|
269
|
+
int sigar_net_connection_list_create(sigar_net_connection_list_t *connlist);
|
270
|
+
|
271
|
+
int sigar_net_connection_list_grow(sigar_net_connection_list_t *connlist);
|
272
|
+
|
273
|
+
#define SIGAR_NET_CONNLIST_GROW(connlist) \
|
274
|
+
if (connlist->number >= connlist->size) { \
|
275
|
+
sigar_net_connection_list_grow(connlist); \
|
276
|
+
}
|
277
|
+
|
278
|
+
#define sigar_net_address_set(a, val) \
|
279
|
+
(a).addr.in = val; \
|
280
|
+
(a).family = SIGAR_AF_INET
|
281
|
+
|
282
|
+
#define sigar_net_address6_set(a, val) \
|
283
|
+
memcpy(&((a).addr.in6), val, sizeof((a).addr.in6)); \
|
284
|
+
(a).family = SIGAR_AF_INET6
|
285
|
+
|
286
|
+
#define SIGAR_IFHWADDRLEN 6
|
287
|
+
|
288
|
+
#define sigar_net_address_mac_set(a, val, len) \
|
289
|
+
memcpy(&((a).addr.mac), val, len); \
|
290
|
+
(a).family = SIGAR_AF_LINK
|
291
|
+
|
292
|
+
#define sigar_hwaddr_set_null(ifconfig) \
|
293
|
+
SIGAR_ZERO(&ifconfig->hwaddr.addr.mac); \
|
294
|
+
ifconfig->hwaddr.family = SIGAR_AF_LINK
|
295
|
+
|
296
|
+
int sigar_net_interface_ipv6_config_get(sigar_t *sigar, const char *name,
|
297
|
+
sigar_net_interface_config_t *ifconfig);
|
298
|
+
|
299
|
+
#define sigar_net_interface_ipv6_config_init(ifconfig) \
|
300
|
+
ifconfig->address6.family = SIGAR_AF_INET6; \
|
301
|
+
ifconfig->prefix6_length = 0; \
|
302
|
+
ifconfig->scope6 = 0
|
303
|
+
|
304
|
+
#define SIGAR_SIN6(s) ((struct sockaddr_in6 *)(s))
|
305
|
+
|
306
|
+
#define SIGAR_SIN6_ADDR(s) &SIGAR_SIN6(s)->sin6_addr
|
307
|
+
|
308
|
+
#define sigar_net_interface_scope6_set(ifconfig, addr) \
|
309
|
+
if (IN6_IS_ADDR_LINKLOCAL(addr)) \
|
310
|
+
ifconfig->scope6 = SIGAR_IPV6_ADDR_LINKLOCAL; \
|
311
|
+
else if (IN6_IS_ADDR_SITELOCAL(addr)) \
|
312
|
+
ifconfig->scope6 = SIGAR_IPV6_ADDR_SITELOCAL; \
|
313
|
+
else if (IN6_IS_ADDR_V4COMPAT(addr)) \
|
314
|
+
ifconfig->scope6 = SIGAR_IPV6_ADDR_COMPATv4; \
|
315
|
+
else if (IN6_IS_ADDR_LOOPBACK(addr)) \
|
316
|
+
ifconfig->scope6 = SIGAR_IPV6_ADDR_LOOPBACK; \
|
317
|
+
else \
|
318
|
+
ifconfig->scope6 = SIGAR_IPV6_ADDR_ANY
|
319
|
+
|
320
|
+
int sigar_tcp_curr_estab(sigar_t *sigar, sigar_tcp_t *tcp);
|
321
|
+
|
322
|
+
int sigar_arp_list_create(sigar_arp_list_t *arplist);
|
323
|
+
|
324
|
+
int sigar_arp_list_grow(sigar_arp_list_t *arplist);
|
325
|
+
|
326
|
+
#define SIGAR_ARP_LIST_GROW(arplist) \
|
327
|
+
if (arplist->number >= arplist->size) { \
|
328
|
+
sigar_arp_list_grow(arplist); \
|
329
|
+
}
|
330
|
+
|
331
|
+
int sigar_who_list_create(sigar_who_list_t *wholist);
|
332
|
+
|
333
|
+
int sigar_who_list_grow(sigar_who_list_t *wholist);
|
334
|
+
|
335
|
+
#define SIGAR_WHO_LIST_GROW(wholist) \
|
336
|
+
if (wholist->number >= wholist->size) { \
|
337
|
+
sigar_who_list_grow(wholist); \
|
338
|
+
}
|
339
|
+
|
340
|
+
int sigar_user_id_get(sigar_t *sigar, const char *name, int *uid);
|
341
|
+
|
342
|
+
int sigar_user_name_get(sigar_t *sigar, int uid, char *buf, int buflen);
|
343
|
+
|
344
|
+
int sigar_group_name_get(sigar_t *sigar, int gid, char *buf, int buflen);
|
345
|
+
|
346
|
+
#define SIGAR_PROC_ENV_KEY_LOOKUP() \
|
347
|
+
if ((procenv->type == SIGAR_PROC_ENV_KEY) && \
|
348
|
+
(pid == sigar->pid)) \
|
349
|
+
{ \
|
350
|
+
char *value = getenv(procenv->key); \
|
351
|
+
if (value != NULL) { \
|
352
|
+
procenv->env_getter(procenv->data, \
|
353
|
+
procenv->key, \
|
354
|
+
procenv->klen, \
|
355
|
+
value, strlen(value)); \
|
356
|
+
} \
|
357
|
+
return SIGAR_OK; \
|
358
|
+
}
|
359
|
+
|
360
|
+
#define SIGAR_DISK_STATS_INIT(disk) \
|
361
|
+
(disk)->reads = (disk)->writes = \
|
362
|
+
(disk)->read_bytes = (disk)->write_bytes = \
|
363
|
+
(disk)->rtime = (disk)->wtime = (disk)->qtime = (disk)->time = \
|
364
|
+
(disk)->queue = (disk)->service_time = SIGAR_FIELD_NOTIMPL; \
|
365
|
+
(disk)->snaptime = 0
|
366
|
+
|
367
|
+
/* key used for filesystem (/) -> device (/dev/hda1) mapping */
|
368
|
+
/* and disk_usage cache for service_time */
|
369
|
+
#define SIGAR_FSDEV_ID(sb) \
|
370
|
+
(S_ISBLK((sb).st_mode) ? (sb).st_rdev : ((sb).st_ino + (sb).st_dev))
|
371
|
+
|
372
|
+
#if defined(WIN32) || defined(NETWARE)
|
373
|
+
int sigar_get_iftype(const char *name, int *type, int *inst);
|
374
|
+
#endif
|
375
|
+
|
376
|
+
#define SIGAR_NIC_LOOPBACK "Local Loopback"
|
377
|
+
#define SIGAR_NIC_UNSPEC "UNSPEC"
|
378
|
+
#define SIGAR_NIC_SLIP "Serial Line IP"
|
379
|
+
#define SIGAR_NIC_CSLIP "VJ Serial Line IP"
|
380
|
+
#define SIGAR_NIC_SLIP6 "6-bit Serial Line IP"
|
381
|
+
#define SIGAR_NIC_CSLIP6 "VJ 6-bit Serial Line IP"
|
382
|
+
#define SIGAR_NIC_ADAPTIVE "Adaptive Serial Line IP"
|
383
|
+
#define SIGAR_NIC_ETHERNET "Ethernet"
|
384
|
+
#define SIGAR_NIC_ASH "Ash"
|
385
|
+
#define SIGAR_NIC_FDDI "Fiber Distributed Data Interface"
|
386
|
+
#define SIGAR_NIC_HIPPI "HIPPI"
|
387
|
+
#define SIGAR_NIC_AX25 "AMPR AX.25"
|
388
|
+
#define SIGAR_NIC_ROSE "AMPR ROSE"
|
389
|
+
#define SIGAR_NIC_NETROM "AMPR NET/ROM"
|
390
|
+
#define SIGAR_NIC_X25 "generic X.25"
|
391
|
+
#define SIGAR_NIC_TUNNEL "IPIP Tunnel"
|
392
|
+
#define SIGAR_NIC_PPP "Point-to-Point Protocol"
|
393
|
+
#define SIGAR_NIC_HDLC "(Cisco)-HDLC"
|
394
|
+
#define SIGAR_NIC_LAPB "LAPB"
|
395
|
+
#define SIGAR_NIC_ARCNET "ARCnet"
|
396
|
+
#define SIGAR_NIC_DLCI "Frame Relay DLCI"
|
397
|
+
#define SIGAR_NIC_FRAD "Frame Relay Access Device"
|
398
|
+
#define SIGAR_NIC_SIT "IPv6-in-IPv4"
|
399
|
+
#define SIGAR_NIC_IRDA "IrLAP"
|
400
|
+
#define SIGAR_NIC_EC "Econet"
|
401
|
+
|
402
|
+
#ifndef WIN32
|
403
|
+
#include <netdb.h>
|
404
|
+
#endif
|
405
|
+
|
406
|
+
#define SIGAR_HOSTENT_LEN 512
|
407
|
+
#if defined(_AIX)
|
408
|
+
#define SIGAR_HAS_HOSTENT_DATA
|
409
|
+
#endif
|
410
|
+
|
411
|
+
typedef struct {
|
412
|
+
char buffer[SIGAR_HOSTENT_LEN];
|
413
|
+
int error;
|
414
|
+
#ifndef WIN32
|
415
|
+
struct hostent hs;
|
416
|
+
#endif
|
417
|
+
#ifdef SIGAR_HAS_HOSTENT_DATA
|
418
|
+
struct hostent_data hd;
|
419
|
+
#endif
|
420
|
+
} sigar_hostent_t;
|
421
|
+
|
422
|
+
#endif
|