/* * Copyright (C), 2000-2007 by the monit project group. * All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #ifdef HAVE_STDIO_H #include #endif #ifdef HAVE_ERRNO_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_FCNTL_H #include #endif #ifdef HAVE_STDLIB_H #include #endif #ifdef TIME_WITH_SYS_TIME #include #ifdef HAVE_SYS_TIME_H #include #endif #else #include #endif #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_PROCINFO_H #include #endif #ifdef HAVE_SYS_PROC_H #include #endif #ifdef HAVE_PROCFS_H #include #endif #ifdef HAVE_CF_H #include #endif #ifdef HAVE_SYS_CFGODM_H #include #endif #ifdef HAVE_SYS_CFGDB_H #include #endif #include "monitor.h" #include "process.h" #include "process_sysdep.h" /** * System dependent resource gathering code for AIX * * @author Richard Schwaninger * @author Jan-Henrik Haukeland, * @author Christian Hopp * * @version \$Id: sysdep_AIX.c,v 1.17 2007/07/25 12:54:32 hauk Exp $ * * @file * most of the code is based on monitor-2.1.5 available on various sources * (see below). * The source code version of monitor program can be get from ftp-server * ftp://ftp.mesa.nl/pub/monitor/monitor-2.1.5.tar.gz * or via the web from * http://www.mesa.nl/pub/monitor/monitor-2.1.5.tar.gz. */ #define NPROCS 10000 struct procinfo procs[NPROCS]; int kmemfd = -1; int nlistdone = 0; int init_process_info_sysdep(void) { struct CuAt* odmobj; int results; if (odm_initialize() == 0) { odmobj = (struct CuAt*)getattr ("sys0", "realmem", 0, &results); systeminfo.mem_kbyte_max = strtoull(odmobj->value, 0, 10); odm_terminate(); } else { mem_kbyte_max = 0; } num_cpus= sysconf( _SC_NPROCESSORS_ONLN); return (getuid()==0); } double timestruc_to_tseconds(struct timeval t) { return t.tv_sec * 10 + t.tv_usec * 1.0e-7; } /*************************************************************************** * DATA CAPTURE FUNCTIONS * ***************************************************************************/ int getkmemdata(void *buf, int bufsize, caddr_t address) { int n; /* * Do stuff we only need to do once per invocation, like opening * the kmem file and fetching the parts of the symbol table. */ if (kmemfd < 0) { if ((kmemfd = open("/dev/kmem", O_RDONLY)) < 0) { perror("kmem"); exit(1); } } /* * Get the structure from the running kernel. */ lseek(kmemfd, (off_t) address, SEEK_SET); n = read(kmemfd, buf, bufsize); return(n); } /* getkmemdata */ /** * This routine returns 'nelem' double precision floats containing * the load averages in 'loadv'; at most 3 values will be returned. * @param loadv destination of the load averages * @param nelem number of averages * @return: 0 if successful, -1 if failed (and all load averages are 0). */ int getloadavg_sysdep (double *loadv, int nelem) { return getloadavg(loadv, nelem); } /** * Read all processes of the proc files system to initialize * the process tree (sysdep version... but should work for * all procfs based unices) * @param reference reference of ProcessTree * @return treesize>0 if succeeded otherwise =0. */ int initprocesstree_sysdep(ProcessTree_T ** reference) { int treesize; int i,rv; struct userinfo user; ProcessTree_T * pt; memset(&user,0,sizeof(struct userinfo)); /* Find all processes in the system */ treesize=getproc(procs,NPROCS,sizeof(struct procinfo)); /* Allocate the tree */ pt = xcalloc(sizeof(ProcessTree_T), treesize); /* Insert data from /proc directory */ for(i=0;i