PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/debs/ganglia/ganglia-3.1.2/libmetrics/hpux/metrics.c

https://github.com/ChuguluGames/mediawiki-svn
C | 910 lines | 658 code | 123 blank | 129 comment | 86 complexity | 42f2c9c34e6dc502d7d2f77f075a366e MD5 | raw file
  1. /*
  2. * hpux.c - Ganglia monitor core gmond module for HP-UX
  3. *
  4. * Change log:
  5. *
  6. * 15oct2002 - Martin Knoblauch <martin.knoblauch@mscsoftware.com>
  7. * Original version.
  8. *
  9. * 04nov2002 - Jack Perdue <j-perdue@tamu.edu>
  10. * Filled in some empty metrics. Stole MTU code from linux.c.
  11. * Replaced Martin's cpu_user/idle/sys/etc_func's with something
  12. * a little cleaner. Tried to put error checking on all system calls.
  13. *
  14. * 18nov2002 - Martin Knoblauch <martin.knoblauch@mscsoftware.com>
  15. * - Put back removal of system processes in proc_run_func()
  16. * - Add cpu_intr_func, cpu_wait_func, cpu_ssys_func
  17. *
  18. * 27nov2002 - Martin Knoblauch <martin.knoblauch@mscsoftware.com>
  19. * - Add mem_arm, mem_rm, mem_avm, mem_vm
  20. * - Add standalone test
  21. *
  22. * 26may2004 - Martin Knoblauch <martin.knoblauch@mscsoftware.com>
  23. * - Rename cpu_wait to cpu_wio for Linux/Solaris compatibility
  24. * - Rename cpu_ssys to cpu_sintr for Linux compatibility
  25. * - Remove WAIT from SYSTEM category
  26. *
  27. * Notes:
  28. *
  29. * - requires use of -D_PSTAT64 on 64-bit (wide) HP-UX 11.0... building
  30. * the core also requires -lpthreads but configure doesn't seem to pick
  31. * it up, so you will probably want something like:
  32. *
  33. * env CFLAGS=-D_PSTAT64 LDFLAGS=-lpthread ./configure --prefix=/opt/ganglia
  34. *
  35. * on wide HP-UX and the same line without the CFLAGS for narrow HP-UX.
  36. *
  37. * - don't know if it will work on HP-UX 10.20... it definitely will
  38. * NOT work on versions of HP-UX before that
  39. *
  40. * #defines:
  41. *
  42. * MOREPOSSIBLE:
  43. * Wraps some interesting new metrics.
  44. * SIMPLE_SYS:
  45. * If defined, only account CP_SYS, otherwise account anything that
  46. * does not fall into user/nice/idle
  47. * SIMPLE_SYSPROC:
  48. * If defined, count all processes in "R" state for proc_run_func(). Otherwise
  49. * remove "system/kelrnel" processes.
  50. *
  51. * To do:
  52. *
  53. * - mem_buffers_func()
  54. * - verify mem_cached_func() makes sense
  55. * - decide if memory swap shold be counted
  56. */
  57. #include <time.h>
  58. #include <unistd.h>
  59. #include <sys/dk.h>
  60. #include <sys/pstat.h>
  61. #include <sys/utsname.h>
  62. #include "libmetrics.h"
  63. #include "interface.h"
  64. /* buffer and keep global some info */
  65. struct pst_static staticinfo;
  66. int cpu_num_func_cpu_num = 0;
  67. long clk_ticks;
  68. g_val_t cpu_func( int ); /* prototype to make metric_init() happy */
  69. /*
  70. * This function is called only once by the gmond. Use to
  71. * initialize data structures, etc or just return SYNAPSE_SUCCESS;
  72. */
  73. g_val_t
  74. metric_init( void )
  75. {
  76. g_val_t rval;
  77. struct pst_dynamic p;
  78. if( -1 == pstat_getstatic( &staticinfo, sizeof(struct pst_static), 1, 0))
  79. {
  80. err_ret("metric_init() got an error from pstat_getstatic()");
  81. rval.int32 = SYNAPSE_FAILURE;
  82. }
  83. else if( -1 == (clk_ticks = sysconf(_SC_CLK_TCK)))
  84. {
  85. err_ret("metric_init() got an error from sysconf()");
  86. rval.int32 = SYNAPSE_FAILURE;
  87. }
  88. /* get num cpus now because things depend on it */
  89. else if( -1 == pstat_getdynamic( &p, sizeof(struct pst_dynamic), 1, 0))
  90. {
  91. err_ret("metric_init() got an error from pstat_getdynamic()");
  92. cpu_num_func_cpu_num = 1; /* if we wanted something */
  93. rval.int32 = SYNAPSE_FAILURE; /* but we don't */
  94. }
  95. else
  96. {
  97. cpu_num_func_cpu_num = p.psd_max_proc_cnt;
  98. rval.int32 = SYNAPSE_SUCCESS;
  99. }
  100. cpu_func(-1); /* initialize first set of counts */
  101. sleep(5); /* wait a little bit */
  102. cpu_func(-1); /* initialze second set of counts */
  103. return rval;
  104. }
  105. g_val_t
  106. boottime_func ( void )
  107. {
  108. g_val_t val;
  109. val.uint32 = staticinfo.boot_time;
  110. return val;
  111. }
  112. g_val_t
  113. cpu_num_func ( void )
  114. {
  115. g_val_t val;
  116. val.uint16 = cpu_num_func_cpu_num;
  117. return val;
  118. }
  119. g_val_t
  120. cpu_speed_func ( void )
  121. {
  122. g_val_t val;
  123. struct pst_processor p;
  124. /* assume all CPUs the same speed as the first one (reasonable?) */
  125. if ( -1 != pstat_getprocessor(&p, sizeof(struct pst_processor), 1, 0))
  126. val.uint32 = (p.psp_iticksperclktick*clk_ticks/1000000);
  127. else
  128. {
  129. err_ret("cpu_speed_func() got an error from pstat_getprocessor()");
  130. val.uint32 = 0;
  131. }
  132. return val;
  133. }
  134. g_val_t
  135. sys_clock_func ( void )
  136. {
  137. g_val_t val;
  138. val.uint32 = time(NULL);
  139. return val;
  140. }
  141. g_val_t
  142. machine_type_func ( void )
  143. {
  144. g_val_t val;
  145. struct utsname uts;
  146. if( -1 == uname(&uts))
  147. {
  148. err_ret("machine_type_func() got an error from uname()");
  149. strncpy( val.str, "unknown", MAX_G_STRING_SIZE);
  150. }
  151. else
  152. strncpy( val.str, uts.machine , MAX_G_STRING_SIZE );
  153. return val;
  154. }
  155. g_val_t
  156. os_name_func ( void )
  157. {
  158. g_val_t val;
  159. struct utsname uts;
  160. if( -1 == uname(&uts))
  161. {
  162. err_ret("os_name_func() got an error from uname()");
  163. strncpy( val.str, "HP-UX", MAX_G_STRING_SIZE);
  164. }
  165. else
  166. strncpy( val.str, uts.sysname , MAX_G_STRING_SIZE );
  167. return val;
  168. }
  169. g_val_t
  170. os_release_func ( void )
  171. {
  172. g_val_t val;
  173. struct utsname uts;
  174. if( -1 == uname(&uts))
  175. {
  176. err_ret("os_release_func() got an error from uname()");
  177. strncpy( val.str, "unknown", MAX_G_STRING_SIZE);
  178. }
  179. else
  180. {
  181. strncpy( val.str, uts.release , MAX_G_STRING_SIZE );
  182. strcat ( val.str, "-");
  183. strncat( val.str, uts.version, MAX_G_STRING_SIZE );
  184. }
  185. return val;
  186. }
  187. /*
  188. * A helper function to return the total number of cpu timespent
  189. */
  190. unsigned long
  191. #if !defined(_PSTAT64)
  192. total_timespent_func ( uint32_t totals[])
  193. #else
  194. total_timespent_func ( uint64_t totals[])
  195. #endif
  196. {
  197. int i,j;
  198. struct pst_processor p;
  199. #if !defined(_PSTAT64)
  200. uint32_t total_timespent = 0;
  201. #else
  202. uint64_t total_timespent = 0L;
  203. #endif
  204. for( j = 0; j < CPUSTATES; j++)
  205. totals[j] = 0;
  206. for( i = 0; i < cpu_num_func_cpu_num; i++)
  207. {
  208. if( -1 == pstat_getprocessor( &p, sizeof(struct pst_processor), 1, i))
  209. {
  210. err_ret("total_timespent_func() got an error from pstat_getprocessor()");
  211. return 0;
  212. }
  213. for( j = 0; j < CPUSTATES; j++)
  214. totals[j] += p.psp_cpu_time[j];
  215. }
  216. for( j = 0; j < CPUSTATES; j++)
  217. {
  218. total_timespent += totals[j];
  219. }
  220. return total_timespent;
  221. }
  222. #define CPU_THRESHOLD 60 /* how many seconds between collecting stats */
  223. g_val_t
  224. cpu_func ( int which ) /* see <sys/dk.h> for which... -1 means initialize counts */
  225. {
  226. g_val_t val;
  227. int j, alltime=0;
  228. time_t stamp;
  229. static time_t laststamp = 0;
  230. double diff;
  231. #if !defined(_PSTAT64)
  232. static uint32_t total_timespent, last_total_timespent,
  233. timespent[CPUSTATES], last_timespent[CPUSTATES];
  234. #else
  235. static uint64_t total_timespent, last_total_timespent,
  236. timespent[CPUSTATES], last_timespent[CPUSTATES];
  237. #endif
  238. if( which >= CPUSTATES)
  239. {
  240. alltime = 1; /* stats since boot (???) */
  241. which -= CPUSTATES;
  242. }
  243. stamp = time(NULL);
  244. /* don't call total_timespent_func() too often */
  245. if( stamp - CPU_THRESHOLD > laststamp || which < 0)
  246. {
  247. laststamp = stamp;
  248. last_total_timespent = total_timespent;
  249. for( j = 0; j < CPUSTATES; j++)
  250. last_timespent[j] = timespent[j];
  251. total_timespent = total_timespent_func(timespent);
  252. }
  253. val.f = 0.0;
  254. if( which >= 0)
  255. {
  256. if( alltime) /* percentage since systems has been up (???) */
  257. {
  258. if( total_timespent != 0)
  259. val.f = (timespent[which]*100.0)/total_timespent;
  260. }
  261. else /* percentage in last time slice */
  262. {
  263. diff = total_timespent - last_total_timespent;
  264. if( diff != 0.0)
  265. val.f = ((timespent[which] - last_timespent[which])/diff)*100;
  266. else
  267. debug_msg("cpu_func() - no difference in total_timespent %ld %ld",
  268. (unsigned long) total_timespent, (unsigned long) last_total_timespent);
  269. }
  270. }
  271. if( val.f < 0.0) val.f = 0; /* catch counter wraps (rare, not very necessary) */
  272. return val;
  273. }
  274. g_val_t
  275. cpu_user_func ( void )
  276. {
  277. return cpu_func(CP_USER);
  278. }
  279. g_val_t
  280. cpu_nice_func ( void )
  281. {
  282. return cpu_func(CP_NICE);
  283. }
  284. g_val_t
  285. cpu_system_func ( void )
  286. {
  287. #ifdef SIMPLE_SYS
  288. return cpu_func(CP_SYS);
  289. #else /* use Martin's definition of everything else */
  290. g_val_t val, tval;
  291. #define NUM_SYSSTATES 5
  292. /*
  293. * Add CP_INTR, CP_SSYS to system time to satisfy the ganglia web-frontend.
  294. * CP_BLOCK and CP_SWAIT are supposed to be obsolete, but I just want to be sure :-)
  295. */
  296. int i, sysstates[NUM_SYSSTATES] = { CP_SYS, CP_BLOCK, CP_SWAIT, CP_INTR, CP_SSYS };
  297. val.f = 0.0;
  298. for( i = 0; i < NUM_SYSSTATES; ++i)
  299. {
  300. tval = cpu_func(sysstates[i]);
  301. val.f += tval.f;
  302. }
  303. return val;
  304. #endif
  305. }
  306. g_val_t
  307. cpu_idle_func ( void )
  308. {
  309. return cpu_func(CP_IDLE);
  310. }
  311. /*
  312. * Time spent processing interrupts
  313. */
  314. g_val_t
  315. cpu_intr_func ( void )
  316. {
  317. return cpu_func(CP_INTR);
  318. }
  319. /*
  320. * Time spent waiting
  321. */
  322. g_val_t
  323. cpu_wio_func ( void )
  324. {
  325. return cpu_func(CP_WAIT);
  326. }
  327. /*
  328. * Time in kernel mode
  329. */
  330. g_val_t
  331. cpu_sintr_func ( void )
  332. {
  333. return cpu_func(CP_SSYS);
  334. }
  335. /*
  336. * FIXME?
  337. */
  338. g_val_t
  339. cpu_aidle_func ( void )
  340. {
  341. return cpu_func(CP_IDLE + CPUSTATES);
  342. }
  343. /*
  344. ** FIXME
  345. */
  346. g_val_t
  347. bytes_in_func ( void )
  348. {
  349. g_val_t val;
  350. val.f = 0.0;
  351. return val;
  352. }
  353. /*
  354. ** FIXME
  355. */
  356. g_val_t
  357. bytes_out_func ( void )
  358. {
  359. g_val_t val;
  360. val.f = 0.0;
  361. return val;
  362. }
  363. /*
  364. ** FIXME
  365. */
  366. g_val_t
  367. pkts_in_func ( void )
  368. {
  369. g_val_t val;
  370. val.f = 0.0;
  371. return val;
  372. }
  373. /*
  374. ** FIXME
  375. */
  376. g_val_t
  377. pkts_out_func ( void )
  378. {
  379. g_val_t val;
  380. val.f = 0.0;
  381. return val;
  382. }
  383. /*
  384. ** FIXME
  385. */
  386. g_val_t
  387. disk_free_func ( void )
  388. {
  389. g_val_t val;
  390. val.d = 0;
  391. return val;
  392. }
  393. /*
  394. ** FIXME
  395. */
  396. g_val_t
  397. disk_total_func ( void )
  398. {
  399. g_val_t val;
  400. val.d = 0;
  401. return val;
  402. }
  403. /*
  404. ** FIXME
  405. */
  406. g_val_t
  407. part_max_used_func ( void )
  408. {
  409. g_val_t val;
  410. val.f = 0.0;
  411. return val;
  412. }
  413. #ifdef MOREPOSSIBLE
  414. g_val_t
  415. cpu_auser_func ( uint32_t i )
  416. {
  417. return cpu_func(CP_USER + CPUSTATES);
  418. }
  419. g_val_t
  420. cpu_anice_func ( uint32_t i )
  421. {
  422. return cpu_func(CP_NICE + CPUSTATES);
  423. }
  424. g_val_t
  425. cpu_asys_func ( uint32_t i )
  426. {
  427. return cpu_func(CP_SYS + CPUSTATES);
  428. }
  429. #endif
  430. enum {LOAD_1, LOAD_5, LOAD_15};
  431. g_val_t
  432. load_func ( int which)
  433. {
  434. g_val_t val;
  435. struct pst_dynamic p;
  436. val.f = 0.0;
  437. if( -1 == pstat_getdynamic( &p, sizeof(struct pst_dynamic), 1, 0))
  438. {
  439. err_ret("load_func() got an error from pstat_getdynamic()");
  440. }
  441. else
  442. switch(which)
  443. {
  444. case LOAD_1: val.f = cpu_num_func_cpu_num * p.psd_avg_1_min; break;
  445. case LOAD_5: val.f = cpu_num_func_cpu_num * p.psd_avg_5_min; break;
  446. case LOAD_15: val.f = cpu_num_func_cpu_num * p.psd_avg_15_min; break;
  447. default:
  448. err_sys("load_func() - invalid value for which = %d", which);
  449. }
  450. return val;
  451. }
  452. g_val_t
  453. load_one_func ( void )
  454. {
  455. return load_func(LOAD_1);
  456. }
  457. g_val_t
  458. load_five_func ( void )
  459. {
  460. return load_func(LOAD_5);
  461. }
  462. g_val_t
  463. load_fifteen_func ( void )
  464. {
  465. return load_func(LOAD_15);
  466. }
  467. /* NOTE: setting this to 80 or above screws everything up on 64-bit (wide) HP-UX...
  468. I don't know why. - jkp
  469. */
  470. #define PROC_BUFFERSIZE 50
  471. g_val_t
  472. proc_func( int pstate )
  473. {
  474. g_val_t val;
  475. int i, got, cruft=0, index = 0;
  476. struct pst_status p[PROC_BUFFERSIZE];
  477. val.uint32 = 0;
  478. do {
  479. got = pstat_getproc( p, sizeof(struct pst_status), PROC_BUFFERSIZE, index);
  480. if( -1 == got)
  481. {
  482. err_ret("proc_func() got an error from pstat_getproc(%d) - got:%d",index, got);
  483. val.uint32 = 0;
  484. return val;
  485. }
  486. if( !pstate)
  487. val.uint32 += got; /* total */
  488. else
  489. for( i = 0; i < got; i++)
  490. {
  491. #if !defined(SIMPLE_SYSPROC)
  492. /*
  493. * Compute "system cruft" for PS_RUN case, MKN
  494. */
  495. if ((p[i].pst_stat == PS_RUN) && /* Process in Run state */
  496. ((p[i].pst_ppid == 0) || /* Owned by Kernel */
  497. ((p[i].pst_ppid == 1) && (p[i].pst_uid == 0)))) /* or owned by init, uid=0 */
  498. cruft++;
  499. #endif
  500. if(pstate == p[i].pst_stat) /* total by state */
  501. {
  502. ++val.uint32;
  503. }
  504. }
  505. if ( got) /* make sure we actually got something (we might have got 0) */
  506. index = p[got-1].pst_idx + 1;
  507. } while( got == PROC_BUFFERSIZE);
  508. #if !defined(SIMPLE_SYSPROC)
  509. if ( pstate == PS_RUN ) val.uint32 -= cruft;
  510. #endif
  511. return val;
  512. }
  513. g_val_t
  514. proc_run_func( void )
  515. {
  516. return proc_func(PS_RUN);
  517. }
  518. g_val_t
  519. proc_total_func ( void )
  520. {
  521. return proc_func(0);
  522. }
  523. #ifdef MOREPOSSIBLE
  524. g_val_t
  525. proc_sleep_func( void )
  526. {
  527. return proc_func(PS_SLEEP);
  528. }
  529. g_val_t
  530. proc_stop_func( void )
  531. {
  532. return proc_func(PS_STOP);
  533. }
  534. #endif
  535. g_val_t
  536. mem_total_func ( void )
  537. {
  538. g_val_t val;
  539. /* assumes page size is a multiple of 1024 */
  540. val.f = staticinfo.physical_memory * (staticinfo.page_size / 1024);
  541. return val;
  542. }
  543. g_val_t
  544. mem_free_func ( void )
  545. {
  546. g_val_t val;
  547. struct pst_dynamic p;
  548. if( -1 == pstat_getdynamic( &p, sizeof(struct pst_dynamic), 1, 0))
  549. {
  550. err_ret("mem_free_func() got an error from pstat_getdynamic()");
  551. val.f = 0;
  552. }
  553. else
  554. {
  555. /* assumes page size is a multiple of 1024 */
  556. val.f = p.psd_free * (staticinfo.page_size / 1024);
  557. }
  558. return val;
  559. }
  560. g_val_t
  561. mem_rm_func ( void )
  562. {
  563. g_val_t val;
  564. struct pst_dynamic p;
  565. if( -1 == pstat_getdynamic( &p, sizeof(struct pst_dynamic), 1, 0))
  566. {
  567. err_ret("mem_rm_func() got an error from pstat_getdynamic()");
  568. val.f = 0;
  569. }
  570. else
  571. {
  572. /* assumes page size is a multiple of 1024 */
  573. val.f = p.psd_rm * (staticinfo.page_size / 1024);
  574. }
  575. return val;
  576. }
  577. g_val_t
  578. mem_arm_func ( void )
  579. {
  580. g_val_t val;
  581. struct pst_dynamic p;
  582. if( -1 == pstat_getdynamic( &p, sizeof(struct pst_dynamic), 1, 0))
  583. {
  584. err_ret("mem_arm_func() got an error from pstat_getdynamic()");
  585. val.f = 0;
  586. }
  587. else
  588. {
  589. /* assumes page size is a multiple of 1024 */
  590. val.f = p.psd_arm * (staticinfo.page_size / 1024);
  591. }
  592. return val;
  593. }
  594. g_val_t
  595. mem_vm_func ( void )
  596. {
  597. g_val_t val;
  598. struct pst_dynamic p;
  599. if( -1 == pstat_getdynamic( &p, sizeof(struct pst_dynamic), 1, 0))
  600. {
  601. err_ret("mem_vm_func() got an error from pstat_getdynamic()");
  602. val.f = 0;
  603. }
  604. else
  605. {
  606. /* assumes page size is a multiple of 1024 */
  607. val.f = p.psd_vm * (staticinfo.page_size / 1024);
  608. }
  609. return val;
  610. }
  611. g_val_t
  612. mem_avm_func ( void )
  613. {
  614. g_val_t val;
  615. struct pst_dynamic p;
  616. if( -1 == pstat_getdynamic( &p, sizeof(struct pst_dynamic), 1, 0))
  617. {
  618. err_ret("mem_avm_func() got an error from pstat_getdynamic()");
  619. val.f = 0;
  620. }
  621. else
  622. {
  623. /* assumes page size is a multiple of 1024 */
  624. val.f = p.psd_avm * (staticinfo.page_size / 1024);
  625. }
  626. return val;
  627. }
  628. #define SHMEM_BUFFERSIZE 16
  629. g_val_t
  630. mem_shared_func ( void )
  631. {
  632. g_val_t val;
  633. int i, got, index = 0;
  634. struct pst_shminfo p[SHMEM_BUFFERSIZE];
  635. val.f = 0;
  636. do {
  637. if( -1 == ( got = pstat_getshm(p,sizeof(struct pst_shminfo), SHMEM_BUFFERSIZE, index)))
  638. {
  639. err_ret("mem_shared_func() got an error from pstat_getshm()");
  640. return val;
  641. }
  642. for( i = 0; i < got; i++)
  643. {
  644. val.f += p[i].psh_segsz; /* size in bytes */
  645. }
  646. if( got) /* make sure we actually got something (we might have got 0) */
  647. index = p[got-1].psh_idx + 1;
  648. } while ( got == SHMEM_BUFFERSIZE);
  649. val.f /= 1024; /* KB */
  650. return val;
  651. }
  652. g_val_t
  653. mem_buffers_func ( void )
  654. {
  655. g_val_t val;
  656. /* FIXME HPUX */
  657. val.f = 0;
  658. return val;
  659. }
  660. g_val_t
  661. mem_cached_func ( void )
  662. {
  663. g_val_t val;
  664. struct pst_dynamic p;
  665. if ( -1 == pstat_getdynamic(&p, sizeof(struct pst_dynamic), (size_t)1, 0))
  666. {
  667. err_ret("mem_cached_func() got an error from pstat_getdynamic()");
  668. val.f = 0;
  669. }
  670. else
  671. {
  672. /* This was Martin Knoblauch's solution... don't know about correctness - JKP */
  673. /* assumes page size is a multiple of 1024 */
  674. val.f = (staticinfo.physical_memory - p.psd_free - p.psd_rm) * (staticinfo.page_size / 1024);
  675. }
  676. return val;
  677. }
  678. enum {SWAP_FREE, SWAP_TOTAL};
  679. #define THELONGWAY
  680. #ifdef THELONGWAY
  681. /* this way may provide more metrics on swap usage in the future (???) */
  682. #define SWAP_BUFFERSIZE 8
  683. g_val_t
  684. swap_func( int which)
  685. {
  686. g_val_t val;
  687. int i, got, kpp, index = 0;
  688. struct pst_swapinfo p[SWAP_BUFFERSIZE];
  689. /* assumes page size is a multiple of 1024 */
  690. kpp = staticinfo.page_size / 1024;
  691. val.f = 0;
  692. do {
  693. if( -1 == ( got = pstat_getswap(p,sizeof(struct pst_swapinfo), SWAP_BUFFERSIZE, index)))
  694. {
  695. err_ret("swap_func() got an error from pstat_getswap()");
  696. return val;
  697. }
  698. for( i = 0; i < got; i++)
  699. {
  700. if( p[i].pss_flags & SW_ENABLED)
  701. {
  702. switch( which)
  703. {
  704. case SWAP_FREE:
  705. val.f += p[i].pss_nfpgs * kpp;
  706. break;
  707. case SWAP_TOTAL:
  708. if( p[i].pss_flags & SW_BLOCK)
  709. val.f += p[i].pss_nblksenabled /* * p[i].pss_swapchunk / 1024) */;
  710. else if( p[i].pss_flags & SW_FS)
  711. /* THIS IS A GUESS AND HAS NOT BEEN TESTED */
  712. val.f += p[i].pss_allocated * p[i].pss_swapchunk / 1024;
  713. else
  714. {
  715. err_msg("swap_func() - unknow swap type - pss_flags=0x%x", p[i].pss_flags);
  716. }
  717. break;
  718. default:
  719. err_sys("swap_func() - invalid value for which = %d", which);
  720. }
  721. }
  722. }
  723. if( got) /* make sure we actually got something (we might have got 0) */
  724. index = p[got-1].pss_idx + 1;
  725. } while ( got == SWAP_BUFFERSIZE);
  726. return val;
  727. }
  728. #else /* the short way */
  729. /* #define SWAP_COUNTMEM to include memory reserved if swap fills up */
  730. g_val_t
  731. swap_func( int which)
  732. {
  733. g_val_t val;
  734. struct pst_vminfo p;
  735. val.f = 0;
  736. if ( -1 == pstat_getvminfo(&p, sizeof(struct pst_vminfo), 1, 0))
  737. {
  738. err_ret("swap_func() got an error from pstat_getswap()");
  739. }
  740. else
  741. {
  742. switch( which)
  743. {
  744. case SWAP_FREE:
  745. /* assumes page size is a multiple of 1024 */
  746. val.f = p.psv_swapspc_cnt;
  747. #ifdef SWAP_COUNTMEM
  748. val.f += p.psv_swapmem_cnt;
  749. #endif
  750. val.f *= (staticinfo.page_size / 1024);
  751. break;
  752. case SWAP_TOTAL:
  753. /* assumes page size is a multiple of 1024 */
  754. val.f = p.psv_swapspc_max;
  755. #ifdef SWAP_COUNTMEM
  756. val.f += p.psv_swapmem_max;
  757. #endif
  758. val.f *= (staticinfo.page_size / 1024);
  759. break;
  760. default:
  761. err_sys("swap_func() - invalid value for which = %d", which);
  762. }
  763. }
  764. return val;
  765. }
  766. #endif
  767. g_val_t
  768. swap_free_func ( void )
  769. {
  770. return swap_func(SWAP_FREE);
  771. }
  772. g_val_t
  773. swap_total_func ( void )
  774. {
  775. return swap_func(SWAP_TOTAL);
  776. }
  777. /* --------------------------------------------------------------------------- */
  778. g_val_t
  779. mtu_func ( void )
  780. {
  781. /* We want to find the minimum MTU (Max packet size) over all UP interfaces. */
  782. g_val_t val;
  783. val.uint32 = get_min_mtu();
  784. /* A val of 0 means there are no UP interfaces. Shouldn't happen. */
  785. return val;
  786. }
  787. /* EOF - hpux.c */