| 1 |
< |
/* |
| 2 |
< |
* i-scream central monitoring system |
| 3 |
< |
* http://www.i-scream.org.uk |
| 4 |
< |
* Copyright (C) 2000-2002 i-scream |
| 1 |
> |
/* |
| 2 |
> |
* i-scream libstatgrab |
| 3 |
> |
* http://www.i-scream.org |
| 4 |
> |
* Copyright (C) 2000-2004 i-scream |
| 5 |
|
* |
| 6 |
< |
* This program is free software; you can redistribute it and/or |
| 7 |
< |
* modify it under the terms of the GNU General Public License |
| 8 |
< |
* as published by the Free Software Foundation; either version 2 |
| 9 |
< |
* of the License, or (at your option) any later version. |
| 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 program is distributed in the hope that it will be useful, |
| 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 |
| 14 |
< |
* GNU General Public License for more details. |
| 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 General Public License |
| 17 |
< |
* along with this program; if not, write to the Free Software |
| 18 |
< |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 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$ |
| 22 |
|
*/ |
| 23 |
|
|
| 24 |
+ |
#ifndef STATGRAB_H |
| 25 |
+ |
#define STATGRAB_H |
| 26 |
+ |
|
| 27 |
+ |
#ifdef __cplusplus |
| 28 |
+ |
extern "C" { |
| 29 |
+ |
#endif |
| 30 |
+ |
|
| 31 |
|
#include <sys/types.h> |
| 32 |
|
|
| 33 |
< |
typedef struct{ |
| 34 |
< |
uint_t user; |
| 35 |
< |
uint_t kernel; |
| 26 |
< |
uint_t idle; |
| 27 |
< |
uint_t iowait; |
| 28 |
< |
uint_t swap; |
| 29 |
< |
uint_t nice; |
| 30 |
< |
uint_t total; |
| 31 |
< |
time_t systime; |
| 32 |
< |
}cpu_states_t; |
| 33 |
> |
/* FIXME typedefs for 32/64-bit types */ |
| 34 |
> |
/* FIXME maybe tidy up field names? */ |
| 35 |
> |
/* FIXME comments for less obvious fields */ |
| 36 |
|
|
| 37 |
< |
typedef struct{ |
| 38 |
< |
float user; |
| 39 |
< |
float kernel; |
| 40 |
< |
float idle; |
| 41 |
< |
float iowait; |
| 42 |
< |
float swap; |
| 43 |
< |
float nice; |
| 37 |
> |
int sg_init(void); |
| 38 |
> |
int sg_snapshot(); |
| 39 |
> |
int sg_shutdown(); |
| 40 |
> |
int sg_drop_privileges(void); |
| 41 |
> |
|
| 42 |
> |
typedef enum { |
| 43 |
> |
SG_ERROR_NONE = 0, |
| 44 |
> |
SG_ERROR_ASPRINTF, |
| 45 |
> |
SG_ERROR_DEVICES, |
| 46 |
> |
SG_ERROR_DEVSTAT_GETDEVS, |
| 47 |
> |
SG_ERROR_DEVSTAT_SELECTDEVS, |
| 48 |
> |
SG_ERROR_DISKINFO, |
| 49 |
> |
SG_ERROR_ENOENT, |
| 50 |
> |
SG_ERROR_GETIFADDRS, |
| 51 |
> |
SG_ERROR_GETMNTINFO, |
| 52 |
> |
SG_ERROR_GETPAGESIZE, |
| 53 |
> |
SG_ERROR_HOST, |
| 54 |
> |
SG_ERROR_KSTAT_DATA_LOOKUP, |
| 55 |
> |
SG_ERROR_KSTAT_LOOKUP, |
| 56 |
> |
SG_ERROR_KSTAT_OPEN, |
| 57 |
> |
SG_ERROR_KSTAT_READ, |
| 58 |
> |
SG_ERROR_KVM_GETSWAPINFO, |
| 59 |
> |
SG_ERROR_KVM_OPENFILES, |
| 60 |
> |
SG_ERROR_MALLOC, |
| 61 |
> |
SG_ERROR_MEMSTATUS, |
| 62 |
> |
SG_ERROR_OPEN, |
| 63 |
> |
SG_ERROR_OPENDIR, |
| 64 |
> |
SG_ERROR_PARSE, |
| 65 |
> |
SG_ERROR_PDHADD, |
| 66 |
> |
SG_ERROR_PDHCOLLECT, |
| 67 |
> |
SG_ERROR_PDHOPEN, |
| 68 |
> |
SG_ERROR_PDHREAD, |
| 69 |
> |
SG_ERROR_PERMISSION, |
| 70 |
> |
SG_ERROR_PSTAT, |
| 71 |
> |
SG_ERROR_SETEGID, |
| 72 |
> |
SG_ERROR_SETEUID, |
| 73 |
> |
SG_ERROR_SETMNTENT, |
| 74 |
> |
SG_ERROR_SOCKET, |
| 75 |
> |
SG_ERROR_SWAPCTL, |
| 76 |
> |
SG_ERROR_SYSCONF, |
| 77 |
> |
SG_ERROR_SYSCTL, |
| 78 |
> |
SG_ERROR_SYSCTLBYNAME, |
| 79 |
> |
SG_ERROR_SYSCTLNAMETOMIB, |
| 80 |
> |
SG_ERROR_UNAME, |
| 81 |
> |
SG_ERROR_UNSUPPORTED, |
| 82 |
> |
SG_ERROR_XSW_VER_MISMATCH |
| 83 |
> |
} sg_error; |
| 84 |
> |
|
| 85 |
> |
void sg_set_error(sg_error code, const char *arg); |
| 86 |
> |
void sg_set_error_with_errno(sg_error code, const char *arg); |
| 87 |
> |
sg_error sg_get_error(); |
| 88 |
> |
const char *sg_get_error_arg(); |
| 89 |
> |
int sg_get_error_errno(); |
| 90 |
> |
const char *sg_str_error(sg_error code); |
| 91 |
> |
|
| 92 |
> |
typedef struct { |
| 93 |
> |
char *os_name; |
| 94 |
> |
char *os_release; |
| 95 |
> |
char *os_version; |
| 96 |
> |
char *platform; |
| 97 |
> |
char *hostname; |
| 98 |
> |
time_t uptime; |
| 99 |
> |
} sg_host_info; |
| 100 |
> |
|
| 101 |
> |
sg_host_info *sg_get_host_info(); |
| 102 |
> |
|
| 103 |
> |
typedef struct { |
| 104 |
> |
long long user; |
| 105 |
> |
long long kernel; |
| 106 |
> |
long long idle; |
| 107 |
> |
long long iowait; |
| 108 |
> |
long long swap; |
| 109 |
> |
long long nice; |
| 110 |
> |
long long total; |
| 111 |
> |
time_t systime; |
| 112 |
> |
} sg_cpu_stats; |
| 113 |
> |
|
| 114 |
> |
sg_cpu_stats *sg_get_cpu_stats(); |
| 115 |
> |
sg_cpu_stats *sg_get_cpu_stats_diff(); |
| 116 |
> |
|
| 117 |
> |
typedef struct { |
| 118 |
> |
float user; |
| 119 |
> |
float kernel; |
| 120 |
> |
float idle; |
| 121 |
> |
float iowait; |
| 122 |
> |
float swap; |
| 123 |
> |
float nice; |
| 124 |
|
time_t time_taken; |
| 125 |
< |
}cpu_percent_t; |
| 125 |
> |
} sg_cpu_percents; |
| 126 |
|
|
| 127 |
< |
typedef struct{ |
| 127 |
> |
sg_cpu_percents *sg_get_cpu_percents(); |
| 128 |
> |
|
| 129 |
> |
typedef struct { |
| 130 |
|
long long total; |
| 131 |
|
long long free; |
| 132 |
|
long long used; |
| 133 |
|
long long cache; |
| 134 |
< |
}mem_stat_t; |
| 134 |
> |
} sg_mem_stats; |
| 135 |
|
|
| 136 |
< |
typedef struct{ |
| 136 |
> |
sg_mem_stats *sg_get_mem_stats(); |
| 137 |
> |
|
| 138 |
> |
typedef struct { |
| 139 |
|
double min1; |
| 140 |
|
double min5; |
| 141 |
|
double min15; |
| 142 |
< |
}load_stat_t; |
| 142 |
> |
} sg_load_stats; |
| 143 |
|
|
| 144 |
< |
#ifdef SOLARIS |
| 58 |
< |
#define MAX_LOGIN_NAME_SIZE 8 |
| 59 |
< |
#endif |
| 144 |
> |
sg_load_stats *sg_get_load_stats(); |
| 145 |
|
|
| 146 |
< |
typedef char name[MAX_LOGIN_NAME_SIZE+1]; |
| 147 |
< |
|
| 63 |
< |
typedef struct{ |
| 64 |
< |
name *name_list; |
| 146 |
> |
typedef struct { |
| 147 |
> |
char *name_list; |
| 148 |
|
int num_entries; |
| 149 |
< |
}user_stat_t; |
| 149 |
> |
} sg_user_stats; |
| 150 |
|
|
| 151 |
< |
typedef struct{ |
| 151 |
> |
sg_user_stats *sg_get_user_stats(); |
| 152 |
> |
|
| 153 |
> |
typedef struct { |
| 154 |
|
long long total; |
| 155 |
|
long long used; |
| 156 |
|
long long free; |
| 157 |
< |
}swap_stat_t; |
| 157 |
> |
} sg_swap_stats; |
| 158 |
|
|
| 159 |
< |
typedef struct{ |
| 75 |
< |
char *os_name; |
| 76 |
< |
char *os_release; |
| 77 |
< |
char *os_version; |
| 78 |
< |
char *platform; |
| 79 |
< |
char *hostname; |
| 80 |
< |
time_t uptime; |
| 81 |
< |
}general_stat_t; |
| 159 |
> |
sg_swap_stats *sg_get_swap_stats(); |
| 160 |
|
|
| 161 |
|
typedef struct { |
| 162 |
< |
char *device_name; |
| 162 |
> |
char *device_name; |
| 163 |
|
char *fs_type; |
| 164 |
< |
char *mnt_point; |
| 165 |
< |
long long size; |
| 166 |
< |
long long used; |
| 167 |
< |
long long avail; |
| 168 |
< |
long long total_inodes; |
| 164 |
> |
char *mnt_point; |
| 165 |
> |
long long size; |
| 166 |
> |
long long used; |
| 167 |
> |
long long avail; |
| 168 |
> |
long long total_inodes; |
| 169 |
|
long long used_inodes; |
| 170 |
< |
long long free_inodes; |
| 171 |
< |
}disk_stat_t; |
| 170 |
> |
long long free_inodes; |
| 171 |
> |
long long avail_inodes; |
| 172 |
> |
long long io_size; |
| 173 |
> |
long long block_size; |
| 174 |
> |
long long total_blocks; |
| 175 |
> |
long long free_blocks; |
| 176 |
> |
long long used_blocks; |
| 177 |
> |
long long avail_blocks; |
| 178 |
> |
} sg_fs_stats; |
| 179 |
|
|
| 180 |
< |
typedef struct{ |
| 96 |
< |
int total; |
| 97 |
< |
int running; |
| 98 |
< |
int sleeping; |
| 99 |
< |
int stopped; |
| 100 |
< |
int zombie; |
| 101 |
< |
}process_stat_t; |
| 180 |
> |
sg_fs_stats *sg_get_fs_stats(int *entries); |
| 181 |
|
|
| 182 |
< |
typedef struct{ |
| 182 |
> |
int sg_fs_compare_device_name(const void *va, const void *vb); |
| 183 |
> |
int sg_fs_compare_mnt_point(const void *va, const void *vb); |
| 184 |
> |
|
| 185 |
> |
typedef struct { |
| 186 |
> |
char *disk_name; |
| 187 |
> |
long long read_bytes; |
| 188 |
> |
long long write_bytes; |
| 189 |
> |
time_t systime; |
| 190 |
> |
} sg_disk_io_stats; |
| 191 |
> |
|
| 192 |
> |
sg_disk_io_stats *sg_get_disk_io_stats(int *entries); |
| 193 |
> |
sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries); |
| 194 |
> |
|
| 195 |
> |
int sg_disk_io_compare_name(const void *va, const void *vb); |
| 196 |
> |
|
| 197 |
> |
typedef struct { |
| 198 |
|
char *interface_name; |
| 199 |
|
long long tx; |
| 200 |
|
long long rx; |
| 201 |
+ |
long long ipackets; |
| 202 |
+ |
long long opackets; |
| 203 |
+ |
long long ierrors; |
| 204 |
+ |
long long oerrors; |
| 205 |
+ |
long long collisions; |
| 206 |
|
time_t systime; |
| 207 |
< |
}network_stat_t; |
| 207 |
> |
} sg_network_io_stats; |
| 208 |
|
|
| 209 |
< |
typedef struct{ |
| 210 |
< |
long long num_pagein; |
| 211 |
< |
long long num_pageout; |
| 209 |
> |
sg_network_io_stats *sg_get_network_io_stats(int *entries); |
| 210 |
> |
sg_network_io_stats *sg_get_network_io_stats_diff(int *entries); |
| 211 |
> |
|
| 212 |
> |
int sg_network_io_compare_name(const void *va, const void *vb); |
| 213 |
> |
|
| 214 |
> |
typedef enum { |
| 215 |
> |
SG_IFACE_DUPLEX_FULL, |
| 216 |
> |
SG_IFACE_DUPLEX_HALF, |
| 217 |
> |
SG_IFACE_DUPLEX_UNKNOWN |
| 218 |
> |
} sg_iface_duplex; |
| 219 |
> |
|
| 220 |
> |
typedef struct { |
| 221 |
> |
char *interface_name; |
| 222 |
> |
int speed; /* In megabits/sec */ |
| 223 |
> |
sg_iface_duplex duplex; |
| 224 |
> |
#ifdef SG_ENABLE_DEPRECATED |
| 225 |
> |
sg_iface_duplex dup; |
| 226 |
> |
#endif |
| 227 |
> |
int up; |
| 228 |
> |
} sg_network_iface_stats; |
| 229 |
> |
|
| 230 |
> |
sg_network_iface_stats *sg_get_network_iface_stats(int *entries); |
| 231 |
> |
|
| 232 |
> |
int sg_network_iface_compare_name(const void *va, const void *vb); |
| 233 |
> |
|
| 234 |
> |
typedef struct { |
| 235 |
|
long long pages_pagein; |
| 236 |
|
long long pages_pageout; |
| 237 |
|
time_t systime; |
| 238 |
< |
}page_stat_t; |
| 238 |
> |
} sg_page_stats; |
| 239 |
|
|
| 240 |
< |
cpu_states_t *get_cpu_totals(); |
| 241 |
< |
cpu_states_t *get_cpu_diff(); |
| 120 |
< |
cpu_percent_t *cpu_percent_usage(); |
| 240 |
> |
sg_page_stats *sg_get_page_stats(); |
| 241 |
> |
sg_page_stats *sg_get_page_stats_diff(); |
| 242 |
|
|
| 243 |
< |
mem_stat_t *get_memory_stats(); |
| 243 |
> |
typedef enum { |
| 244 |
> |
SG_PROCESS_STATE_RUNNING, |
| 245 |
> |
SG_PROCESS_STATE_SLEEPING, |
| 246 |
> |
SG_PROCESS_STATE_STOPPED, |
| 247 |
> |
SG_PROCESS_STATE_ZOMBIE, |
| 248 |
> |
SG_PROCESS_STATE_UNKNOWN |
| 249 |
> |
} sg_process_state; |
| 250 |
|
|
| 251 |
< |
load_stat_t *get_load_stats(); |
| 251 |
> |
typedef struct { |
| 252 |
> |
char *process_name; |
| 253 |
> |
char *proctitle; |
| 254 |
|
|
| 255 |
< |
user_stat_t *get_user_stats(); |
| 255 |
> |
pid_t pid; |
| 256 |
> |
pid_t parent; /* Parent pid */ |
| 257 |
> |
pid_t pgid; /* process id of process group leader */ |
| 258 |
|
|
| 259 |
< |
swap_stat_t *get_swap_stats(); |
| 259 |
> |
/* Windows does not have uid_t or gid_t types */ |
| 260 |
> |
#ifndef WIN32 |
| 261 |
> |
uid_t uid; |
| 262 |
> |
uid_t euid; |
| 263 |
> |
gid_t gid; |
| 264 |
> |
gid_t egid; |
| 265 |
> |
#else |
| 266 |
> |
int uid; |
| 267 |
> |
int euid; |
| 268 |
> |
int gid; |
| 269 |
> |
int egid; |
| 270 |
> |
#endif |
| 271 |
|
|
| 272 |
< |
general_stat_t *get_general_stats(); |
| 272 |
> |
unsigned long long proc_size; /* in bytes */ |
| 273 |
> |
unsigned long long proc_resident; /* in bytes */ |
| 274 |
> |
time_t time_spent; /* time running in seconds */ |
| 275 |
> |
double cpu_percent; |
| 276 |
> |
int nice; |
| 277 |
> |
sg_process_state state; |
| 278 |
> |
} sg_process_stats; |
| 279 |
|
|
| 280 |
< |
disk_stat_t *get_disk_stats(int *entries); |
| 280 |
> |
sg_process_stats *sg_get_process_stats(int *entries); |
| 281 |
|
|
| 282 |
< |
process_stat_t *get_process_stats(); |
| 282 |
> |
int sg_process_compare_name(const void *va, const void *vb); |
| 283 |
> |
int sg_process_compare_pid(const void *va, const void *vb); |
| 284 |
> |
int sg_process_compare_uid(const void *va, const void *vb); |
| 285 |
> |
int sg_process_compare_gid(const void *va, const void *vb); |
| 286 |
> |
int sg_process_compare_size(const void *va, const void *vb); |
| 287 |
> |
int sg_process_compare_res(const void *va, const void *vb); |
| 288 |
> |
int sg_process_compare_cpu(const void *va, const void *vb); |
| 289 |
> |
int sg_process_compare_time(const void *va, const void *vb); |
| 290 |
|
|
| 291 |
< |
network_stat_t *get_network_stats(int *entries); |
| 291 |
> |
typedef struct { |
| 292 |
> |
int total; |
| 293 |
> |
int running; |
| 294 |
> |
int sleeping; |
| 295 |
> |
int stopped; |
| 296 |
> |
int zombie; |
| 297 |
> |
} sg_process_count; |
| 298 |
|
|
| 299 |
< |
page_stat_t *get_page_stats(); |
| 299 |
> |
sg_process_count *sg_get_process_count(); |
| 300 |
> |
|
| 301 |
> |
#ifdef SG_ENABLE_DEPRECATED |
| 302 |
> |
#include <statgrab_deprecated.h> |
| 303 |
> |
#endif |
| 304 |
> |
|
| 305 |
> |
#ifdef __cplusplus |
| 306 |
> |
} |
| 307 |
> |
#endif |
| 308 |
> |
|
| 309 |
> |
#endif |