ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/statgrab.h
Revision: 1.49
Committed: Thu Apr 8 13:44:44 2004 UTC (20 years, 1 month ago) by ats
Content type: text/plain
Branch: MAIN
CVS Tags: LIBSTATGRAB_0_10
Changes since 1.48: +11 -1 lines
Log Message:
Add comparison functions for names where that's likely to be useful.

Make the network_iface_stats example show how to use bsearch to find an
interface by name.

File Contents

# Content
1 /*
2 * i-scream libstatgrab
3 * http://www.i-scream.org
4 * Copyright (C) 2000-2004 i-scream
5 *
6 * 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 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * 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 *
21 * $Id: statgrab.h,v 1.48 2004/04/08 13:16:05 ats Exp $
22 */
23
24 #include <sys/types.h>
25
26 /* 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
33 typedef enum {
34 SG_ERROR_NONE = 0,
35 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 SG_ERROR_MALLOC,
49 SG_ERROR_OPEN,
50 SG_ERROR_OPENDIR,
51 SG_ERROR_PARSE,
52 SG_ERROR_SETEGID,
53 SG_ERROR_SETEUID,
54 SG_ERROR_SETMNTENT,
55 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 } sg_error;
65
66 void sg_set_error(sg_error code, const char *arg);
67 sg_error sg_get_error();
68 const char *sg_get_error_arg();
69 const char *sg_str_error(sg_error code);
70
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 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 } sg_cpu_stats;
92
93 sg_cpu_stats *sg_get_cpu_stats();
94 sg_cpu_stats *sg_get_cpu_stats_diff();
95
96 typedef struct {
97 float user;
98 float kernel;
99 float idle;
100 float iowait;
101 float swap;
102 float nice;
103 time_t time_taken;
104 } sg_cpu_percents;
105
106 sg_cpu_percents *sg_get_cpu_percents();
107
108 typedef struct {
109 long long total;
110 long long free;
111 long long used;
112 long long cache;
113 } sg_mem_stats;
114
115 sg_mem_stats *sg_get_mem_stats();
116
117 typedef struct {
118 double min1;
119 double min5;
120 double min15;
121 } sg_load_stats;
122
123 sg_load_stats *sg_get_load_stats();
124
125 typedef struct {
126 char *name_list;
127 int num_entries;
128 } sg_user_stats;
129
130 sg_user_stats *sg_get_user_stats();
131
132 typedef struct {
133 long long total;
134 long long used;
135 long long free;
136 } sg_swap_stats;
137
138 sg_swap_stats *sg_get_swap_stats();
139
140 typedef struct {
141 char *device_name;
142 char *fs_type;
143 char *mnt_point;
144 long long size;
145 long long used;
146 long long avail;
147 long long total_inodes;
148 long long used_inodes;
149 long long free_inodes;
150 } sg_fs_stats;
151
152 sg_fs_stats *sg_get_fs_stats(int *entries);
153
154 int sg_fs_compare_device_name(const void *va, const void *vb);
155 int sg_fs_compare_mnt_point(const void *va, const void *vb);
156
157 typedef struct {
158 char *disk_name;
159 long long read_bytes;
160 long long write_bytes;
161 time_t systime;
162 } sg_disk_io_stats;
163
164 sg_disk_io_stats *sg_get_disk_io_stats(int *entries);
165 sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries);
166
167 int sg_disk_io_compare_name(const void *va, const void *vb);
168
169 typedef struct {
170 char *interface_name;
171 long long tx;
172 long long rx;
173 long long ipackets;
174 long long opackets;
175 long long ierrors;
176 long long oerrors;
177 long long collisions;
178 time_t systime;
179 } sg_network_io_stats;
180
181 sg_network_io_stats *sg_get_network_io_stats(int *entries);
182 sg_network_io_stats *sg_get_network_io_stats_diff(int *entries);
183
184 int sg_network_io_compare_name(const void *va, const void *vb);
185
186 typedef enum {
187 SG_IFACE_DUPLEX_FULL,
188 SG_IFACE_DUPLEX_HALF,
189 SG_IFACE_DUPLEX_UNKNOWN
190 } sg_iface_duplex;
191
192 typedef struct {
193 char *interface_name;
194 int speed; /* In megabits/sec */
195 sg_iface_duplex dup;
196 int up;
197 } sg_network_iface_stats;
198
199 sg_network_iface_stats *sg_get_network_iface_stats(int *entries);
200
201 int sg_network_iface_compare_name(const void *va, const void *vb);
202
203 typedef struct {
204 long long pages_pagein;
205 long long pages_pageout;
206 time_t systime;
207 } sg_page_stats;
208
209 sg_page_stats *sg_get_page_stats();
210 sg_page_stats *sg_get_page_stats_diff();
211
212 typedef enum {
213 SG_PROCESS_STATE_RUNNING,
214 SG_PROCESS_STATE_SLEEPING,
215 SG_PROCESS_STATE_STOPPED,
216 SG_PROCESS_STATE_ZOMBIE,
217 SG_PROCESS_STATE_UNKNOWN
218 } sg_process_state;
219
220 typedef struct {
221 char *process_name;
222 char *proctitle;
223
224 pid_t pid;
225 pid_t parent; /* Parent pid */
226 pid_t pgid; /* process id of process group leader */
227
228 uid_t uid;
229 uid_t euid;
230 gid_t gid;
231 gid_t egid;
232
233 unsigned long long proc_size; /* in bytes */
234 unsigned long long proc_resident; /* in bytes */
235 time_t time_spent; /* time running in seconds */
236 double cpu_percent;
237 int nice;
238 sg_process_state state;
239 } sg_process_stats;
240
241 sg_process_stats *sg_get_process_stats(int *entries);
242
243 int sg_process_compare_name(const void *va, const void *vb);
244 int sg_process_compare_pid(const void *va, const void *vb);
245 int sg_process_compare_uid(const void *va, const void *vb);
246 int sg_process_compare_gid(const void *va, const void *vb);
247 int sg_process_compare_size(const void *va, const void *vb);
248 int sg_process_compare_res(const void *va, const void *vb);
249 int sg_process_compare_cpu(const void *va, const void *vb);
250 int sg_process_compare_time(const void *va, const void *vb);
251
252 typedef struct {
253 int total;
254 int running;
255 int sleeping;
256 int stopped;
257 int zombie;
258 } sg_process_count;
259
260 sg_process_count *sg_get_process_count();
261
262 #ifdef SG_ENABLE_DEPRECATED
263 #include <statgrab_deprecated.h>
264 #endif
265