1 |
|
/* |
2 |
< |
* i-scream central monitoring system |
2 |
> |
* i-scream libstatgrab |
3 |
|
* http://www.i-scream.org |
4 |
|
* Copyright (C) 2000-2004 i-scream |
5 |
|
* |
23 |
|
|
24 |
|
#include <sys/types.h> |
25 |
|
|
26 |
< |
typedef struct{ |
27 |
< |
long long user; |
28 |
< |
long long kernel; |
29 |
< |
long long idle; |
30 |
< |
long long iowait; |
31 |
< |
long long swap; |
32 |
< |
long long nice; |
33 |
< |
long long total; |
34 |
< |
time_t systime; |
35 |
< |
}cpu_states_t; |
26 |
> |
/* FIXME typedefs for 32/64-bit types */ |
27 |
> |
/* FIXME maybe tidy up field names? */ |
28 |
> |
/* FIXME comments for less obvious fields */ |
29 |
|
|
30 |
< |
typedef struct{ |
31 |
< |
float user; |
32 |
< |
float kernel; |
33 |
< |
float idle; |
34 |
< |
float iowait; |
35 |
< |
float swap; |
36 |
< |
float nice; |
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 |
< |
}cpu_percent_t; |
104 |
> |
} sg_cpu_percents; |
105 |
|
|
106 |
< |
typedef struct{ |
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 |
< |
}mem_stat_t; |
113 |
> |
} sg_mem_stats; |
114 |
|
|
115 |
< |
typedef struct{ |
115 |
> |
sg_mem_stats *sg_get_mem_stats(); |
116 |
> |
|
117 |
> |
typedef struct { |
118 |
|
double min1; |
119 |
|
double min5; |
120 |
|
double min15; |
121 |
< |
}load_stat_t; |
121 |
> |
} sg_load_stats; |
122 |
|
|
123 |
< |
typedef struct{ |
123 |
> |
sg_load_stats *sg_get_load_stats(); |
124 |
> |
|
125 |
> |
typedef struct { |
126 |
|
char *name_list; |
127 |
|
int num_entries; |
128 |
< |
}user_stat_t; |
128 |
> |
} sg_user_stats; |
129 |
|
|
130 |
< |
typedef struct{ |
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 |
< |
}swap_stat_t; |
136 |
> |
} sg_swap_stats; |
137 |
|
|
138 |
< |
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 |
< |
}general_stat_t; |
138 |
> |
sg_swap_stats *sg_get_swap_stats(); |
139 |
|
|
140 |
|
typedef struct { |
141 |
< |
char *device_name; |
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; |
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 |
< |
}disk_stat_t; |
149 |
> |
long long free_inodes; |
150 |
> |
} sg_fs_stats; |
151 |
|
|
152 |
< |
typedef struct{ |
152 |
> |
sg_fs_stats *sg_get_fs_stats(int *entries); |
153 |
> |
|
154 |
> |
typedef struct { |
155 |
|
char *disk_name; |
156 |
|
long long read_bytes; |
157 |
|
long long write_bytes; |
158 |
|
time_t systime; |
159 |
< |
}diskio_stat_t; |
159 |
> |
} sg_disk_io_stats; |
160 |
|
|
161 |
< |
typedef struct{ |
162 |
< |
int total; |
101 |
< |
int running; |
102 |
< |
int sleeping; |
103 |
< |
int stopped; |
104 |
< |
int zombie; |
105 |
< |
}process_stat_t; |
161 |
> |
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 |
|
|
164 |
< |
typedef struct{ |
164 |
> |
typedef struct { |
165 |
|
char *interface_name; |
166 |
|
long long tx; |
167 |
|
long long rx; |
171 |
|
long long oerrors; |
172 |
|
long long collisions; |
173 |
|
time_t systime; |
174 |
< |
}network_stat_t; |
174 |
> |
} sg_network_io_stats; |
175 |
|
|
176 |
< |
typedef enum{ |
177 |
< |
FULL_DUPLEX, |
121 |
< |
HALF_DUPLEX, |
122 |
< |
UNKNOWN_DUPLEX |
123 |
< |
}statgrab_duplex; |
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 |
|
|
179 |
< |
typedef struct{ |
179 |
> |
typedef enum { |
180 |
> |
SG_IFACE_DUPLEX_FULL, |
181 |
> |
SG_IFACE_DUPLEX_HALF, |
182 |
> |
SG_IFACE_DUPLEX_UNKNOWN |
183 |
> |
} sg_iface_duplex; |
184 |
> |
|
185 |
> |
typedef struct { |
186 |
|
char *interface_name; |
187 |
|
int speed; /* In megabits/sec */ |
188 |
< |
statgrab_duplex dup; |
188 |
> |
sg_iface_duplex dup; |
189 |
|
int up; |
190 |
< |
}network_iface_stat_t; |
190 |
> |
} sg_network_iface_stats; |
191 |
|
|
192 |
< |
typedef struct{ |
192 |
> |
sg_network_iface_stats *sg_get_network_iface_stats(int *entries); |
193 |
> |
|
194 |
> |
typedef struct { |
195 |
|
long long pages_pagein; |
196 |
|
long long pages_pageout; |
197 |
|
time_t systime; |
198 |
< |
}page_stat_t; |
198 |
> |
} sg_page_stats; |
199 |
|
|
200 |
< |
typedef struct{ |
200 |
> |
sg_page_stats *sg_get_page_stats(); |
201 |
> |
sg_page_stats *sg_get_page_stats_diff(); |
202 |
> |
|
203 |
> |
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 |
> |
|
211 |
> |
typedef struct { |
212 |
|
char *process_name; |
213 |
|
char *proctitle; |
214 |
|
|
223 |
|
|
224 |
|
unsigned long long proc_size; /* in bytes */ |
225 |
|
unsigned long long proc_resident; /* in bytes */ |
226 |
< |
time_t time_spent; |
226 |
> |
time_t time_spent; /* time running in seconds */ |
227 |
|
double cpu_percent; |
228 |
|
int nice; |
229 |
< |
int state; |
230 |
< |
}proc_state_t; |
229 |
> |
sg_process_state state; |
230 |
> |
} sg_process_stats; |
231 |
|
|
232 |
< |
int get_proc_snapshot(proc_state_t **proc_state); |
232 |
> |
sg_process_stats *sg_get_process_stats(int *entries); |
233 |
|
|
234 |
< |
cpu_states_t *get_cpu_totals(); |
235 |
< |
cpu_states_t *get_cpu_diff(); |
236 |
< |
cpu_percent_t *cpu_percent_usage(); |
234 |
> |
typedef struct { |
235 |
> |
int total; |
236 |
> |
int running; |
237 |
> |
int sleeping; |
238 |
> |
int stopped; |
239 |
> |
int zombie; |
240 |
> |
} sg_process_count; |
241 |
|
|
242 |
< |
mem_stat_t *get_memory_stats(); |
242 |
> |
sg_process_count *sg_get_process_count(); |
243 |
|
|
244 |
< |
load_stat_t *get_load_stats(); |
245 |
< |
|
246 |
< |
user_stat_t *get_user_stats(); |
170 |
< |
|
171 |
< |
swap_stat_t *get_swap_stats(); |
172 |
< |
|
173 |
< |
general_stat_t *get_general_stats(); |
174 |
< |
|
175 |
< |
disk_stat_t *get_disk_stats(int *entries); |
176 |
< |
diskio_stat_t *get_diskio_stats(int *entries); |
177 |
< |
diskio_stat_t *get_diskio_stats_diff(int *entries); |
178 |
< |
|
179 |
< |
process_stat_t *get_process_stats(); |
180 |
< |
|
181 |
< |
network_stat_t *get_network_stats(int *entries); |
182 |
< |
network_stat_t *get_network_stats_diff(int *entries); |
183 |
< |
|
184 |
< |
network_iface_stat_t *get_network_iface_stats(int *entries); |
185 |
< |
|
186 |
< |
page_stat_t *get_page_stats(); |
187 |
< |
page_stat_t *get_page_stats_diff(); |
188 |
< |
|
189 |
< |
int statgrab_init(void); |
190 |
< |
int statgrab_drop_privileges(void); |
244 |
> |
#ifdef SG_ENABLE_DEPRECATED |
245 |
> |
#include <statgrab_deprecated.h> |
246 |
> |
#endif |
247 |
|
|