1 |
tdb |
1.22 |
/* |
2 |
tdb |
1.34 |
* i-scream libstatgrab |
3 |
tdb |
1.13 |
* http://www.i-scream.org |
4 |
tdb |
1.22 |
* Copyright (C) 2000-2004 i-scream |
5 |
pajs |
1.1 |
* |
6 |
tdb |
1.22 |
* This library is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU Lesser General Public |
8 |
|
|
* License as published by the Free Software Foundation; either |
9 |
|
|
* version 2.1 of the License, or (at your option) any later version. |
10 |
pajs |
1.1 |
* |
11 |
tdb |
1.22 |
* This library is distributed in the hope that it will be useful, |
12 |
pajs |
1.1 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
tdb |
1.22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
|
* Lesser General Public License for more details. |
15 |
pajs |
1.1 |
* |
16 |
tdb |
1.22 |
* You should have received a copy of the GNU Lesser General Public |
17 |
|
|
* License along with this library; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
19 |
|
|
* 02111-1307 USA |
20 |
tdb |
1.23 |
* |
21 |
ats |
1.48 |
* $Id: statgrab.h,v 1.47 2004/04/08 13:03:23 tdb Exp $ |
22 |
pajs |
1.1 |
*/ |
23 |
|
|
|
24 |
pajs |
1.21 |
#include <sys/types.h> |
25 |
|
|
|
26 |
ats |
1.33 |
/* FIXME typedefs for 32/64-bit types */ |
27 |
|
|
/* FIXME maybe tidy up field names? */ |
28 |
|
|
/* FIXME comments for less obvious fields */ |
29 |
|
|
|
30 |
|
|
int sg_init(void); |
31 |
|
|
int sg_drop_privileges(void); |
32 |
tdb |
1.36 |
|
33 |
|
|
typedef enum { |
34 |
tdb |
1.38 |
SG_ERROR_NONE = 0, |
35 |
tdb |
1.42 |
SG_ERROR_ASPRINTF, |
36 |
|
|
SG_ERROR_DEVSTAT_GETDEVS, |
37 |
|
|
SG_ERROR_DEVSTAT_SELECTDEVS, |
38 |
|
|
SG_ERROR_ENOENT, |
39 |
|
|
SG_ERROR_GETIFADDRS, |
40 |
|
|
SG_ERROR_GETMNTINFO, |
41 |
|
|
SG_ERROR_GETPAGESIZE, |
42 |
|
|
SG_ERROR_KSTAT_DATA_LOOKUP, |
43 |
|
|
SG_ERROR_KSTAT_LOOKUP, |
44 |
|
|
SG_ERROR_KSTAT_OPEN, |
45 |
|
|
SG_ERROR_KSTAT_READ, |
46 |
|
|
SG_ERROR_KVM_GETSWAPINFO, |
47 |
|
|
SG_ERROR_KVM_OPENFILES, |
48 |
tdb |
1.39 |
SG_ERROR_MALLOC, |
49 |
|
|
SG_ERROR_OPEN, |
50 |
tdb |
1.42 |
SG_ERROR_OPENDIR, |
51 |
tdb |
1.41 |
SG_ERROR_PARSE, |
52 |
tdb |
1.42 |
SG_ERROR_SETEGID, |
53 |
|
|
SG_ERROR_SETEUID, |
54 |
tdb |
1.41 |
SG_ERROR_SETMNTENT, |
55 |
tdb |
1.42 |
SG_ERROR_SOCKET, |
56 |
|
|
SG_ERROR_SWAPCTL, |
57 |
|
|
SG_ERROR_SYSCONF, |
58 |
|
|
SG_ERROR_SYSCTL, |
59 |
|
|
SG_ERROR_SYSCTLBYNAME, |
60 |
|
|
SG_ERROR_SYSCTLNAMETOMIB, |
61 |
|
|
SG_ERROR_UNAME, |
62 |
|
|
SG_ERROR_UNSUPPORTED, |
63 |
|
|
SG_ERROR_XSW_VER_MISMATCH |
64 |
tdb |
1.36 |
} sg_error; |
65 |
|
|
|
66 |
|
|
void sg_set_error(sg_error code, const char *arg); |
67 |
|
|
sg_error sg_get_error(); |
68 |
ats |
1.43 |
const char *sg_get_error_arg(); |
69 |
ats |
1.37 |
const char *sg_str_error(sg_error code); |
70 |
ats |
1.33 |
|
71 |
|
|
typedef struct { |
72 |
|
|
char *os_name; |
73 |
|
|
char *os_release; |
74 |
|
|
char *os_version; |
75 |
|
|
char *platform; |
76 |
|
|
char *hostname; |
77 |
|
|
time_t uptime; |
78 |
|
|
} sg_host_info; |
79 |
|
|
|
80 |
|
|
sg_host_info *sg_get_host_info(); |
81 |
|
|
|
82 |
|
|
typedef struct { |
83 |
tdb |
1.39 |
long long user; |
84 |
|
|
long long kernel; |
85 |
|
|
long long idle; |
86 |
|
|
long long iowait; |
87 |
|
|
long long swap; |
88 |
|
|
long long nice; |
89 |
|
|
long long total; |
90 |
|
|
time_t systime; |
91 |
ats |
1.33 |
} sg_cpu_stats; |
92 |
pajs |
1.1 |
|
93 |
ats |
1.33 |
sg_cpu_stats *sg_get_cpu_stats(); |
94 |
|
|
sg_cpu_stats *sg_get_cpu_stats_diff(); |
95 |
|
|
|
96 |
|
|
typedef struct { |
97 |
tdb |
1.39 |
float user; |
98 |
|
|
float kernel; |
99 |
|
|
float idle; |
100 |
|
|
float iowait; |
101 |
|
|
float swap; |
102 |
|
|
float nice; |
103 |
pajs |
1.1 |
time_t time_taken; |
104 |
ats |
1.33 |
} sg_cpu_percents; |
105 |
|
|
|
106 |
|
|
sg_cpu_percents *sg_get_cpu_percents(); |
107 |
pajs |
1.1 |
|
108 |
ats |
1.33 |
typedef struct { |
109 |
pajs |
1.1 |
long long total; |
110 |
|
|
long long free; |
111 |
|
|
long long used; |
112 |
|
|
long long cache; |
113 |
ats |
1.33 |
} sg_mem_stats; |
114 |
|
|
|
115 |
|
|
sg_mem_stats *sg_get_mem_stats(); |
116 |
pajs |
1.1 |
|
117 |
ats |
1.33 |
typedef struct { |
118 |
pajs |
1.1 |
double min1; |
119 |
|
|
double min5; |
120 |
|
|
double min15; |
121 |
ats |
1.33 |
} sg_load_stats; |
122 |
|
|
|
123 |
|
|
sg_load_stats *sg_get_load_stats(); |
124 |
pajs |
1.1 |
|
125 |
ats |
1.33 |
typedef struct { |
126 |
pajs |
1.8 |
char *name_list; |
127 |
pajs |
1.1 |
int num_entries; |
128 |
ats |
1.33 |
} sg_user_stats; |
129 |
|
|
|
130 |
|
|
sg_user_stats *sg_get_user_stats(); |
131 |
pajs |
1.1 |
|
132 |
ats |
1.33 |
typedef struct { |
133 |
pajs |
1.1 |
long long total; |
134 |
|
|
long long used; |
135 |
|
|
long long free; |
136 |
ats |
1.33 |
} sg_swap_stats; |
137 |
pajs |
1.1 |
|
138 |
ats |
1.33 |
sg_swap_stats *sg_get_swap_stats(); |
139 |
pajs |
1.1 |
|
140 |
|
|
typedef struct { |
141 |
tdb |
1.39 |
char *device_name; |
142 |
pajs |
1.1 |
char *fs_type; |
143 |
tdb |
1.39 |
char *mnt_point; |
144 |
|
|
long long size; |
145 |
|
|
long long used; |
146 |
|
|
long long avail; |
147 |
|
|
long long total_inodes; |
148 |
pajs |
1.1 |
long long used_inodes; |
149 |
tdb |
1.39 |
long long free_inodes; |
150 |
ats |
1.33 |
} sg_fs_stats; |
151 |
|
|
|
152 |
|
|
sg_fs_stats *sg_get_fs_stats(int *entries); |
153 |
pajs |
1.1 |
|
154 |
ats |
1.33 |
typedef struct { |
155 |
pajs |
1.4 |
char *disk_name; |
156 |
|
|
long long read_bytes; |
157 |
|
|
long long write_bytes; |
158 |
|
|
time_t systime; |
159 |
ats |
1.33 |
} sg_disk_io_stats; |
160 |
pajs |
1.4 |
|
161 |
ats |
1.33 |
sg_disk_io_stats *sg_get_disk_io_stats(int *entries); |
162 |
|
|
sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries); |
163 |
pajs |
1.1 |
|
164 |
ats |
1.33 |
typedef struct { |
165 |
pajs |
1.1 |
char *interface_name; |
166 |
|
|
long long tx; |
167 |
|
|
long long rx; |
168 |
tdb |
1.28 |
long long ipackets; |
169 |
|
|
long long opackets; |
170 |
|
|
long long ierrors; |
171 |
|
|
long long oerrors; |
172 |
|
|
long long collisions; |
173 |
pajs |
1.1 |
time_t systime; |
174 |
ats |
1.33 |
} sg_network_io_stats; |
175 |
|
|
|
176 |
|
|
sg_network_io_stats *sg_get_network_io_stats(int *entries); |
177 |
|
|
sg_network_io_stats *sg_get_network_io_stats_diff(int *entries); |
178 |
pajs |
1.24 |
|
179 |
ats |
1.33 |
typedef enum { |
180 |
|
|
SG_IFACE_DUPLEX_FULL, |
181 |
|
|
SG_IFACE_DUPLEX_HALF, |
182 |
|
|
SG_IFACE_DUPLEX_UNKNOWN |
183 |
|
|
} sg_iface_duplex; |
184 |
pajs |
1.24 |
|
185 |
ats |
1.33 |
typedef struct { |
186 |
pajs |
1.24 |
char *interface_name; |
187 |
|
|
int speed; /* In megabits/sec */ |
188 |
ats |
1.33 |
sg_iface_duplex dup; |
189 |
pajs |
1.27 |
int up; |
190 |
ats |
1.33 |
} sg_network_iface_stats; |
191 |
|
|
|
192 |
|
|
sg_network_iface_stats *sg_get_network_iface_stats(int *entries); |
193 |
pajs |
1.1 |
|
194 |
ats |
1.33 |
typedef struct { |
195 |
pajs |
1.2 |
long long pages_pagein; |
196 |
|
|
long long pages_pageout; |
197 |
pajs |
1.1 |
time_t systime; |
198 |
ats |
1.33 |
} sg_page_stats; |
199 |
|
|
|
200 |
|
|
sg_page_stats *sg_get_page_stats(); |
201 |
|
|
sg_page_stats *sg_get_page_stats_diff(); |
202 |
pajs |
1.29 |
|
203 |
ats |
1.33 |
typedef enum { |
204 |
|
|
SG_PROCESS_STATE_RUNNING, |
205 |
|
|
SG_PROCESS_STATE_SLEEPING, |
206 |
|
|
SG_PROCESS_STATE_STOPPED, |
207 |
|
|
SG_PROCESS_STATE_ZOMBIE, |
208 |
|
|
SG_PROCESS_STATE_UNKNOWN |
209 |
|
|
} sg_process_state; |
210 |
pajs |
1.30 |
|
211 |
ats |
1.33 |
typedef struct { |
212 |
pajs |
1.29 |
char *process_name; |
213 |
|
|
char *proctitle; |
214 |
|
|
|
215 |
|
|
pid_t pid; |
216 |
|
|
pid_t parent; /* Parent pid */ |
217 |
|
|
pid_t pgid; /* process id of process group leader */ |
218 |
|
|
|
219 |
|
|
uid_t uid; |
220 |
|
|
uid_t euid; |
221 |
|
|
gid_t gid; |
222 |
|
|
gid_t egid; |
223 |
|
|
|
224 |
|
|
unsigned long long proc_size; /* in bytes */ |
225 |
|
|
unsigned long long proc_resident; /* in bytes */ |
226 |
tdb |
1.31 |
time_t time_spent; /* time running in seconds */ |
227 |
pajs |
1.29 |
double cpu_percent; |
228 |
|
|
int nice; |
229 |
ats |
1.33 |
sg_process_state state; |
230 |
|
|
} sg_process_stats; |
231 |
pajs |
1.29 |
|
232 |
ats |
1.33 |
sg_process_stats *sg_get_process_stats(int *entries); |
233 |
pajs |
1.1 |
|
234 |
ats |
1.48 |
int sg_process_compare_pid(const void *va, const void *vb); |
235 |
|
|
int sg_process_compare_uid(const void *va, const void *vb); |
236 |
|
|
int sg_process_compare_gid(const void *va, const void *vb); |
237 |
|
|
int sg_process_compare_size(const void *va, const void *vb); |
238 |
|
|
int sg_process_compare_res(const void *va, const void *vb); |
239 |
|
|
int sg_process_compare_cpu(const void *va, const void *vb); |
240 |
|
|
int sg_process_compare_time(const void *va, const void *vb); |
241 |
|
|
|
242 |
ats |
1.33 |
typedef struct { |
243 |
|
|
int total; |
244 |
|
|
int running; |
245 |
|
|
int sleeping; |
246 |
|
|
int stopped; |
247 |
|
|
int zombie; |
248 |
|
|
} sg_process_count; |
249 |
pajs |
1.14 |
|
250 |
ats |
1.33 |
sg_process_count *sg_get_process_count(); |
251 |
tdb |
1.35 |
|
252 |
|
|
#ifdef SG_ENABLE_DEPRECATED |
253 |
|
|
#include <statgrab_deprecated.h> |
254 |
|
|
#endif |
255 |
ats |
1.18 |
|