xref: /6.6.0/sigar/include/sigar.h (revision aa768481)
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_H
20#define SIGAR_H
21
22/* System Information Gatherer And Reporter */
23
24#include <limits.h>
25#include <sigar_visibility.h>
26#include <stdint.h>
27#include <inttypes.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#if defined(_LP64)         || \
34    defined(__LP64__)      || \
35    defined(__64BIT__)     || \
36    defined(__powerpc64__) || \
37    defined(__osf__)
38#define SIGAR_64BIT
39#endif
40
41   typedef int32_t sigar_int32_t;
42   typedef int64_t sigar_int64_t;
43   typedef uint32_t sigar_uint32_t;
44   typedef uint64_t sigar_uint64_t;
45
46#define SIGAR_FIELD_NOTIMPL -1
47
48#define SIGAR_OK 0
49#define SIGAR_START_ERROR 20000
50#define SIGAR_ENOTIMPL       (SIGAR_START_ERROR + 1)
51#define SIGAR_OS_START_ERROR (SIGAR_START_ERROR*2)
52
53#ifdef WIN32
54#   define SIGAR_ENOENT ERROR_FILE_NOT_FOUND
55#   define SIGAR_EACCES ERROR_ACCESS_DENIED
56#   define SIGAR_ENXIO  ERROR_BAD_DRIVER_LEVEL
57#else
58#   define SIGAR_ENOENT ENOENT
59#   define SIGAR_EACCES EACCES
60#   define SIGAR_ENXIO  ENXIO
61#endif
62
63#define SIGAR_DECLARE(type) SIGAR_PUBLIC_API type
64
65#if defined(PATH_MAX)
66#   define SIGAR_PATH_MAX PATH_MAX
67#elif defined(MAXPATHLEN)
68#   define SIGAR_PATH_MAX MAXPATHLEN
69#else
70#   define SIGAR_PATH_MAX 4096
71#endif
72
73#ifdef WIN32
74typedef sigar_uint64_t sigar_pid_t;
75typedef unsigned long sigar_uid_t;
76typedef unsigned long sigar_gid_t;
77#else
78#include <sys/types.h>
79typedef pid_t sigar_pid_t;
80typedef uid_t sigar_uid_t;
81typedef gid_t sigar_gid_t;
82#endif
83
84typedef struct sigar_t sigar_t;
85
86SIGAR_DECLARE(int) sigar_open(sigar_t **sigar);
87
88SIGAR_DECLARE(int) sigar_close(sigar_t *sigar);
89
90SIGAR_DECLARE(sigar_pid_t) sigar_pid_get(sigar_t *sigar);
91
92SIGAR_DECLARE(char *) sigar_strerror(sigar_t *sigar, int err);
93
94/* system memory info */
95
96typedef struct {
97    sigar_uint64_t
98        ram,
99        total,
100        used,
101        free,
102        actual_used,
103        actual_free;
104    double used_percent;
105    double free_percent;
106} sigar_mem_t;
107
108SIGAR_DECLARE(int) sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem);
109
110typedef struct {
111    sigar_uint64_t
112        total,
113        used,
114        free,
115        page_in,
116        page_out,
117        allocstall,             /* up until 4.10 */
118        allocstall_dma,         /* 4.10 onwards */
119        allocstall_dma32,       /* 4.10 onwards */
120        allocstall_normal,      /* 4.10 onwards */
121        allocstall_movable;     /* 4.10 onwards */
122} sigar_swap_t;
123
124SIGAR_DECLARE(int) sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap);
125
126typedef struct {
127    sigar_uint64_t
128        user,
129        sys,
130        nice,
131        idle,
132        wait,
133        irq,
134        soft_irq,
135        stolen,
136        total;
137} sigar_cpu_t;
138
139SIGAR_DECLARE(int) sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu);
140
141typedef struct {
142    char vendor[128];
143    char model[128];
144    int mhz;
145    int mhz_max;
146    int mhz_min;
147    sigar_uint64_t cache_size;
148    int total_sockets;
149    int total_cores;
150    int cores_per_socket;
151} sigar_cpu_info_t;
152
153typedef struct {
154    double uptime;
155} sigar_uptime_t;
156
157typedef struct {
158    unsigned long number;
159    unsigned long size;
160    sigar_pid_t *data;
161} sigar_proc_list_t;
162
163SIGAR_DECLARE(int) sigar_proc_list_get(sigar_t *sigar,
164                                       sigar_proc_list_t *proclist);
165
166SIGAR_DECLARE(int)
167sigar_proc_list_get_children(sigar_t* sigar,
168                             sigar_pid_t ppid,
169                             sigar_proc_list_t* proclist);
170
171SIGAR_DECLARE(int) sigar_proc_list_destroy(sigar_t *sigar,
172                                           sigar_proc_list_t *proclist);
173
174
175typedef struct {
176    sigar_uint64_t
177        size,
178        resident,
179        share,
180        minor_faults,
181        major_faults,
182        page_faults;
183} sigar_proc_mem_t;
184
185SIGAR_DECLARE(int) sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
186                                      sigar_proc_mem_t *procmem);
187
188typedef struct {
189    sigar_uid_t uid;
190    sigar_gid_t gid;
191    sigar_uid_t euid;
192    sigar_gid_t egid;
193} sigar_proc_cred_t;
194
195typedef struct {
196    sigar_uint64_t
197        start_time,
198        user,
199        sys,
200        total;
201} sigar_proc_time_t;
202
203// Not used externally
204int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
205                                       sigar_proc_time_t *proctime);
206
207typedef struct {
208    /* must match sigar_proc_time_t fields */
209    sigar_uint64_t
210        start_time,
211        user,
212        sys,
213        total;
214    sigar_uint64_t last_time;
215    double percent;
216} sigar_proc_cpu_t;
217
218SIGAR_DECLARE(int) sigar_proc_cpu_get(sigar_t *sigar, sigar_pid_t pid,
219                                      sigar_proc_cpu_t *proccpu);
220
221#define SIGAR_PROC_STATE_SLEEP  'S'
222#define SIGAR_PROC_STATE_RUN    'R'
223#define SIGAR_PROC_STATE_STOP   'T'
224#define SIGAR_PROC_STATE_ZOMBIE 'Z'
225#define SIGAR_PROC_STATE_IDLE   'D'
226
227#define SIGAR_PROC_NAME_LEN 128
228
229typedef struct {
230    char name[SIGAR_PROC_NAME_LEN];
231    char state;
232    sigar_pid_t ppid;
233    int tty;
234    int priority;
235    int nice;
236    int processor;
237    sigar_uint64_t threads;
238} sigar_proc_state_t;
239
240SIGAR_DECLARE(int) sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
241                                        sigar_proc_state_t *procstate);
242
243typedef struct {
244    unsigned long number;
245    unsigned long size;
246    char **data;
247} sigar_proc_args_t;
248
249typedef struct {
250    void *data; /* user data */
251
252    int (*module_getter)(void *, char *, int);
253} sigar_proc_modules_t;
254
255
256typedef enum {
257    SIGAR_FSTYPE_UNKNOWN,
258    SIGAR_FSTYPE_NONE,
259    SIGAR_FSTYPE_LOCAL_DISK,
260    SIGAR_FSTYPE_NETWORK,
261    SIGAR_FSTYPE_RAM_DISK,
262    SIGAR_FSTYPE_CDROM,
263    SIGAR_FSTYPE_SWAP,
264    SIGAR_FSTYPE_MAX
265} sigar_file_system_type_e;
266
267#define SIGAR_FS_NAME_LEN SIGAR_PATH_MAX
268#define SIGAR_FS_INFO_LEN 256
269
270typedef struct {
271    char dir_name[SIGAR_FS_NAME_LEN];
272    char dev_name[SIGAR_FS_NAME_LEN];
273    char type_name[SIGAR_FS_INFO_LEN];     /* e.g. "local" */
274    char sys_type_name[SIGAR_FS_INFO_LEN]; /* e.g. "ext3" */
275    char options[SIGAR_FS_INFO_LEN];
276    sigar_file_system_type_e type;
277    unsigned long flags;
278} sigar_file_system_t;
279
280typedef struct {
281    unsigned long number;
282    unsigned long size;
283    sigar_file_system_t *data;
284} sigar_file_system_list_t;
285
286SIGAR_DECLARE(int)
287sigar_file_system_list_get(sigar_t *sigar,
288                           sigar_file_system_list_t *fslist);
289
290SIGAR_DECLARE(int)
291sigar_file_system_list_destroy(sigar_t *sigar,
292                               sigar_file_system_list_t *fslist);
293
294typedef struct {
295    sigar_uint64_t reads;
296    sigar_uint64_t writes;
297    sigar_uint64_t write_bytes;
298    sigar_uint64_t read_bytes;
299    sigar_uint64_t rtime;
300    sigar_uint64_t wtime;
301    sigar_uint64_t qtime;
302    sigar_uint64_t time;
303    sigar_uint64_t snaptime;
304    double service_time;
305    double queue;
306} sigar_disk_usage_t;
307
308typedef struct {
309    sigar_disk_usage_t disk;
310    double use_percent;
311    sigar_uint64_t total;
312    sigar_uint64_t free;
313    sigar_uint64_t used;
314    sigar_uint64_t avail;
315    sigar_uint64_t files;
316    sigar_uint64_t free_files;
317} sigar_file_system_usage_t;
318
319#undef SIGAR_DISK_USAGE_T
320
321
322
323
324typedef struct {
325    enum {
326        SIGAR_AF_UNSPEC,
327        SIGAR_AF_INET,
328        SIGAR_AF_INET6,
329        SIGAR_AF_LINK
330    } family;
331    union {
332        sigar_uint32_t in;
333        sigar_uint32_t in6[4];
334        unsigned char mac[8];
335    } addr;
336} sigar_net_address_t;
337
338#define SIGAR_INET6_ADDRSTRLEN 46
339
340#define SIGAR_MAXDOMAINNAMELEN 256
341#define SIGAR_MAXHOSTNAMELEN 256
342
343
344
345/*
346 * platforms define most of these "standard" flags,
347 * but of course, with different values in some cases.
348 */
349#define SIGAR_IFF_UP          0x1
350#define SIGAR_IFF_BROADCAST   0x2
351#define SIGAR_IFF_DEBUG       0x4
352#define SIGAR_IFF_LOOPBACK    0x8
353#define SIGAR_IFF_POINTOPOINT 0x10
354#define SIGAR_IFF_NOTRAILERS  0x20
355#define SIGAR_IFF_RUNNING     0x40
356#define SIGAR_IFF_NOARP       0x80
357#define SIGAR_IFF_PROMISC     0x100
358#define SIGAR_IFF_ALLMULTI    0x200
359#define SIGAR_IFF_MULTICAST   0x800
360#define SIGAR_IFF_SLAVE       0x1000
361#define SIGAR_IFF_MASTER      0x2000
362#define SIGAR_IFF_DYNAMIC     0x4000
363
364#define SIGAR_NULL_HWADDR "00:00:00:00:00:00"
365
366/* scope values from linux-2.6/include/net/ipv6.h */
367#define SIGAR_IPV6_ADDR_ANY        0x0000
368#define SIGAR_IPV6_ADDR_UNICAST    0x0001
369#define SIGAR_IPV6_ADDR_MULTICAST  0x0002
370#define SIGAR_IPV6_ADDR_LOOPBACK   0x0010
371#define SIGAR_IPV6_ADDR_LINKLOCAL  0x0020
372#define SIGAR_IPV6_ADDR_SITELOCAL  0x0040
373#define SIGAR_IPV6_ADDR_COMPATv4   0x0080
374
375typedef struct {
376    char name[16];
377    char type[64];
378    char description[256];
379    sigar_net_address_t hwaddr;
380    sigar_net_address_t address;
381    sigar_net_address_t destination;
382    sigar_net_address_t broadcast;
383    sigar_net_address_t netmask;
384    sigar_net_address_t address6;
385    int prefix6_length;
386    int scope6;
387    sigar_uint64_t
388        flags,
389        mtu,
390        metric;
391    int tx_queue_len;
392} sigar_net_interface_config_t;
393
394SIGAR_DECLARE(int)
395sigar_net_interface_config_get(sigar_t *sigar,
396                               const char *name,
397                               sigar_net_interface_config_t *ifconfig);
398
399SIGAR_DECLARE(int)
400sigar_net_interface_config_primary_get(sigar_t *sigar,
401                                       sigar_net_interface_config_t *ifconfig);
402
403
404typedef struct {
405    unsigned long number;
406    unsigned long size;
407    char **data;
408} sigar_net_interface_list_t;
409
410SIGAR_DECLARE(int)
411sigar_net_interface_list_get(sigar_t *sigar,
412                             sigar_net_interface_list_t *iflist);
413
414SIGAR_DECLARE(int)
415sigar_net_interface_list_destroy(sigar_t *sigar,
416                                 sigar_net_interface_list_t *iflist);
417
418#define SIGAR_NETCONN_CLIENT 0x01
419#define SIGAR_NETCONN_SERVER 0x02
420
421#define SIGAR_NETCONN_TCP  0x10
422#define SIGAR_NETCONN_UDP  0x20
423#define SIGAR_NETCONN_RAW  0x40
424#define SIGAR_NETCONN_UNIX 0x80
425
426enum {
427    SIGAR_TCP_ESTABLISHED = 1,
428    SIGAR_TCP_SYN_SENT,
429    SIGAR_TCP_SYN_RECV,
430    SIGAR_TCP_FIN_WAIT1,
431    SIGAR_TCP_FIN_WAIT2,
432    SIGAR_TCP_TIME_WAIT,
433    SIGAR_TCP_CLOSE,
434    SIGAR_TCP_CLOSE_WAIT,
435    SIGAR_TCP_LAST_ACK,
436    SIGAR_TCP_LISTEN,
437    SIGAR_TCP_CLOSING,
438    SIGAR_TCP_IDLE,
439    SIGAR_TCP_BOUND,
440    SIGAR_TCP_UNKNOWN
441};
442
443typedef struct {
444    unsigned long local_port;
445    sigar_net_address_t local_address;
446    unsigned long remote_port;
447    sigar_net_address_t remote_address;
448    sigar_uid_t uid;
449    unsigned long inode;
450    int type;
451    int state;
452    unsigned long send_queue;
453    unsigned long receive_queue;
454} sigar_net_connection_t;
455
456typedef struct {
457    unsigned long number;
458    unsigned long size;
459    sigar_net_connection_t *data;
460} sigar_net_connection_list_t;
461
462SIGAR_DECLARE(int)
463sigar_net_connection_list_get(sigar_t *sigar,
464                              sigar_net_connection_list_t *connlist,
465                              int flags);
466
467SIGAR_DECLARE(int)
468sigar_net_connection_list_destroy(sigar_t *sigar,
469                                  sigar_net_connection_list_t *connlist);
470
471typedef struct sigar_net_connection_walker_t sigar_net_connection_walker_t;
472
473/* alternative to sigar_net_connection_list_get */
474struct sigar_net_connection_walker_t {
475    sigar_t *sigar;
476    int flags;
477    void *data; /* user data */
478    int (*add_connection)(sigar_net_connection_walker_t *walker,
479                          sigar_net_connection_t *connection);
480};
481
482SIGAR_DECLARE(int)
483sigar_net_connection_walk(sigar_net_connection_walker_t *walker);
484
485
486
487/* TCP-MIB */
488typedef struct {
489    sigar_uint64_t active_opens;
490    sigar_uint64_t passive_opens;
491    sigar_uint64_t attempt_fails;
492    sigar_uint64_t estab_resets;
493    sigar_uint64_t curr_estab;
494    sigar_uint64_t in_segs;
495    sigar_uint64_t out_segs;
496    sigar_uint64_t retrans_segs;
497    sigar_uint64_t in_errs;
498    sigar_uint64_t out_rsts;
499} sigar_tcp_t;
500
501
502#define SIGAR_SYS_INFO_LEN SIGAR_MAXHOSTNAMELEN /* more than enough */
503
504typedef struct {
505    char name[SIGAR_SYS_INFO_LEN]; /* canonicalized sysname */
506    char version[SIGAR_SYS_INFO_LEN]; /* utsname.release */
507    char arch[SIGAR_SYS_INFO_LEN];
508    char machine[SIGAR_SYS_INFO_LEN];
509    char description[SIGAR_SYS_INFO_LEN];
510    char patch_level[SIGAR_SYS_INFO_LEN];
511    char vendor[SIGAR_SYS_INFO_LEN];
512    char vendor_version[SIGAR_SYS_INFO_LEN];
513    char vendor_name[SIGAR_SYS_INFO_LEN];  /* utsname.sysname */
514    char vendor_code_name[SIGAR_SYS_INFO_LEN];
515} sigar_sys_info_t;
516
517#ifdef __cplusplus
518}
519#endif
520
521#endif
522