ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/memory_stats.c
Revision: 1.3
Committed: Thu Feb 20 13:19:52 2003 UTC (21 years, 2 months ago) by tdb
Content type: text/plain
Branch: MAIN
Changes since 1.2: +0 -1 lines
Log Message:
Removed references to ukcprog.h.
Fixed a missing * in the disk stats.
And removed a block of linux stuff that shouldn't have been there :-)
All with Pete's approval, of course.

File Contents

# Content
1 /*
2 * i-scream central monitoring system
3 * http://www.i-scream.org.uk
4 * Copyright (C) 2000-2002 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.
10 *
11 * This program 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.
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.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <stdio.h>
26 #include "statgrab.h"
27 #ifdef LINUX
28 #include <string.h>
29 #endif
30 #ifdef SOLARIS
31 #include <unistd.h>
32 #include <kstat.h>
33 #endif
34 #ifdef FREEBSD
35 #include <sys/types.h>
36 #include <sys/sysctl.h>
37 #include <unistd.h>
38 #endif
39
40 mem_stat_t *get_memory_stats(){
41
42 static mem_stat_t mem_stat;
43
44 #ifdef SOLARIS
45 kstat_ctl_t *kc;
46 kstat_t *ksp;
47 kstat_named_t *kn;
48 long totalmem;
49 int pagesize;
50 #endif
51
52 #ifdef SOLARIS
53 if((pagesize=sysconf(_SC_PAGESIZE)) == -1){
54 return NULL;
55 }
56
57 if((totalmem=sysconf(_SC_PHYS_PAGES)) == -1){
58 return NULL;
59 }
60
61 if ((kc = kstat_open()) == NULL) {
62 return NULL;
63 }
64 if((ksp=kstat_lookup(kc, "unix", 0, "system_pages")) == NULL){
65 return NULL;
66 }
67 if (kstat_read(kc, ksp, 0) == -1) {
68 return NULL;
69 }
70 if((kn=kstat_data_lookup(ksp, "freemem")) == NULL){
71 return NULL;
72 }
73 kstat_close(kc);
74
75 mem_stat.total = (long long)totalmem * (long long)pagesize;
76 mem_stat.free = ((long long)kn->value.ul) * (long long)pagesize;
77 mem_stat.used = mem_stat.total - mem_stat.free;
78 #endif
79
80 return &mem_stat;
81
82 }