~ubuntu-branches/ubuntu/maverick/monit/maverick

« back to all changes in this revision

Viewing changes to process/sysdep_HPUX.c

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Alfredsson
  • Date: 2010-03-19 22:40:11 UTC
  • mfrom: (1.1.6 upstream) (5.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100319224011-o1z4m0xh8z81jczo
Tags: 1:5.1.1-1
* New upstream release (Closes: #573777)
* Added configurable statefile in /etc/default/monit (Closes: #569616)
* Verbose info when syntax errors are detected at start (Closes: #427922)
* Sample configuration adjustments (Closes: #427924)
* Removed pam_securityserver in pam config (Closes: #574120)
* An include-directory is supplied (Closes: #249933)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2009 Tildeslash Ltd. All rights reserved.
 
2
 * Copyright (C) 2010 Tildeslash Ltd. All rights reserved.
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License version 3.
114
114
 *  @author Christian Hopp <chopp@iei.tu-clausthal.de>
115
115
 *  @author Joe Bryant <JBryant@RiteAid.com>
116
116
 *  @author Martin Pala, <martinp@tildeslash.com>
117
 
 *  @version \$Id: sysdep_HPUX.c,v 1.35 2009/02/13 09:18:17 hauk Exp $
118
117
 *
119
118
 *  @file
120
119
 */
121
120
 
122
121
/*
123
122
 * Helpful guide for implematation:
124
 
 * "SunOS to HP-UX 9.05 Porting Guide" at
125
 
 *    http://www.interex.org/tech/9000/Tech/sun_hpux_port/portguide.html
 
123
 * "SunOS to HP-UX 9.05 Porting Guide" at http://www.interex.org/tech/9000/Tech/sun_hpux_port/portguide.html
126
124
 */
127
125
 
128
126
int init_process_info_sysdep(void) {
129
127
  struct pst_dynamic psd;
130
128
  struct pst_static pst;
131
129
 
132
 
  if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) {
133
 
 
 
130
  if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0) != -1)
134
131
    systeminfo.cpus=psd.psd_proc_cnt;
135
 
 
136
 
  } else {
137
 
 
 
132
  else
138
133
    return FALSE;
139
134
 
140
 
  }
141
 
 
142
135
  if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) != -1) {
143
 
 
144
136
    systeminfo.mem_kbyte_max=(unsigned long)(pst.physical_memory * (pst.page_size / 1024)); 
145
137
    page_size=pst.page_size;
146
 
 
147
138
  } else {
148
 
 
149
139
    return FALSE;
150
 
 
151
140
  }
152
141
 
153
142
  return TRUE;
154
143
}
155
144
 
 
145
 
156
146
/**
157
147
 * This routine returns 'na' double precision floats containing
158
148
 * the load averages in 'a'; at most 3 values will be returned.
161
151
 * @return: 0 if successful, -1 if failed (and all load averages are 0).
162
152
 */
163
153
int getloadavg_sysdep (double *a, int na) {
164
 
  
165
154
  struct pst_dynamic psd;
166
155
        
167
 
  if (pstat_getdynamic(&psd,sizeof(psd),(size_t)1,0)!=-1) {
168
 
    
 
156
  if (pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0) != -1) {
169
157
    switch (na) {
170
158
    case 3:
171
 
 
172
 
      a[2]=psd.psd_avg_15_min;
 
159
      a[2] = psd.psd_avg_15_min;
173
160
 
174
161
    case 2:
175
 
 
176
 
      a[1]=psd.psd_avg_5_min;
 
162
      a[1] = psd.psd_avg_5_min;
177
163
 
178
164
    case 1:
179
 
 
180
 
      a[0]=psd.psd_avg_1_min;
181
 
 
 
165
      a[0] = psd.psd_avg_1_min;
182
166
    }
183
 
 
184
167
  } else {
185
 
 
186
168
    return FALSE;
187
 
 
188
169
  }
189
170
 
190
171
  return TRUE;
197
178
 * @return treesize>0 if succeeded otherwise 0.
198
179
 */
199
180
int initprocesstree_sysdep(ProcessTree_T ** reference) {
200
 
 
201
181
  int            i;
202
182
  int            treesize;
203
183
  ProcessTree_T *pt;
204
184
 
205
185
  ASSERT(reference);
206
186
 
207
 
  /* Gather process data */
208
 
 
209
187
  pstat_getdynamic(&pst_dyn, sizeof(struct pst_dynamic), 1, 0);
210
188
  nproc = pst_dyn.psd_activeprocs;
211
189
 
212
 
  if ((psall = (struct pst_status *) xresize(psall, nproc * sizeof(struct pst_status))) == NULL)
213
 
        return 0;
 
190
  if ((psall = (struct pst_status *)xresize(psall, nproc * sizeof(struct pst_status))) == NULL)
 
191
    return 0;
214
192
 
215
 
  if ((treesize=pstat_getproc(psall, sizeof(struct pst_status), nproc , 0))==-1) {
 
193
  if ((treesize = pstat_getproc(psall, sizeof(struct pst_status), nproc , 0)) == -1) {
216
194
    LogError("system statistic error 1 -- pstat_getproc failed: %s\n", strerror(errno));
217
195
    return 0;
218
196
  }
219
197
 
220
 
  /* Allocate the tree */
221
 
 
222
198
  pt = xcalloc(sizeof(ProcessTree_T), treesize);
223
199
 
224
 
  /* Inspect data */
225
 
 
226
200
  for (i = 0; i < treesize; i++) {
227
 
 
228
 
    pt[i].pid = psall[i].pst_pid;
229
 
    pt[i].ppid = psall[i].pst_ppid;
230
 
 
231
 
    /* get the actual time */
232
 
 
233
 
    pt[i].time = get_float_time();
234
 
 
235
 
    pt[i].cputime =  psall[i].pst_utime + psall[i].pst_stime * 10;
 
201
    pt[i].pid         = psall[i].pst_pid;
 
202
    pt[i].ppid        = psall[i].pst_ppid;
 
203
    pt[i].time        = get_float_time();
 
204
    pt[i].cputime     =  psall[i].pst_utime + psall[i].pst_stime * 10;
236
205
    pt[i].cpu_percent = (int)(1000. * psall[i].pst_pctcpu / (float)systeminfo.cpus);
237
 
    pt[i].mem_kbyte = (unsigned long)(psall[i].pst_rssize * (page_size / 1024.0));
238
 
 
239
 
    /* State is Zombie -> then we are a Zombie ... clear or? (-: */
240
 
 
241
 
    if ( psall[i].pst_stat == PS_ZOMBIE ) {
242
 
 
 
206
    pt[i].mem_kbyte   = (unsigned long)(psall[i].pst_rssize * (page_size / 1024.0));
 
207
 
 
208
    if ( psall[i].pst_stat == PS_ZOMBIE )
243
209
      pt[i].status_flag |= PROCESS_ZOMBIE;
244
 
      
245
 
    }
246
 
    
247
210
  }
248
211
 
249
 
  /* Return results */
250
 
 
251
 
  * reference = pt;
 
212
  *reference = pt;
252
213
 
253
214
  return treesize;
254
 
 
255
215
}
256
216
 
257
217
 
293
253
  pstat_getdynamic(&psd, sizeof(psd), 1, 0);
294
254
 
295
255
  for(i = 0; i < CPUSTATES; i++)
296
 
  {
297
256
    cpu_total_new += psd.psd_cpu_time[i];
298
 
  }
299
257
  cpu_total     = cpu_total_new - cpu_total_old;
300
258
  cpu_total_old = cpu_total_new;
301
259
  cpu_user      = psd.psd_cpu_time[CP_USER] + psd.psd_cpu_time[CP_NICE];
302
260
  cpu_syst      = psd.psd_cpu_time[CP_SYS];
303
261
  cpu_wait      = psd.psd_cpu_time[CP_WAIT];
304
262
 
305
 
  si->total_cpu_user_percent =
306
 
    (cpu_total > 0)?(int)(1000 * (double)(cpu_user - cpu_user_old) / cpu_total):-10;
307
 
  si->total_cpu_syst_percent =
308
 
    (cpu_total > 0)?(int)(1000 * (double)(cpu_syst - cpu_syst_old) / cpu_total):-10;
309
 
  si->total_cpu_wait_percent =
310
 
    (cpu_total > 0)?(int)(1000 * (double)(cpu_wait - cpu_wait_old) / cpu_total):-10;
 
263
  si->total_cpu_user_percent = (cpu_total > 0)?(int)(1000 * (double)(cpu_user - cpu_user_old) / cpu_total):-10;
 
264
  si->total_cpu_syst_percent = (cpu_total > 0)?(int)(1000 * (double)(cpu_syst - cpu_syst_old) / cpu_total):-10;
 
265
  si->total_cpu_wait_percent = (cpu_total > 0)?(int)(1000 * (double)(cpu_wait - cpu_wait_old) / cpu_total):-10;
311
266
 
312
267
  cpu_user_old = cpu_user;
313
268
  cpu_syst_old = cpu_syst;