sigar-test 0.7.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/NOTICE +117 -0
- data/README +2 -0
- data/Rakefile +105 -0
- data/bindings/SigarBuild.pm +301 -0
- data/bindings/SigarWrapper.pm +3025 -0
- data/bindings/ruby/extconf.rb +131 -0
- data/bindings/ruby/rbsigar.c +888 -0
- data/include/sigar.h +984 -0
- data/include/sigar_fileinfo.h +157 -0
- data/include/sigar_format.h +65 -0
- data/include/sigar_getline.h +18 -0
- data/include/sigar_log.h +80 -0
- data/include/sigar_private.h +429 -0
- data/include/sigar_ptql.h +53 -0
- data/include/sigar_util.h +197 -0
- data/src/os/aix/aix_sigar.c +2168 -0
- data/src/os/aix/sigar_os.h +73 -0
- data/src/os/darwin/Info.plist.in +27 -0
- data/src/os/darwin/darwin_sigar.c +3718 -0
- data/src/os/darwin/sigar_os.h +80 -0
- data/src/os/hpux/hpux_sigar.c +1361 -0
- data/src/os/hpux/sigar_os.h +49 -0
- data/src/os/linux/linux_sigar.c +2810 -0
- data/src/os/linux/sigar_os.h +82 -0
- data/src/os/solaris/get_mib2.c +321 -0
- data/src/os/solaris/get_mib2.h +127 -0
- data/src/os/solaris/kstats.c +181 -0
- data/src/os/solaris/procfs.c +97 -0
- data/src/os/solaris/sigar_os.h +224 -0
- data/src/os/solaris/solaris_sigar.c +2732 -0
- data/src/os/win32/peb.c +212 -0
- data/src/os/win32/sigar.rc.in +40 -0
- data/src/os/win32/sigar_os.h +685 -0
- data/src/os/win32/sigar_pdh.h +47 -0
- data/src/os/win32/win32_sigar.c +4109 -0
- data/src/sigar.c +2444 -0
- data/src/sigar_cache.c +253 -0
- data/src/sigar_fileinfo.c +815 -0
- data/src/sigar_format.c +696 -0
- data/src/sigar_getline.c +1849 -0
- data/src/sigar_ptql.c +1976 -0
- data/src/sigar_signal.c +216 -0
- data/src/sigar_util.c +1060 -0
- data/src/sigar_version.c.in +22 -0
- data/src/sigar_version_autoconf.c.in +22 -0
- data/version.properties +11 -0
- metadata +91 -0
@@ -0,0 +1,1361 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2004-2009 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
|
+
#include "sigar.h"
|
20
|
+
#include "sigar_private.h"
|
21
|
+
#include "sigar_util.h"
|
22
|
+
#include "sigar_os.h"
|
23
|
+
|
24
|
+
#include <net/if.h>
|
25
|
+
#include <sys/dk.h>
|
26
|
+
#ifndef __ia64__
|
27
|
+
#include <sys/lwp.h>
|
28
|
+
#endif
|
29
|
+
#include <sys/ioctl.h>
|
30
|
+
#include <sys/stat.h>
|
31
|
+
#include <errno.h>
|
32
|
+
|
33
|
+
#ifdef _PSTAT64
|
34
|
+
typedef int64_t pstat_int_t;
|
35
|
+
#else
|
36
|
+
typedef int32_t pstat_int_t;
|
37
|
+
#endif
|
38
|
+
|
39
|
+
int sigar_os_open(sigar_t **sigar)
|
40
|
+
{
|
41
|
+
*sigar = malloc(sizeof(**sigar));
|
42
|
+
|
43
|
+
/* does not change while system is running */
|
44
|
+
pstat_getstatic(&(*sigar)->pstatic,
|
45
|
+
sizeof((*sigar)->pstatic),
|
46
|
+
1, 0);
|
47
|
+
|
48
|
+
(*sigar)->ticks = sysconf(_SC_CLK_TCK);
|
49
|
+
|
50
|
+
(*sigar)->last_pid = -1;
|
51
|
+
|
52
|
+
(*sigar)->pinfo = NULL;
|
53
|
+
|
54
|
+
(*sigar)->mib = -1;
|
55
|
+
|
56
|
+
return SIGAR_OK;
|
57
|
+
|
58
|
+
}
|
59
|
+
|
60
|
+
int sigar_os_close(sigar_t *sigar)
|
61
|
+
{
|
62
|
+
if (sigar->pinfo) {
|
63
|
+
free(sigar->pinfo);
|
64
|
+
}
|
65
|
+
if (sigar->mib >= 0) {
|
66
|
+
close_mib(sigar->mib);
|
67
|
+
}
|
68
|
+
free(sigar);
|
69
|
+
return SIGAR_OK;
|
70
|
+
}
|
71
|
+
|
72
|
+
char *sigar_os_error_string(sigar_t *sigar, int err)
|
73
|
+
{
|
74
|
+
return NULL;
|
75
|
+
}
|
76
|
+
|
77
|
+
int sigar_mem_get(sigar_t *sigar, sigar_mem_t *mem)
|
78
|
+
{
|
79
|
+
struct pst_dynamic stats;
|
80
|
+
struct pst_vminfo vminfo;
|
81
|
+
sigar_uint64_t pagesize = sigar->pstatic.page_size;
|
82
|
+
sigar_uint64_t kern;
|
83
|
+
|
84
|
+
mem->total = sigar->pstatic.physical_memory * pagesize;
|
85
|
+
|
86
|
+
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
87
|
+
|
88
|
+
mem->free = stats.psd_free * pagesize;
|
89
|
+
mem->used = mem->total - mem->free;
|
90
|
+
|
91
|
+
pstat_getvminfo(&vminfo, sizeof(vminfo), 1, 0);
|
92
|
+
|
93
|
+
/* "kernel dynamic memory" */
|
94
|
+
kern = vminfo.psv_kern_dynmem * pagesize;
|
95
|
+
mem->actual_free = mem->free + kern;
|
96
|
+
mem->actual_used = mem->used - kern;
|
97
|
+
|
98
|
+
sigar_mem_calc_ram(sigar, mem);
|
99
|
+
|
100
|
+
return SIGAR_OK;
|
101
|
+
}
|
102
|
+
|
103
|
+
int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
|
104
|
+
{
|
105
|
+
struct pst_swapinfo swapinfo;
|
106
|
+
struct pst_vminfo vminfo;
|
107
|
+
int i=0;
|
108
|
+
|
109
|
+
swap->total = swap->free = 0;
|
110
|
+
|
111
|
+
while (pstat_getswap(&swapinfo, sizeof(swapinfo), 1, i++) > 0) {
|
112
|
+
swapinfo.pss_nfpgs *= 4; /* nfpgs is in 512 byte blocks */
|
113
|
+
|
114
|
+
if (swapinfo.pss_nblksenabled == 0) {
|
115
|
+
swapinfo.pss_nblksenabled = swapinfo.pss_nfpgs;
|
116
|
+
}
|
117
|
+
|
118
|
+
swap->total += swapinfo.pss_nblksenabled;
|
119
|
+
swap->free += swapinfo.pss_nfpgs;
|
120
|
+
}
|
121
|
+
|
122
|
+
swap->used = swap->total - swap->free;
|
123
|
+
|
124
|
+
pstat_getvminfo(&vminfo, sizeof(vminfo), 1, 0);
|
125
|
+
|
126
|
+
swap->page_in = vminfo.psv_spgin;
|
127
|
+
swap->page_out = vminfo.psv_spgout;
|
128
|
+
|
129
|
+
return SIGAR_OK;
|
130
|
+
}
|
131
|
+
|
132
|
+
static void get_cpu_metrics(sigar_t *sigar,
|
133
|
+
sigar_cpu_t *cpu,
|
134
|
+
pstat_int_t *cpu_time)
|
135
|
+
{
|
136
|
+
cpu->user = SIGAR_TICK2MSEC(cpu_time[CP_USER]);
|
137
|
+
|
138
|
+
cpu->sys = SIGAR_TICK2MSEC(cpu_time[CP_SYS] +
|
139
|
+
cpu_time[CP_SSYS]);
|
140
|
+
|
141
|
+
cpu->nice = SIGAR_TICK2MSEC(cpu_time[CP_NICE]);
|
142
|
+
|
143
|
+
cpu->idle = SIGAR_TICK2MSEC(cpu_time[CP_IDLE]);
|
144
|
+
|
145
|
+
cpu->wait = SIGAR_TICK2MSEC(cpu_time[CP_SWAIT] +
|
146
|
+
cpu_time[CP_BLOCK]);
|
147
|
+
|
148
|
+
cpu->irq = SIGAR_TICK2MSEC(cpu_time[CP_INTR]);
|
149
|
+
cpu->soft_irq = 0; /*N/A*/
|
150
|
+
cpu->stolen = 0; /*N/A*/
|
151
|
+
|
152
|
+
cpu->total =
|
153
|
+
cpu->user + cpu->sys + cpu->nice + cpu->idle + cpu->wait + cpu->irq;
|
154
|
+
}
|
155
|
+
|
156
|
+
int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
|
157
|
+
{
|
158
|
+
struct pst_dynamic stats;
|
159
|
+
|
160
|
+
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
161
|
+
sigar->ncpu = stats.psd_proc_cnt;
|
162
|
+
|
163
|
+
get_cpu_metrics(sigar, cpu, stats.psd_cpu_time);
|
164
|
+
|
165
|
+
return SIGAR_OK;
|
166
|
+
}
|
167
|
+
|
168
|
+
int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
|
169
|
+
{
|
170
|
+
int i;
|
171
|
+
struct pst_dynamic stats;
|
172
|
+
|
173
|
+
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
174
|
+
sigar->ncpu = stats.psd_proc_cnt;
|
175
|
+
|
176
|
+
sigar_cpu_list_create(cpulist);
|
177
|
+
|
178
|
+
for (i=0; i<sigar->ncpu; i++) {
|
179
|
+
sigar_cpu_t *cpu;
|
180
|
+
struct pst_processor proc;
|
181
|
+
|
182
|
+
if (pstat_getprocessor(&proc, sizeof(proc), 1, i) < 0) {
|
183
|
+
continue;
|
184
|
+
}
|
185
|
+
|
186
|
+
SIGAR_CPU_LIST_GROW(cpulist);
|
187
|
+
|
188
|
+
cpu = &cpulist->data[cpulist->number++];
|
189
|
+
|
190
|
+
get_cpu_metrics(sigar, cpu, proc.psp_cpu_time);
|
191
|
+
}
|
192
|
+
|
193
|
+
return SIGAR_OK;
|
194
|
+
}
|
195
|
+
|
196
|
+
int sigar_uptime_get(sigar_t *sigar,
|
197
|
+
sigar_uptime_t *uptime)
|
198
|
+
{
|
199
|
+
uptime->uptime = time(NULL) - sigar->pstatic.boot_time;
|
200
|
+
|
201
|
+
return SIGAR_OK;
|
202
|
+
}
|
203
|
+
|
204
|
+
int sigar_loadavg_get(sigar_t *sigar,
|
205
|
+
sigar_loadavg_t *loadavg)
|
206
|
+
{
|
207
|
+
struct pst_dynamic stats;
|
208
|
+
|
209
|
+
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
210
|
+
|
211
|
+
loadavg->loadavg[0] = stats.psd_avg_1_min;
|
212
|
+
loadavg->loadavg[1] = stats.psd_avg_5_min;
|
213
|
+
loadavg->loadavg[2] = stats.psd_avg_15_min;
|
214
|
+
|
215
|
+
return SIGAR_OK;
|
216
|
+
}
|
217
|
+
|
218
|
+
#define PROC_ELTS 16
|
219
|
+
|
220
|
+
int sigar_os_proc_list_get(sigar_t *sigar,
|
221
|
+
sigar_proc_list_t *proclist)
|
222
|
+
{
|
223
|
+
int num, idx=0;
|
224
|
+
struct pst_status proctab[PROC_ELTS];
|
225
|
+
|
226
|
+
while ((num = pstat_getproc(proctab, sizeof(proctab[0]),
|
227
|
+
PROC_ELTS, idx)) > 0)
|
228
|
+
{
|
229
|
+
int i;
|
230
|
+
|
231
|
+
for (i=0; i<num; i++) {
|
232
|
+
SIGAR_PROC_LIST_GROW(proclist);
|
233
|
+
proclist->data[proclist->number++] =
|
234
|
+
proctab[i].pst_pid;
|
235
|
+
}
|
236
|
+
|
237
|
+
idx = proctab[num-1].pst_idx + 1;
|
238
|
+
}
|
239
|
+
|
240
|
+
if (proclist->number == 0) {
|
241
|
+
return errno;
|
242
|
+
}
|
243
|
+
|
244
|
+
return SIGAR_OK;
|
245
|
+
}
|
246
|
+
|
247
|
+
static int sigar_pstat_getproc(sigar_t *sigar, sigar_pid_t pid)
|
248
|
+
{
|
249
|
+
int status, num;
|
250
|
+
time_t timenow = time(NULL);
|
251
|
+
|
252
|
+
if (sigar->pinfo == NULL) {
|
253
|
+
sigar->pinfo = malloc(sizeof(*sigar->pinfo));
|
254
|
+
}
|
255
|
+
|
256
|
+
if (sigar->last_pid == pid) {
|
257
|
+
if ((timenow - sigar->last_getprocs) < SIGAR_LAST_PROC_EXPIRE) {
|
258
|
+
return SIGAR_OK;
|
259
|
+
}
|
260
|
+
}
|
261
|
+
|
262
|
+
sigar->last_pid = pid;
|
263
|
+
sigar->last_getprocs = timenow;
|
264
|
+
|
265
|
+
if (pstat_getproc(sigar->pinfo,
|
266
|
+
sizeof(*sigar->pinfo),
|
267
|
+
0, pid) == -1)
|
268
|
+
{
|
269
|
+
return errno;
|
270
|
+
}
|
271
|
+
|
272
|
+
return SIGAR_OK;
|
273
|
+
}
|
274
|
+
|
275
|
+
int sigar_proc_mem_get(sigar_t *sigar, sigar_pid_t pid,
|
276
|
+
sigar_proc_mem_t *procmem)
|
277
|
+
{
|
278
|
+
int pagesize = sigar->pstatic.page_size;
|
279
|
+
int status = sigar_pstat_getproc(sigar, pid);
|
280
|
+
struct pst_status *pinfo = sigar->pinfo;
|
281
|
+
|
282
|
+
if (status != SIGAR_OK) {
|
283
|
+
return status;
|
284
|
+
}
|
285
|
+
|
286
|
+
procmem->size =
|
287
|
+
pinfo->pst_vtsize + /* text */
|
288
|
+
pinfo->pst_vdsize + /* data */
|
289
|
+
pinfo->pst_vssize + /* stack */
|
290
|
+
pinfo->pst_vshmsize + /* shared memory */
|
291
|
+
pinfo->pst_vmmsize + /* mem-mapped files */
|
292
|
+
pinfo->pst_vusize + /* U-Area & K-Stack */
|
293
|
+
pinfo->pst_viosize; /* I/O dev mapping */
|
294
|
+
|
295
|
+
procmem->size *= pagesize;
|
296
|
+
|
297
|
+
procmem->resident = pinfo->pst_rssize * pagesize;
|
298
|
+
|
299
|
+
procmem->share = pinfo->pst_vshmsize * pagesize;
|
300
|
+
|
301
|
+
procmem->minor_faults = pinfo->pst_minorfaults;
|
302
|
+
procmem->major_faults = pinfo->pst_majorfaults;
|
303
|
+
procmem->page_faults =
|
304
|
+
procmem->minor_faults +
|
305
|
+
procmem->major_faults;
|
306
|
+
|
307
|
+
return SIGAR_OK;
|
308
|
+
}
|
309
|
+
|
310
|
+
int sigar_proc_cumulative_disk_io_get(sigar_t *sigar, sigar_pid_t pid,
|
311
|
+
sigar_proc_cumulative_disk_io_t *proc_cumulative_disk_io)
|
312
|
+
{
|
313
|
+
|
314
|
+
int status = sigar_pstat_getproc(sigar, pid);
|
315
|
+
struct pst_status *pinfo = sigar->pinfo;
|
316
|
+
|
317
|
+
if (status != SIGAR_OK) {
|
318
|
+
return status;
|
319
|
+
}
|
320
|
+
proc_cumulative_disk_io->bytes_read = SIGAR_FIELD_NOTIMPL;
|
321
|
+
proc_cumulative_disk_io->bytes_written = SIGAR_FIELD_NOTIMPL;
|
322
|
+
proc_cumulative_disk_io->bytes_total = pinfo->pst_ioch;
|
323
|
+
|
324
|
+
|
325
|
+
return SIGAR_OK;
|
326
|
+
}
|
327
|
+
|
328
|
+
|
329
|
+
int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
330
|
+
sigar_proc_cred_t *proccred)
|
331
|
+
{
|
332
|
+
int status = sigar_pstat_getproc(sigar, pid);
|
333
|
+
struct pst_status *pinfo = sigar->pinfo;
|
334
|
+
|
335
|
+
if (status != SIGAR_OK) {
|
336
|
+
return status;
|
337
|
+
}
|
338
|
+
|
339
|
+
proccred->uid = pinfo->pst_uid;
|
340
|
+
proccred->gid = pinfo->pst_gid;
|
341
|
+
proccred->euid = pinfo->pst_euid;
|
342
|
+
proccred->egid = pinfo->pst_egid;
|
343
|
+
|
344
|
+
return SIGAR_OK;
|
345
|
+
}
|
346
|
+
|
347
|
+
int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
348
|
+
sigar_proc_time_t *proctime)
|
349
|
+
{
|
350
|
+
int status = sigar_pstat_getproc(sigar, pid);
|
351
|
+
struct pst_status *pinfo = sigar->pinfo;
|
352
|
+
|
353
|
+
if (status != SIGAR_OK) {
|
354
|
+
return status;
|
355
|
+
}
|
356
|
+
|
357
|
+
proctime->start_time = pinfo->pst_start;
|
358
|
+
proctime->start_time *= SIGAR_MSEC;
|
359
|
+
proctime->user = pinfo->pst_utime * SIGAR_MSEC;
|
360
|
+
proctime->sys = pinfo->pst_stime * SIGAR_MSEC;
|
361
|
+
proctime->total = proctime->user + proctime->sys;
|
362
|
+
|
363
|
+
return SIGAR_OK;
|
364
|
+
}
|
365
|
+
|
366
|
+
int sigar_proc_state_get(sigar_t *sigar, sigar_pid_t pid,
|
367
|
+
sigar_proc_state_t *procstate)
|
368
|
+
{
|
369
|
+
int status = sigar_pstat_getproc(sigar, pid);
|
370
|
+
struct pst_status *pinfo = sigar->pinfo;
|
371
|
+
|
372
|
+
if (status != SIGAR_OK) {
|
373
|
+
return status;
|
374
|
+
}
|
375
|
+
|
376
|
+
|
377
|
+
SIGAR_SSTRCPY(procstate->name, pinfo->pst_ucomm);
|
378
|
+
procstate->ppid = pinfo->pst_ppid;
|
379
|
+
procstate->tty = makedev(pinfo->pst_term.psd_major,
|
380
|
+
pinfo->pst_term.psd_minor);
|
381
|
+
procstate->priority = pinfo->pst_pri;
|
382
|
+
procstate->nice = pinfo->pst_nice;
|
383
|
+
procstate->threads = pinfo->pst_nlwps;
|
384
|
+
procstate->processor = pinfo->pst_procnum;
|
385
|
+
|
386
|
+
/* cast to prevent compiler warning: */
|
387
|
+
/* Case label too big for the type of the switch expression */
|
388
|
+
switch ((int32_t)pinfo->pst_stat) {
|
389
|
+
case PS_SLEEP:
|
390
|
+
procstate->state = 'S';
|
391
|
+
break;
|
392
|
+
case PS_RUN:
|
393
|
+
procstate->state = 'R';
|
394
|
+
break;
|
395
|
+
case PS_STOP:
|
396
|
+
procstate->state = 'T';
|
397
|
+
break;
|
398
|
+
case PS_ZOMBIE:
|
399
|
+
procstate->state = 'Z';
|
400
|
+
break;
|
401
|
+
case PS_IDLE:
|
402
|
+
procstate->state = 'D';
|
403
|
+
break;
|
404
|
+
}
|
405
|
+
|
406
|
+
return SIGAR_OK;
|
407
|
+
}
|
408
|
+
|
409
|
+
int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
410
|
+
sigar_proc_args_t *procargs)
|
411
|
+
{
|
412
|
+
char *args, *arg;
|
413
|
+
#ifdef PSTAT_GETCOMMANDLINE
|
414
|
+
char buf[1024]; /* kernel limit */
|
415
|
+
|
416
|
+
# ifdef pstat_getcommandline /* 11i v2 + */
|
417
|
+
if (pstat_getcommandline(buf, sizeof(buf), sizeof(buf[0]), pid) == -1) {
|
418
|
+
return errno;
|
419
|
+
}
|
420
|
+
# else
|
421
|
+
union pstun pu;
|
422
|
+
|
423
|
+
pu.pst_command = buf;
|
424
|
+
if (pstat(PSTAT_GETCOMMANDLINE, pu, sizeof(buf), sizeof(buf[0]), pid) == -1) {
|
425
|
+
return errno;
|
426
|
+
}
|
427
|
+
# endif /* pstat_getcommandline */
|
428
|
+
|
429
|
+
args = buf;
|
430
|
+
#else
|
431
|
+
struct pst_status status;
|
432
|
+
|
433
|
+
if (pstat_getproc(&status, sizeof(status), 0, pid) == -1) {
|
434
|
+
return errno;
|
435
|
+
}
|
436
|
+
|
437
|
+
args = status.pst_cmd;
|
438
|
+
#endif
|
439
|
+
|
440
|
+
while (*args && (arg = sigar_getword(&args, ' '))) {
|
441
|
+
SIGAR_PROC_ARGS_GROW(procargs);
|
442
|
+
procargs->data[procargs->number++] = arg;
|
443
|
+
}
|
444
|
+
|
445
|
+
return SIGAR_OK;
|
446
|
+
}
|
447
|
+
|
448
|
+
int sigar_proc_env_get(sigar_t *sigar, sigar_pid_t pid,
|
449
|
+
sigar_proc_env_t *procenv)
|
450
|
+
{
|
451
|
+
return SIGAR_ENOTIMPL;
|
452
|
+
}
|
453
|
+
|
454
|
+
int sigar_proc_fd_get(sigar_t *sigar, sigar_pid_t pid,
|
455
|
+
sigar_proc_fd_t *procfd)
|
456
|
+
{
|
457
|
+
struct pst_status status;
|
458
|
+
int idx=0, n;
|
459
|
+
struct pst_fileinfo2 psf[16];
|
460
|
+
|
461
|
+
procfd->total = 0;
|
462
|
+
|
463
|
+
if (pstat_getproc(&status, sizeof(status), 0, pid) == -1) {
|
464
|
+
return errno;
|
465
|
+
}
|
466
|
+
|
467
|
+
/* HPUX 11.31 removed the deprecated pstat_getfile call */
|
468
|
+
while ((n = pstat_getfile2(psf, sizeof(psf[0]),
|
469
|
+
sizeof(psf)/sizeof(psf[0]),
|
470
|
+
idx, pid)) > 0)
|
471
|
+
{
|
472
|
+
procfd->total += n;
|
473
|
+
idx = psf[n-1].psf_fd + 1;
|
474
|
+
}
|
475
|
+
|
476
|
+
if (n == -1) {
|
477
|
+
return errno;
|
478
|
+
}
|
479
|
+
|
480
|
+
return SIGAR_OK;
|
481
|
+
}
|
482
|
+
|
483
|
+
int sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
|
484
|
+
sigar_proc_exe_t *procexe)
|
485
|
+
{
|
486
|
+
#ifdef __pst_fid /* 11.11+ */
|
487
|
+
int rc;
|
488
|
+
struct pst_status status;
|
489
|
+
|
490
|
+
if (pstat_getproc(&status, sizeof(status), 0, pid) == -1) {
|
491
|
+
return errno;
|
492
|
+
}
|
493
|
+
|
494
|
+
rc = pstat_getpathname(procexe->cwd,
|
495
|
+
sizeof(procexe->cwd),
|
496
|
+
&status.pst_fid_cdir);
|
497
|
+
if (rc == -1) {
|
498
|
+
return errno;
|
499
|
+
}
|
500
|
+
|
501
|
+
rc = pstat_getpathname(procexe->name,
|
502
|
+
sizeof(procexe->name),
|
503
|
+
&status.pst_fid_text);
|
504
|
+
if (rc == -1) {
|
505
|
+
return errno;
|
506
|
+
}
|
507
|
+
|
508
|
+
rc = pstat_getpathname(procexe->root,
|
509
|
+
sizeof(procexe->root),
|
510
|
+
&status.pst_fid_rdir);
|
511
|
+
if (rc == -1) {
|
512
|
+
return errno;
|
513
|
+
}
|
514
|
+
|
515
|
+
return SIGAR_OK;
|
516
|
+
#else
|
517
|
+
return SIGAR_ENOTIMPL; /* 11.00 */
|
518
|
+
#endif
|
519
|
+
}
|
520
|
+
|
521
|
+
int sigar_proc_modules_get(sigar_t *sigar, sigar_pid_t pid,
|
522
|
+
sigar_proc_modules_t *procmods)
|
523
|
+
{
|
524
|
+
return SIGAR_ENOTIMPL;
|
525
|
+
}
|
526
|
+
|
527
|
+
#define TIME_NSEC(t) \
|
528
|
+
(SIGAR_SEC2NANO((t).tv_sec) + (sigar_uint64_t)(t).tv_nsec)
|
529
|
+
|
530
|
+
int sigar_thread_cpu_get(sigar_t *sigar,
|
531
|
+
sigar_uint64_t id,
|
532
|
+
sigar_thread_cpu_t *cpu)
|
533
|
+
{
|
534
|
+
#ifdef __ia64__
|
535
|
+
/* XXX seems _lwp funcs were for solaris compat and dont exist
|
536
|
+
* on itanium. hp docs claim that have equiv functions,
|
537
|
+
* but wtf is it for _lwp_info?
|
538
|
+
*/
|
539
|
+
return SIGAR_ENOTIMPL;
|
540
|
+
#else
|
541
|
+
struct lwpinfo info;
|
542
|
+
|
543
|
+
if (id != 0) {
|
544
|
+
return SIGAR_ENOTIMPL;
|
545
|
+
}
|
546
|
+
|
547
|
+
_lwp_info(&info);
|
548
|
+
|
549
|
+
cpu->user = TIME_NSEC(info.lwp_utime);
|
550
|
+
cpu->sys = TIME_NSEC(info.lwp_stime);
|
551
|
+
cpu->total = TIME_NSEC(info.lwp_utime) + TIME_NSEC(info.lwp_stime);
|
552
|
+
|
553
|
+
return SIGAR_OK;
|
554
|
+
#endif
|
555
|
+
}
|
556
|
+
|
557
|
+
#include <mntent.h>
|
558
|
+
|
559
|
+
int sigar_os_fs_type_get(sigar_file_system_t *fsp)
|
560
|
+
{
|
561
|
+
char *type = fsp->sys_type_name;
|
562
|
+
|
563
|
+
switch (*type) {
|
564
|
+
case 'h':
|
565
|
+
if (strEQ(type, "hfs")) {
|
566
|
+
fsp->type = SIGAR_FSTYPE_LOCAL_DISK;
|
567
|
+
}
|
568
|
+
break;
|
569
|
+
case 'c':
|
570
|
+
if (strEQ(type, "cdfs")) {
|
571
|
+
fsp->type = SIGAR_FSTYPE_CDROM;
|
572
|
+
}
|
573
|
+
break;
|
574
|
+
}
|
575
|
+
|
576
|
+
return fsp->type;
|
577
|
+
}
|
578
|
+
|
579
|
+
int sigar_file_system_list_get(sigar_t *sigar,
|
580
|
+
sigar_file_system_list_t *fslist)
|
581
|
+
{
|
582
|
+
struct mntent *ent;
|
583
|
+
|
584
|
+
FILE *fp;
|
585
|
+
sigar_file_system_t *fsp;
|
586
|
+
|
587
|
+
if (!(fp = setmntent(MNT_MNTTAB, "r"))) {
|
588
|
+
return errno;
|
589
|
+
}
|
590
|
+
|
591
|
+
sigar_file_system_list_create(fslist);
|
592
|
+
|
593
|
+
while ((ent = getmntent(fp))) {
|
594
|
+
if ((*(ent->mnt_type) == 's') &&
|
595
|
+
strEQ(ent->mnt_type, "swap"))
|
596
|
+
{
|
597
|
+
/*
|
598
|
+
* in this case, devname == "...", for
|
599
|
+
* which statfs chokes on. so skip it.
|
600
|
+
* also notice hpux df command has no swap info.
|
601
|
+
*/
|
602
|
+
continue;
|
603
|
+
}
|
604
|
+
|
605
|
+
SIGAR_FILE_SYSTEM_LIST_GROW(fslist);
|
606
|
+
|
607
|
+
fsp = &fslist->data[fslist->number++];
|
608
|
+
|
609
|
+
SIGAR_SSTRCPY(fsp->dir_name, ent->mnt_dir);
|
610
|
+
SIGAR_SSTRCPY(fsp->dev_name, ent->mnt_fsname);
|
611
|
+
SIGAR_SSTRCPY(fsp->sys_type_name, ent->mnt_type);
|
612
|
+
SIGAR_SSTRCPY(fsp->options, ent->mnt_opts);
|
613
|
+
sigar_fs_type_init(fsp);
|
614
|
+
}
|
615
|
+
|
616
|
+
endmntent(fp);
|
617
|
+
|
618
|
+
return SIGAR_OK;
|
619
|
+
}
|
620
|
+
|
621
|
+
static int create_fsdev_cache(sigar_t *sigar)
|
622
|
+
{
|
623
|
+
sigar_file_system_list_t fslist;
|
624
|
+
int i;
|
625
|
+
int status =
|
626
|
+
sigar_file_system_list_get(sigar, &fslist);
|
627
|
+
|
628
|
+
if (status != SIGAR_OK) {
|
629
|
+
return status;
|
630
|
+
}
|
631
|
+
|
632
|
+
sigar->fsdev = sigar_cache_new(15);
|
633
|
+
|
634
|
+
for (i=0; i<fslist.number; i++) {
|
635
|
+
sigar_file_system_t *fsp = &fslist.data[i];
|
636
|
+
|
637
|
+
if (fsp->type == SIGAR_FSTYPE_LOCAL_DISK) {
|
638
|
+
sigar_cache_entry_t *ent;
|
639
|
+
struct stat sb;
|
640
|
+
|
641
|
+
if (stat(fsp->dir_name, &sb) < 0) {
|
642
|
+
continue;
|
643
|
+
}
|
644
|
+
|
645
|
+
ent = sigar_cache_get(sigar->fsdev, SIGAR_FSDEV_ID(sb));
|
646
|
+
ent->value = strdup(fsp->dev_name);
|
647
|
+
}
|
648
|
+
}
|
649
|
+
|
650
|
+
return SIGAR_OK;
|
651
|
+
}
|
652
|
+
|
653
|
+
int sigar_disk_usage_get(sigar_t *sigar, const char *name,
|
654
|
+
sigar_disk_usage_t *usage)
|
655
|
+
{
|
656
|
+
return SIGAR_ENOTIMPL;
|
657
|
+
}
|
658
|
+
|
659
|
+
int sigar_file_system_usage_get(sigar_t *sigar,
|
660
|
+
const char *dirname,
|
661
|
+
sigar_file_system_usage_t *fsusage)
|
662
|
+
{
|
663
|
+
struct stat sb;
|
664
|
+
int status = sigar_statvfs(sigar, dirname, fsusage);
|
665
|
+
|
666
|
+
if (status != SIGAR_OK) {
|
667
|
+
return status;
|
668
|
+
}
|
669
|
+
|
670
|
+
fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage);
|
671
|
+
|
672
|
+
SIGAR_DISK_STATS_INIT(&fsusage->disk);
|
673
|
+
|
674
|
+
if (!sigar->fsdev) {
|
675
|
+
if (create_fsdev_cache(sigar) != SIGAR_OK) {
|
676
|
+
return SIGAR_OK;
|
677
|
+
}
|
678
|
+
}
|
679
|
+
|
680
|
+
if (stat(dirname, &sb) == 0) {
|
681
|
+
sigar_cache_entry_t *ent;
|
682
|
+
struct pst_lvinfo lv;
|
683
|
+
struct stat devsb;
|
684
|
+
char *devname;
|
685
|
+
int retval;
|
686
|
+
|
687
|
+
ent = sigar_cache_get(sigar->fsdev, SIGAR_FSDEV_ID(sb));
|
688
|
+
if (ent->value == NULL) {
|
689
|
+
return SIGAR_OK;
|
690
|
+
}
|
691
|
+
|
692
|
+
if (stat((char *)ent->value, &devsb) < 0) {
|
693
|
+
return SIGAR_OK;
|
694
|
+
}
|
695
|
+
|
696
|
+
retval = pstat_getlv(&lv, sizeof(lv), 0, (int)devsb.st_rdev);
|
697
|
+
|
698
|
+
if (retval == 1) {
|
699
|
+
fsusage->disk.reads = lv.psl_rxfer;
|
700
|
+
fsusage->disk.writes = lv.psl_wxfer;
|
701
|
+
fsusage->disk.read_bytes = lv.psl_rcount;
|
702
|
+
fsusage->disk.write_bytes = lv.psl_wcount;
|
703
|
+
fsusage->disk.queue = SIGAR_FIELD_NOTIMPL;
|
704
|
+
}
|
705
|
+
}
|
706
|
+
|
707
|
+
return SIGAR_OK;
|
708
|
+
}
|
709
|
+
|
710
|
+
int sigar_cpu_info_list_get(sigar_t *sigar,
|
711
|
+
sigar_cpu_info_list_t *cpu_infos)
|
712
|
+
{
|
713
|
+
int i;
|
714
|
+
struct pst_dynamic stats;
|
715
|
+
|
716
|
+
pstat_getdynamic(&stats, sizeof(stats), 1, 0);
|
717
|
+
sigar->ncpu = stats.psd_proc_cnt;
|
718
|
+
|
719
|
+
sigar_cpu_info_list_create(cpu_infos);
|
720
|
+
|
721
|
+
for (i=0; i<sigar->ncpu; i++) {
|
722
|
+
sigar_cpu_info_t *info;
|
723
|
+
struct pst_processor proc;
|
724
|
+
|
725
|
+
if (pstat_getprocessor(&proc, sizeof(proc), 1, i) < 0) {
|
726
|
+
perror("pstat_getprocessor");
|
727
|
+
continue;
|
728
|
+
}
|
729
|
+
|
730
|
+
SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
|
731
|
+
|
732
|
+
info = &cpu_infos->data[cpu_infos->number++];
|
733
|
+
|
734
|
+
info->total_cores = sigar->ncpu;
|
735
|
+
info->cores_per_socket = 1; /*XXX*/
|
736
|
+
info->total_sockets = sigar->ncpu; /*XXX*/
|
737
|
+
|
738
|
+
#ifdef __ia64__
|
739
|
+
SIGAR_SSTRCPY(info->vendor, "Intel"); /*XXX*/
|
740
|
+
SIGAR_SSTRCPY(info->model, "Itanium"); /*XXX*/
|
741
|
+
#else
|
742
|
+
SIGAR_SSTRCPY(info->vendor, "HP"); /*XXX*/
|
743
|
+
SIGAR_SSTRCPY(info->model, "PA RISC"); /*XXX*/
|
744
|
+
#endif
|
745
|
+
#ifdef PSP_MAX_CACHE_LEVELS /* 11.31+; see SIGAR-196 */
|
746
|
+
info->mhz = proc.psp_cpu_frequency / 1000000;
|
747
|
+
#else
|
748
|
+
info->mhz = sigar->ticks * proc.psp_iticksperclktick / 1000000;
|
749
|
+
#endif
|
750
|
+
info->cache_size = SIGAR_FIELD_NOTIMPL; /*XXX*/
|
751
|
+
}
|
752
|
+
|
753
|
+
return SIGAR_OK;
|
754
|
+
}
|
755
|
+
|
756
|
+
static int sigar_get_mib_info(sigar_t *sigar,
|
757
|
+
struct nmparms *parms)
|
758
|
+
{
|
759
|
+
if (sigar->mib < 0) {
|
760
|
+
if ((sigar->mib = open_mib("/dev/ip", O_RDONLY, 0, 0)) < 0) {
|
761
|
+
return errno;
|
762
|
+
}
|
763
|
+
}
|
764
|
+
return get_mib_info(sigar->mib, parms);
|
765
|
+
}
|
766
|
+
|
767
|
+
/* wrapper around get_physical_stat() */
|
768
|
+
static int sigar_get_physical_stat(sigar_t *sigar, int *count)
|
769
|
+
{
|
770
|
+
int status;
|
771
|
+
unsigned int len;
|
772
|
+
struct nmparms parms;
|
773
|
+
|
774
|
+
len = sizeof(*count);
|
775
|
+
parms.objid = ID_ifNumber;
|
776
|
+
parms.buffer = count;
|
777
|
+
parms.len = &len;
|
778
|
+
|
779
|
+
if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
|
780
|
+
return status;
|
781
|
+
}
|
782
|
+
|
783
|
+
len = sizeof(nmapi_phystat) * *count;
|
784
|
+
|
785
|
+
if (sigar->ifconf_len < len) {
|
786
|
+
sigar->ifconf_buf = realloc(sigar->ifconf_buf, len);
|
787
|
+
sigar->ifconf_len = len;
|
788
|
+
}
|
789
|
+
|
790
|
+
if (get_physical_stat(sigar->ifconf_buf, &len) < 0) {
|
791
|
+
return errno;
|
792
|
+
}
|
793
|
+
else {
|
794
|
+
return SIGAR_OK;
|
795
|
+
}
|
796
|
+
}
|
797
|
+
|
798
|
+
#define SIGAR_IF_NAMESIZE 16
|
799
|
+
/* hpux if_indextoname() does not work as advertised in 11.11 */
|
800
|
+
static int sigar_if_indextoname(sigar_t *sigar,
|
801
|
+
char *name,
|
802
|
+
int index)
|
803
|
+
{
|
804
|
+
int i, status, count;
|
805
|
+
nmapi_phystat *stat;
|
806
|
+
|
807
|
+
if ((status = sigar_get_physical_stat(sigar, &count) != SIGAR_OK)) {
|
808
|
+
return status;
|
809
|
+
}
|
810
|
+
|
811
|
+
for (i=0, stat = (nmapi_phystat *)sigar->ifconf_buf;
|
812
|
+
i<count;
|
813
|
+
i++, stat++)
|
814
|
+
{
|
815
|
+
if (stat->if_entry.ifIndex == index) {
|
816
|
+
strncpy(name, stat->nm_device, SIGAR_IF_NAMESIZE);
|
817
|
+
return SIGAR_OK;
|
818
|
+
}
|
819
|
+
}
|
820
|
+
|
821
|
+
return ENXIO;
|
822
|
+
}
|
823
|
+
|
824
|
+
int sigar_net_route_list_get(sigar_t *sigar,
|
825
|
+
sigar_net_route_list_t *routelist)
|
826
|
+
{
|
827
|
+
int status, count, i;
|
828
|
+
unsigned int len;
|
829
|
+
struct nmparms parms;
|
830
|
+
mib_ipRouteEnt *routes;
|
831
|
+
sigar_net_route_t *route;
|
832
|
+
|
833
|
+
len = sizeof(count);
|
834
|
+
parms.objid = ID_ipRouteNumEnt;
|
835
|
+
parms.buffer = &count;
|
836
|
+
parms.len = &len;
|
837
|
+
|
838
|
+
if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
|
839
|
+
return status;
|
840
|
+
}
|
841
|
+
|
842
|
+
len = count * sizeof(*routes);
|
843
|
+
routes = malloc(len);
|
844
|
+
|
845
|
+
parms.objid = ID_ipRouteTable;
|
846
|
+
parms.buffer = routes;
|
847
|
+
parms.len = &len;
|
848
|
+
|
849
|
+
if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
|
850
|
+
free(routes);
|
851
|
+
return status;
|
852
|
+
}
|
853
|
+
|
854
|
+
routelist->size = routelist->number = 0;
|
855
|
+
|
856
|
+
sigar_net_route_list_create(routelist);
|
857
|
+
|
858
|
+
for (i=0; i<count; i++) {
|
859
|
+
mib_ipRouteEnt *ent = &routes[i];
|
860
|
+
|
861
|
+
SIGAR_NET_ROUTE_LIST_GROW(routelist);
|
862
|
+
|
863
|
+
route = &routelist->data[routelist->number++];
|
864
|
+
SIGAR_ZERO(route); /* XXX: other fields */
|
865
|
+
|
866
|
+
sigar_net_address_set(route->destination,
|
867
|
+
ent->Dest);
|
868
|
+
|
869
|
+
sigar_net_address_set(route->mask,
|
870
|
+
ent->Mask);
|
871
|
+
|
872
|
+
sigar_net_address_set(route->gateway,
|
873
|
+
ent->NextHop);
|
874
|
+
|
875
|
+
sigar_if_indextoname(sigar, route->ifname, ent->IfIndex);
|
876
|
+
|
877
|
+
route->flags = SIGAR_RTF_UP;
|
878
|
+
if ((ent->Dest == 0) &&
|
879
|
+
(ent->Mask == 0))
|
880
|
+
{
|
881
|
+
route->flags |= SIGAR_RTF_GATEWAY;
|
882
|
+
}
|
883
|
+
}
|
884
|
+
|
885
|
+
free(routes);
|
886
|
+
|
887
|
+
return SIGAR_OK;
|
888
|
+
}
|
889
|
+
|
890
|
+
static int get_mib_ifstat(sigar_t *sigar,
|
891
|
+
const char *name,
|
892
|
+
mib_ifEntry *mib)
|
893
|
+
{
|
894
|
+
int i, status, count;
|
895
|
+
nmapi_phystat *stat;
|
896
|
+
|
897
|
+
if ((status = sigar_get_physical_stat(sigar, &count) != SIGAR_OK)) {
|
898
|
+
return status;
|
899
|
+
}
|
900
|
+
|
901
|
+
for (i=0, stat = (nmapi_phystat *)sigar->ifconf_buf;
|
902
|
+
i<count;
|
903
|
+
i++, stat++)
|
904
|
+
{
|
905
|
+
if (strEQ(stat->nm_device, name)) {
|
906
|
+
memcpy(mib, &stat->if_entry, sizeof(*mib));
|
907
|
+
return SIGAR_OK;
|
908
|
+
}
|
909
|
+
}
|
910
|
+
|
911
|
+
return ENXIO;
|
912
|
+
}
|
913
|
+
|
914
|
+
int sigar_net_interface_stat_get(sigar_t *sigar, const char *name,
|
915
|
+
sigar_net_interface_stat_t *ifstat)
|
916
|
+
{
|
917
|
+
int status;
|
918
|
+
mib_ifEntry mib;
|
919
|
+
|
920
|
+
status = get_mib_ifstat(sigar, name, &mib);
|
921
|
+
|
922
|
+
if (status != SIGAR_OK) {
|
923
|
+
return status;
|
924
|
+
}
|
925
|
+
|
926
|
+
ifstat->rx_bytes = mib.ifInOctets;
|
927
|
+
ifstat->rx_packets = mib.ifInUcastPkts + mib.ifInNUcastPkts;
|
928
|
+
ifstat->rx_errors = mib.ifInErrors;
|
929
|
+
ifstat->rx_dropped = mib.ifInDiscards;
|
930
|
+
ifstat->rx_overruns = SIGAR_FIELD_NOTIMPL;
|
931
|
+
ifstat->rx_frame = SIGAR_FIELD_NOTIMPL;
|
932
|
+
|
933
|
+
ifstat->tx_bytes = mib.ifOutOctets;
|
934
|
+
ifstat->tx_packets = mib.ifOutUcastPkts + mib.ifOutNUcastPkts;
|
935
|
+
ifstat->tx_errors = mib.ifOutErrors;
|
936
|
+
ifstat->tx_dropped = mib.ifOutDiscards;
|
937
|
+
ifstat->tx_overruns = SIGAR_FIELD_NOTIMPL;
|
938
|
+
ifstat->tx_collisions = SIGAR_FIELD_NOTIMPL;
|
939
|
+
ifstat->tx_carrier = SIGAR_FIELD_NOTIMPL;
|
940
|
+
|
941
|
+
ifstat->speed = mib.ifSpeed;
|
942
|
+
|
943
|
+
return SIGAR_OK;
|
944
|
+
}
|
945
|
+
|
946
|
+
int sigar_net_interface_ipv6_config_get(sigar_t *sigar, const char *name,
|
947
|
+
sigar_net_interface_config_t *ifconfig)
|
948
|
+
{
|
949
|
+
int sock;
|
950
|
+
struct if_laddrreq iflr;
|
951
|
+
|
952
|
+
if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
|
953
|
+
return errno;
|
954
|
+
}
|
955
|
+
|
956
|
+
SIGAR_SSTRCPY(iflr.iflr_name, name);
|
957
|
+
|
958
|
+
if (ioctl(sock, SIOCGLIFADDR, &iflr) == 0) {
|
959
|
+
struct in6_addr *addr = SIGAR_SIN6_ADDR(&iflr.iflr_addr);
|
960
|
+
|
961
|
+
sigar_net_address6_set(ifconfig->address6, addr);
|
962
|
+
sigar_net_interface_scope6_set(ifconfig, addr);
|
963
|
+
|
964
|
+
if (ioctl(sock, SIOCGLIFNETMASK, &iflr) == 0) {
|
965
|
+
addr = SIGAR_SIN6_ADDR(&iflr.iflr_addr);
|
966
|
+
ifconfig->prefix6_length = 10; /*XXX*/
|
967
|
+
}
|
968
|
+
}
|
969
|
+
|
970
|
+
close(sock);
|
971
|
+
return SIGAR_OK;
|
972
|
+
}
|
973
|
+
|
974
|
+
static int net_conn_get_udp_listen(sigar_net_connection_walker_t *walker)
|
975
|
+
{
|
976
|
+
sigar_t *sigar = walker->sigar;
|
977
|
+
int flags = walker->flags;
|
978
|
+
int status, count, i;
|
979
|
+
unsigned int len;
|
980
|
+
mib_udpLsnEnt *entries;
|
981
|
+
struct nmparms parms;
|
982
|
+
|
983
|
+
len = sizeof(count);
|
984
|
+
parms.objid = ID_udpLsnNumEnt;
|
985
|
+
parms.buffer = &count;
|
986
|
+
parms.len = &len;
|
987
|
+
|
988
|
+
if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
|
989
|
+
return status;
|
990
|
+
}
|
991
|
+
|
992
|
+
if (count <= 0) {
|
993
|
+
return ENOENT;
|
994
|
+
}
|
995
|
+
|
996
|
+
len = count * sizeof(*entries);
|
997
|
+
entries = malloc(len);
|
998
|
+
parms.objid = ID_udpLsnTable;
|
999
|
+
parms.buffer = entries;
|
1000
|
+
parms.len = &len;
|
1001
|
+
|
1002
|
+
if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
|
1003
|
+
free(entries);
|
1004
|
+
return status;
|
1005
|
+
}
|
1006
|
+
|
1007
|
+
for (i=0; i<count; i++) {
|
1008
|
+
sigar_net_connection_t conn;
|
1009
|
+
mib_udpLsnEnt *entry = &entries[i];
|
1010
|
+
|
1011
|
+
SIGAR_ZERO(&conn);
|
1012
|
+
|
1013
|
+
conn.type = SIGAR_NETCONN_UDP;
|
1014
|
+
|
1015
|
+
conn.local_port = (unsigned short)entry->LocalPort;
|
1016
|
+
conn.remote_port = 0;
|
1017
|
+
|
1018
|
+
sigar_net_address_set(conn.local_address,
|
1019
|
+
entry->LocalAddress);
|
1020
|
+
|
1021
|
+
sigar_net_address_set(conn.remote_address, 0);
|
1022
|
+
|
1023
|
+
conn.send_queue = conn.receive_queue = SIGAR_FIELD_NOTIMPL;
|
1024
|
+
|
1025
|
+
if (walker->add_connection(walker, &conn) != SIGAR_OK) {
|
1026
|
+
break;
|
1027
|
+
}
|
1028
|
+
}
|
1029
|
+
|
1030
|
+
free(entries);
|
1031
|
+
return SIGAR_OK;
|
1032
|
+
}
|
1033
|
+
|
1034
|
+
static int net_conn_get_udp(sigar_net_connection_walker_t *walker)
|
1035
|
+
{
|
1036
|
+
int status = SIGAR_OK;
|
1037
|
+
|
1038
|
+
if (walker->flags & SIGAR_NETCONN_SERVER) {
|
1039
|
+
status = net_conn_get_udp_listen(walker);
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
return status;
|
1043
|
+
}
|
1044
|
+
|
1045
|
+
#define IS_TCP_SERVER(state, flags) \
|
1046
|
+
((flags & SIGAR_NETCONN_SERVER) && (state == TCLISTEN))
|
1047
|
+
|
1048
|
+
#define IS_TCP_CLIENT(state, flags) \
|
1049
|
+
((flags & SIGAR_NETCONN_CLIENT) && (state != TCLISTEN))
|
1050
|
+
|
1051
|
+
static int net_conn_get_tcp(sigar_net_connection_walker_t *walker)
|
1052
|
+
{
|
1053
|
+
sigar_t *sigar = walker->sigar;
|
1054
|
+
int flags = walker->flags;
|
1055
|
+
int status, count, i;
|
1056
|
+
unsigned int len;
|
1057
|
+
mib_tcpConnEnt *entries;
|
1058
|
+
struct nmparms parms;
|
1059
|
+
|
1060
|
+
len = sizeof(count);
|
1061
|
+
parms.objid = ID_tcpConnNumEnt;
|
1062
|
+
parms.buffer = &count;
|
1063
|
+
parms.len = &len;
|
1064
|
+
|
1065
|
+
if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
|
1066
|
+
return status;
|
1067
|
+
}
|
1068
|
+
|
1069
|
+
if (count <= 0) {
|
1070
|
+
return ENOENT;
|
1071
|
+
}
|
1072
|
+
|
1073
|
+
len = count * sizeof(*entries);
|
1074
|
+
entries = malloc(len);
|
1075
|
+
parms.objid = ID_tcpConnTable;
|
1076
|
+
parms.buffer = entries;
|
1077
|
+
parms.len = &len;
|
1078
|
+
|
1079
|
+
if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
|
1080
|
+
free(entries);
|
1081
|
+
return status;
|
1082
|
+
}
|
1083
|
+
|
1084
|
+
for (i=0; i<count; i++) {
|
1085
|
+
sigar_net_connection_t conn;
|
1086
|
+
mib_tcpConnEnt *entry = &entries[i];
|
1087
|
+
int state = entry->State;
|
1088
|
+
|
1089
|
+
if (!(IS_TCP_SERVER(state, flags) ||
|
1090
|
+
IS_TCP_CLIENT(state, flags)))
|
1091
|
+
{
|
1092
|
+
continue;
|
1093
|
+
}
|
1094
|
+
|
1095
|
+
SIGAR_ZERO(&conn);
|
1096
|
+
|
1097
|
+
switch (state) {
|
1098
|
+
case TCCLOSED:
|
1099
|
+
conn.state = SIGAR_TCP_CLOSE;
|
1100
|
+
break;
|
1101
|
+
case TCLISTEN:
|
1102
|
+
conn.state = SIGAR_TCP_LISTEN;
|
1103
|
+
break;
|
1104
|
+
case TCSYNSENT:
|
1105
|
+
conn.state = SIGAR_TCP_SYN_SENT;
|
1106
|
+
break;
|
1107
|
+
case TCSYNRECEIVE:
|
1108
|
+
conn.state = SIGAR_TCP_SYN_RECV;
|
1109
|
+
break;
|
1110
|
+
case TCESTABLISED:
|
1111
|
+
conn.state = SIGAR_TCP_ESTABLISHED;
|
1112
|
+
break;
|
1113
|
+
case TCFINWAIT1:
|
1114
|
+
conn.state = SIGAR_TCP_FIN_WAIT1;
|
1115
|
+
break;
|
1116
|
+
case TCFINWAIT2:
|
1117
|
+
conn.state = SIGAR_TCP_FIN_WAIT2;
|
1118
|
+
break;
|
1119
|
+
case TCCLOSEWAIT:
|
1120
|
+
conn.state = SIGAR_TCP_CLOSE_WAIT;
|
1121
|
+
break;
|
1122
|
+
case TCCLOSING:
|
1123
|
+
conn.state = SIGAR_TCP_CLOSING;
|
1124
|
+
break;
|
1125
|
+
case TCLASTACK:
|
1126
|
+
conn.state = SIGAR_TCP_LAST_ACK;
|
1127
|
+
break;
|
1128
|
+
case TCTIMEWAIT:
|
1129
|
+
conn.state = SIGAR_TCP_TIME_WAIT;
|
1130
|
+
break;
|
1131
|
+
case TCDELETETCB:
|
1132
|
+
default:
|
1133
|
+
conn.state = SIGAR_TCP_UNKNOWN;
|
1134
|
+
break;
|
1135
|
+
}
|
1136
|
+
|
1137
|
+
conn.local_port = (unsigned short)entry->LocalPort;
|
1138
|
+
conn.remote_port = (unsigned short)entry->RemPort;
|
1139
|
+
conn.type = SIGAR_NETCONN_TCP;
|
1140
|
+
|
1141
|
+
sigar_net_address_set(conn.local_address, entry->LocalAddress);
|
1142
|
+
sigar_net_address_set(conn.remote_address, entry->RemAddress);
|
1143
|
+
|
1144
|
+
conn.send_queue = conn.receive_queue = SIGAR_FIELD_NOTIMPL;
|
1145
|
+
|
1146
|
+
if (walker->add_connection(walker, &conn) != SIGAR_OK) {
|
1147
|
+
break;
|
1148
|
+
}
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
free(entries);
|
1152
|
+
|
1153
|
+
return SIGAR_OK;
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
int sigar_net_connection_walk(sigar_net_connection_walker_t *walker)
|
1157
|
+
{
|
1158
|
+
int status;
|
1159
|
+
|
1160
|
+
if (walker->flags & SIGAR_NETCONN_TCP) {
|
1161
|
+
status = net_conn_get_tcp(walker);
|
1162
|
+
|
1163
|
+
if (status != SIGAR_OK) {
|
1164
|
+
return status;
|
1165
|
+
}
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
if (walker->flags & SIGAR_NETCONN_UDP) {
|
1169
|
+
status = net_conn_get_udp(walker);
|
1170
|
+
|
1171
|
+
if (status != SIGAR_OK) {
|
1172
|
+
return status;
|
1173
|
+
}
|
1174
|
+
}
|
1175
|
+
|
1176
|
+
return SIGAR_OK;
|
1177
|
+
}
|
1178
|
+
|
1179
|
+
#define tcpsoff(x) sigar_offsetof(sigar_tcp_t, x)
|
1180
|
+
|
1181
|
+
static struct {
|
1182
|
+
unsigned int id;
|
1183
|
+
size_t offset;
|
1184
|
+
} tcps_lu[] = {
|
1185
|
+
#if 0
|
1186
|
+
{ ID_tcpRtoAlgorithm, tcpsoff(xxx) },
|
1187
|
+
{ ID_tcpRtoMin, tcpsoff(xxx) },
|
1188
|
+
{ ID_tcpRtoMax, tcpsoff(xxx) },
|
1189
|
+
{ ID_tcpMaxConn, tcpsoff(max_conn) },
|
1190
|
+
#endif
|
1191
|
+
{ ID_tcpActiveOpens, tcpsoff(active_opens) },
|
1192
|
+
{ ID_tcpPassiveOpens, tcpsoff(passive_opens) },
|
1193
|
+
{ ID_tcpAttemptFails, tcpsoff(attempt_fails) },
|
1194
|
+
{ ID_tcpEstabResets, tcpsoff(estab_resets) },
|
1195
|
+
{ ID_tcpCurrEstab, tcpsoff(curr_estab) },
|
1196
|
+
{ ID_tcpInSegs, tcpsoff(in_segs) },
|
1197
|
+
{ ID_tcpOutSegs, tcpsoff(out_segs) },
|
1198
|
+
{ ID_tcpRetransSegs, tcpsoff(retrans_segs) },
|
1199
|
+
{ ID_tcpInErrs, tcpsoff(in_errs) },
|
1200
|
+
{ ID_tcpOutRsts, tcpsoff(out_rsts) }
|
1201
|
+
};
|
1202
|
+
|
1203
|
+
SIGAR_DECLARE(int)
|
1204
|
+
sigar_tcp_get(sigar_t *sigar,
|
1205
|
+
sigar_tcp_t *tcp)
|
1206
|
+
{
|
1207
|
+
int i;
|
1208
|
+
|
1209
|
+
for (i=0; i<sizeof(tcps_lu)/sizeof(tcps_lu[0]); i++) {
|
1210
|
+
struct nmparms parms;
|
1211
|
+
int val;
|
1212
|
+
unsigned int len = sizeof(val);
|
1213
|
+
parms.objid = tcps_lu[i].id;
|
1214
|
+
parms.buffer = &val;
|
1215
|
+
parms.len = &len;
|
1216
|
+
|
1217
|
+
if (sigar_get_mib_info(sigar, &parms) != SIGAR_OK) {
|
1218
|
+
val = -1;
|
1219
|
+
}
|
1220
|
+
|
1221
|
+
*(sigar_uint64_t *)((char *)tcp + tcps_lu[i].offset) = val;
|
1222
|
+
}
|
1223
|
+
|
1224
|
+
return SIGAR_OK;
|
1225
|
+
}
|
1226
|
+
|
1227
|
+
int sigar_nfs_client_v2_get(sigar_t *sigar,
|
1228
|
+
sigar_nfs_client_v2_t *nfs)
|
1229
|
+
{
|
1230
|
+
return SIGAR_ENOTIMPL;
|
1231
|
+
}
|
1232
|
+
|
1233
|
+
int sigar_nfs_server_v2_get(sigar_t *sigar,
|
1234
|
+
sigar_nfs_server_v2_t *nfs)
|
1235
|
+
{
|
1236
|
+
return SIGAR_ENOTIMPL;
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
int sigar_nfs_client_v3_get(sigar_t *sigar,
|
1240
|
+
sigar_nfs_client_v3_t *nfs)
|
1241
|
+
{
|
1242
|
+
return SIGAR_ENOTIMPL;
|
1243
|
+
}
|
1244
|
+
|
1245
|
+
int sigar_nfs_server_v3_get(sigar_t *sigar,
|
1246
|
+
sigar_nfs_server_v3_t *nfs)
|
1247
|
+
{
|
1248
|
+
return SIGAR_ENOTIMPL;
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
int sigar_arp_list_get(sigar_t *sigar,
|
1252
|
+
sigar_arp_list_t *arplist)
|
1253
|
+
{
|
1254
|
+
int status, count, i;
|
1255
|
+
unsigned int len;
|
1256
|
+
struct nmparms parms;
|
1257
|
+
mib_ipNetToMediaEnt *entries;
|
1258
|
+
sigar_arp_t *arp;
|
1259
|
+
|
1260
|
+
len = sizeof(count);
|
1261
|
+
parms.objid = ID_ipNetToMediaTableNum;
|
1262
|
+
parms.buffer = &count;
|
1263
|
+
parms.len = &len;
|
1264
|
+
|
1265
|
+
if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
|
1266
|
+
return status;
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
len = count * sizeof(*entries);
|
1270
|
+
entries = malloc(len);
|
1271
|
+
|
1272
|
+
parms.objid = ID_ipNetToMediaTable;
|
1273
|
+
parms.buffer = entries;
|
1274
|
+
parms.len = &len;
|
1275
|
+
|
1276
|
+
if ((status = sigar_get_mib_info(sigar, &parms)) != SIGAR_OK) {
|
1277
|
+
free(entries);
|
1278
|
+
return status;
|
1279
|
+
}
|
1280
|
+
|
1281
|
+
sigar_arp_list_create(arplist);
|
1282
|
+
|
1283
|
+
for (i=0; i<count; i++) {
|
1284
|
+
mib_ipNetToMediaEnt *ent = &entries[i];
|
1285
|
+
|
1286
|
+
SIGAR_ARP_LIST_GROW(arplist);
|
1287
|
+
|
1288
|
+
arp = &arplist->data[arplist->number++];
|
1289
|
+
|
1290
|
+
sigar_net_address_set(arp->address,
|
1291
|
+
ent->NetAddr);
|
1292
|
+
|
1293
|
+
sigar_net_address_mac_set(arp->hwaddr,
|
1294
|
+
ent->PhysAddr.o_bytes,
|
1295
|
+
ent->PhysAddr.o_length);
|
1296
|
+
|
1297
|
+
sigar_if_indextoname(sigar, arp->ifname, ent->IfIndex);
|
1298
|
+
|
1299
|
+
SIGAR_SSTRCPY(arp->type, "ether"); /*XXX*/
|
1300
|
+
arp->flags = 0; /*XXX*/
|
1301
|
+
}
|
1302
|
+
|
1303
|
+
free(entries);
|
1304
|
+
|
1305
|
+
return SIGAR_OK;
|
1306
|
+
}
|
1307
|
+
|
1308
|
+
int sigar_proc_port_get(sigar_t *sigar, int protocol,
|
1309
|
+
unsigned long port, sigar_pid_t *pid)
|
1310
|
+
{
|
1311
|
+
return SIGAR_ENOTIMPL;
|
1312
|
+
}
|
1313
|
+
|
1314
|
+
|
1315
|
+
int sigar_os_sys_info_get(sigar_t *sigar,
|
1316
|
+
sigar_sys_info_t *sysinfo)
|
1317
|
+
{
|
1318
|
+
char *vendor_version, *arch;
|
1319
|
+
long cpu = sysconf(_SC_CPU_VERSION);
|
1320
|
+
|
1321
|
+
switch (cpu) {
|
1322
|
+
case CPU_PA_RISC1_0:
|
1323
|
+
arch = "PA_RISC1.0";
|
1324
|
+
break;
|
1325
|
+
case CPU_PA_RISC1_1:
|
1326
|
+
arch = "PA_RISC1.1";
|
1327
|
+
break;
|
1328
|
+
case CPU_PA_RISC2_0:
|
1329
|
+
arch = "PA_RISC2.0";
|
1330
|
+
break;
|
1331
|
+
#ifdef CPU_IA64_ARCHREV_0
|
1332
|
+
case CPU_IA64_ARCHREV_0:
|
1333
|
+
arch = "ia64";
|
1334
|
+
break;
|
1335
|
+
#endif
|
1336
|
+
default:
|
1337
|
+
arch = "unknown";
|
1338
|
+
break;
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
SIGAR_SSTRCPY(sysinfo->arch, arch);
|
1342
|
+
|
1343
|
+
SIGAR_SSTRCPY(sysinfo->name, "HPUX");
|
1344
|
+
SIGAR_SSTRCPY(sysinfo->vendor, "Hewlett-Packard");
|
1345
|
+
|
1346
|
+
if (strstr(sysinfo->version, ".11.")) {
|
1347
|
+
vendor_version = "11";
|
1348
|
+
}
|
1349
|
+
else {
|
1350
|
+
vendor_version = sysinfo->version;
|
1351
|
+
}
|
1352
|
+
|
1353
|
+
SIGAR_SSTRCPY(sysinfo->vendor_version, vendor_version);
|
1354
|
+
|
1355
|
+
snprintf(sysinfo->description,
|
1356
|
+
sizeof(sysinfo->description),
|
1357
|
+
"%s %s",
|
1358
|
+
sysinfo->vendor_name, sysinfo->vendor_version);
|
1359
|
+
|
1360
|
+
return SIGAR_OK;
|
1361
|
+
}
|