Lines 1-221
Link Here
|
1 |
--- agent/mibgroup/host/hr_storage.c.orig Fri Oct 7 07:55:23 2005 |
|
|
2 |
+++ agent/mibgroup/host/hr_storage.c Wed Nov 30 12:01:05 2005 |
3 |
@@ -233,6 +233,10 @@ |
4 |
void sol_get_swapinfo(int *, int *); |
5 |
#endif |
6 |
|
7 |
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500102 |
8 |
+void collect_mbuf(long *long_mbuf, long *long_mbufc); |
9 |
+#endif |
10 |
+ |
11 |
#define HRSTORE_MEMSIZE 1 |
12 |
#define HRSTORE_INDEX 2 |
13 |
#define HRSTORE_TYPE 3 |
14 |
@@ -472,7 +476,8 @@ |
15 |
NULL, |
16 |
"Memory Buffers", /* HRS_TYPE_MBUF */ |
17 |
"Real Memory", /* HRS_TYPE_MEM */ |
18 |
- "Swap Space" /* HRS_TYPE_SWAP */ |
19 |
+ "Swap Space", /* HRS_TYPE_SWAP */ |
20 |
+ "Memory Buffer Clusters" /* HRS_TYPE_MBUFCLUSTER */ |
21 |
}; |
22 |
|
23 |
|
24 |
@@ -611,6 +616,7 @@ |
25 |
storage_type_id[storage_type_len - 1] = 3; /* |
26 |
break; |
27 |
case HRS_TYPE_MBUF: |
28 |
+ case HRS_TYPE_MBUFCLUSTER: |
29 |
storage_type_id[storage_type_len - 1] = 1; /* |
30 |
break; |
31 |
default: |
32 |
@@ -704,7 +710,7 @@ |
33 |
long_return = memory_totals.t_vm; |
34 |
#endif |
35 |
break; |
36 |
-#else /* !linux && !solaris2 && !hpux10 && !hpux11 && ... */ |
37 |
+#else |
38 |
case HRS_TYPE_MEM: |
39 |
long_return = physmem; |
40 |
break; |
41 |
@@ -726,13 +732,45 @@ |
42 |
i++) |
43 |
long_return += mbstat.m_mtypes[i]; |
44 |
#elif defined(MBSTAT_SYMBOL) && defined(STRUCT_MBSTAT_HAS_M_MBUFS) |
45 |
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500021 |
46 |
long_return = mbstat.m_mbufs; |
47 |
+#elif defined(__FreeBSD__) && __FreeBSD_version < 500024 |
48 |
+ /* mbuf stats disabled */ |
49 |
+ return NULL; |
50 |
+#elif defined(__FreeBSD__) |
51 |
+ { |
52 |
+ size_t mlen = sizeof(int); |
53 |
+ int nmbufs; |
54 |
+ if (sysctlbyname("kern.ipc.nmbufs", &nmbufs, &mlen, |
55 |
+ NULL, 0) < 0) { |
56 |
+ return NULL; |
57 |
+ } |
58 |
+ long_return = nmbufs; |
59 |
+ break; |
60 |
+ } |
61 |
+#else |
62 |
+#error "XXX" |
63 |
+ /* XXX TODO: implement new method */ |
64 |
+ return NULL; |
65 |
+#endif /* __FreeBSD__ */ |
66 |
#elif defined(NO_DUMMY_VALUES) |
67 |
goto try_next; |
68 |
#else |
69 |
long_return = 0; |
70 |
#endif |
71 |
break; |
72 |
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500024 |
73 |
+ case HRS_TYPE_MBUFCLUSTER: { |
74 |
+ size_t mlen = sizeof(int); |
75 |
+ int nmbclusters; |
76 |
+ if (sysctlbyname("kern.ipc.nmbclusters", &nmbclusters, &mlen, |
77 |
+ NULL, 0) < 0) { |
78 |
+ return NULL; |
79 |
+ } |
80 |
+ long_return = nmbclusters; |
81 |
+ break; |
82 |
+ } |
83 |
+#endif |
84 |
default: |
85 |
#if NO_DUMMY_VALUES |
86 |
goto try_next; |
87 |
@@ -796,6 +834,12 @@ |
88 |
#endif |
89 |
#elif defined(MBSTAT_SYMBOL) && defined(STRUCT_MBSTAT_HAS_M_CLUSTERS) |
90 |
long_return = mbstat.m_clusters - mbstat.m_clfree; |
91 |
/* unlikely, but... */ |
0 |
/* unlikely, but... */ |
92 |
+#elif defined(__FreeBSD__) && __FreeBSD_version < 500102 |
|
|
93 |
+ /* mbuf stats disabled */ |
94 |
+ return NULL; |
95 |
+#elif defined(__FreeBSD__) |
96 |
+ collect_mbuf((long*)&long_return, (long*)NULL); |
97 |
+ break; |
98 |
#elif defined(NO_DUMMY_VALUES) |
99 |
goto try_next; |
100 |
#else |
101 |
@@ -803,6 +847,11 @@ |
102 |
#endif |
103 |
break; |
104 |
#endif /* !linux && !solaris2 && !hpux10 && |
105 |
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500102 |
106 |
+ case HRS_TYPE_MBUFCLUSTER: |
107 |
+ collect_mbuf(NULL, &long_return); |
108 |
+ break; |
109 |
+#endif |
110 |
default: |
111 |
#if NO_DUMMY_VALUES |
112 |
goto try_next; |
113 |
@@ -829,7 +878,11 @@ |
114 |
break; |
115 |
#if !defined(linux) && !defined(solaris2) && !defined(hpux10) && |
116 |
case HRS_TYPE_MBUF: |
117 |
+#if defined(__FreeBSD__) && __FreeBSD_version >= 502113 |
118 |
+ long_return = mbstat.m_mcfail + mbstat.m_mpfail; |
119 |
+#else |
120 |
long_return = mbstat.m_drops; |
121 |
+#endif |
122 |
break; |
123 |
#endif /* !linux && !solaris2 && !hpux10 && |
124 |
default: |
125 |
@@ -955,3 +1008,97 @@ |
126 |
*usedP = ainfo.ani_resv; |
127 |
} |
128 |
#endif /* solaris2 */ |
129 |
+ |
130 |
+#if defined(__FreeBSD__) && __FreeBSD_version >= 500102 |
131 |
+void |
132 |
+collect_mbuf(long *long_mbuf, long *long_mbufc) |
133 |
+{ |
134 |
+#if __FreeBSD_version >= 502113 |
135 |
+ size_t mlen; |
136 |
+ struct mbstat mbstat; |
137 |
+ |
138 |
+ mlen = sizeof mbstat; |
139 |
+ if (sysctlbyname("kern.ipc.mbstat", &mbstat, &mlen, NULL, 0) < 0) { |
140 |
+ warn("sysctl: retrieving mbstat"); |
141 |
+ return; |
142 |
+ } |
143 |
+ if (mbstat.m_mbufs < 0) mbstat.m_mbufs = 0; /* XXX */ |
144 |
+ if (mbstat.m_mclusts < 0) mbstat.m_mclusts = 0; /* XXX */ |
145 |
+ if (long_mbuf) { |
146 |
+ *long_mbuf = mbstat.m_mbufs; |
147 |
+ } |
148 |
+ if (long_mbufc) { |
149 |
+ *long_mbufc = mbstat.m_mclusts; |
150 |
+ } |
151 |
+#else |
152 |
+ int i, j, num_objs; |
153 |
+ size_t mlen; |
154 |
+ u_long totused[2]; |
155 |
+ u_long totnum, totfree; |
156 |
+ struct mbstat mbstat; |
157 |
+ struct mbpstat **mbpstat = NULL; |
158 |
+ |
159 |
+ if (sysctlbyname("kern.ipc.mb_statpcpu", NULL, &mlen, NULL, 0) < 0) { |
160 |
+ warn("sysctl: retrieving mb_statpcpu len"); |
161 |
+ goto err; |
162 |
+ } |
163 |
+ num_objs = (int)(mlen / sizeof(struct mbpstat)); |
164 |
+ if ((mbpstat = calloc(num_objs, sizeof(struct mbpstat *))) == NULL) { |
165 |
+ warn("calloc: cannot allocate memory for mbpstats pointers"); |
166 |
+ goto err; |
167 |
+ } |
168 |
+ if ((mbpstat[0] = calloc(num_objs, sizeof(struct mbpstat))) == NULL) { |
169 |
+ warn("calloc: cannot allocate memory for mbpstats"); |
170 |
+ goto err; |
171 |
+ } |
172 |
+ |
173 |
+ if (sysctlbyname("kern.ipc.mb_statpcpu", mbpstat[0], &mlen, NULL, 0) |
174 |
0) { |
175 |
+ warn("sysctl: retrieving mb_statpcpu"); |
176 |
+ goto err; |
177 |
+ } |
178 |
+ mlen = sizeof mbstat; |
179 |
+ if (sysctlbyname("kern.ipc.mbstat", &mbstat, &mlen, NULL, 0) < 0) { |
180 |
+ warn("sysctl: retrieving mbstat"); |
181 |
+ goto err; |
182 |
+ } |
183 |
+ |
184 |
+ for (i = 0; i < num_objs; i++) |
185 |
+ mbpstat[i] = mbpstat[0] + i; |
186 |
+ |
187 |
+#define GENLST (num_objs - 1) |
188 |
+ |
189 |
+ totnum = mbpstat[GENLST]->mb_mbbucks * mbstat.m_mbperbuck; |
190 |
+ totfree = mbpstat[GENLST]->mb_mbfree; |
191 |
+ for (i = 0; i < (num_objs - 1); i++) { |
192 |
+ if (mbpstat[i]->mb_active == 0) |
193 |
+ continue; |
194 |
+ totnum += mbpstat[i]->mb_mbbucks * mbstat.m_mbperbuck; |
195 |
+ totfree += mbpstat[i]->mb_mbfree; |
196 |
+ } |
197 |
+ totused[0] = totnum - totfree; |
198 |
+ totnum = mbpstat[GENLST]->mb_clbucks * mbstat.m_clperbuck; |
199 |
+ totfree = mbpstat[GENLST]->mb_clfree; |
200 |
+ for (i = 0; i < (num_objs - 1); i++) { |
201 |
+ if (mbpstat[i]->mb_active == 0) |
202 |
+ continue; |
203 |
+ totnum += mbpstat[i]->mb_clbucks * mbstat.m_clperbuck; |
204 |
+ totfree += mbpstat[i]->mb_clfree; |
205 |
+ } |
206 |
+ totused[1] = totnum - totfree; |
207 |
+ |
208 |
+ if (long_mbuf) { |
209 |
+ *long_mbuf = totused[0]; |
210 |
+ } |
211 |
+ if (long_mbufc) { |
212 |
+ *long_mbufc = totused[1]; |
213 |
+ } |
214 |
+ |
215 |
+ err: |
216 |
+ if (mbpstat != NULL) { |
217 |
+ if (mbpstat[0] != NULL) |
218 |
+ free(mbpstat[0]); |
219 |
+ free(mbpstat); |
220 |
+ } |
221 |
+#endif |
222 |
+} |
223 |
+#endif |