summaryrefslogtreecommitdiff
path: root/sysutils/gkrellm/patches/patch-ab
blob: dc4017a3804dc2ab87952b69237263d7cdb38a31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
$NetBSD: patch-ab,v 1.14 2005/09/08 13:19:56 cube Exp $

--- src/sysdeps/netbsd.c.orig	2005-05-24 05:45:10.000000000 +0200
+++ src/sysdeps/netbsd.c
@@ -63,7 +63,8 @@ gkrellm_sys_cpu_read_data(void)
 {
    static int mib[] = { CTL_KERN, KERN_CP_TIME };
    u_int64_t cp_time[ncpus][CPUSTATES];
-   int len, n;
+   int n;
+   size_t len;
 
    if (ncpus > 1) {
        len = sizeof(cp_time[0]);
@@ -94,7 +95,7 @@ get_ncpus(void)
 {
 	static int mib[] = { CTL_HW, HW_NCPU };
 	int ncpus;
-	int len = sizeof(int);
+	size_t len = sizeof(int);
 
 	if (sysctl(mib, 2, &ncpus, &len, NULL, 0) < 0)
 		return 1;
@@ -109,41 +110,35 @@ get_ncpus(void)
 #include <sys/proc.h>
 #include <sys/sysctl.h>
 #include <uvm/uvm_extern.h>
-#include <kvm.h>
 
 #include <utmp.h>
 
-static struct nlist nl[] = {
-#define X_UVM_EXP    0
-   { "_uvmexp" },
-   { NULL }
-};
-
-extern	kvm_t	*kvmd;
-
 void
 gkrellm_sys_proc_read_data(void)
 {
-   static int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
+   int mib[6];
    double avenrun;
-	guint	n_forks = 0, n_processes = 0;
-   struct uvmexp *uvmexp;
-   int len, i;
-
-   if (sysctl(mib, 3, NULL, &len, NULL, 0) >= 0) {
-      n_processes = len / sizeof(struct kinfo_proc);
+   guint n_forks = 0, n_processes = 0;
+   struct uvmexp_sysctl uvmexp;
+   size_t size;
+
+   mib[0] = CTL_KERN;
+   mib[1] = KERN_PROC2;
+   mib[2] = KERN_PROC_ALL;
+   mib[3] = 0;
+   mib[4] = sizeof(struct kinfo_proc2);
+   mib[5] = 0;
+   if (sysctl(mib, 6, NULL, &size, NULL, 0) >= 0) {
+      n_processes = size / sizeof(struct kinfo_proc2);
    }
 
-   /* get name list if it is not done yet */
-   if (kvmd == NULL) return;
-   if (nl[0].n_type == 0) kvm_nlist(kvmd, nl);
-
-   if (nl[0].n_type != 0) {
-      uvmexp = (struct uvmexp *)nl[X_UVM_EXP].n_value;
-      if (kvm_read(kvmd, (u_long)&uvmexp->forks, &i, sizeof(i)) == sizeof(i))
-	 n_forks = i;
+   mib[0] = CTL_VM;
+   mib[1] = VM_UVMEXP2;
+   size = sizeof(uvmexp);
+   if (sysctl(mib, 2, &uvmexp, &size, NULL, 0) >= 0) {
+      n_forks = uvmexp.forks;
    }
-
+ 
    if (getloadavg(&avenrun, 1) <= 0)
 		avenrun = 0;
 	gkrellm_proc_assign_data(n_processes, 0, n_forks, avenrun);
@@ -183,6 +178,96 @@ gkrellm_sys_proc_init(void)
 
 
 /* ===================================================================== */
+/* Memory/Swap monitor interface */
+
+#include <sys/vmmeter.h>
+#include <sys/sysctl.h>
+#include <uvm/uvm_extern.h>
+
+
+void
+gkrellm_sys_mem_read_data(void)
+{
+   int mib[2];
+   guint64 total, used, free, shared, buffers, cached;
+   struct vmtotal vmt;
+   struct uvmexp_sysctl uvmexp;
+   size_t len;
+
+   mib[0] = CTL_VM;
+   mib[1] = VM_METER;
+   len = sizeof(vmt);
+   if (sysctl(mib, 2, &vmt, &len, NULL, 0) < 0)
+      memset(&vmt, 0, sizeof(vmt));
+
+   mib[0] = CTL_VM;
+   mib[1] = VM_UVMEXP2;
+   len = sizeof(uvmexp);
+   if (sysctl(mib, 2, &uvmexp, &len, NULL, 0) < 0)
+      memset(&uvmexp, 0, sizeof(uvmexp));
+
+   total = uvmexp.npages << uvmexp.pageshift;
+
+   /* not sure of what must be computed */
+   free = (uvmexp.inactive + uvmexp.free) << uvmexp.pageshift;
+   shared = vmt.t_rmshr << uvmexp.pageshift;
+
+   /* can't use "uvmexp.active << uvmexp.pageshift" here because the
+    * display for "free" uses "total - used" which is very wrong. */
+   used = total - free;
+
+   /* don't know how to get those values */
+   buffers = 0;
+   cached = 0;
+
+   gkrellm_mem_assign_data(total, used, free, shared, buffers, cached);
+
+}
+
+void
+gkrellm_sys_swap_read_data(void)
+{
+   static int pgout, pgin;
+   int mib[2];
+   struct uvmexp_sysctl uvmexp;
+   size_t len;
+   static gulong swapin = 0, swapout = 0;
+   guint64 swap_total, swap_used;
+
+   mib[0] = CTL_VM;
+   mib[1] = VM_UVMEXP2;
+   len = sizeof(uvmexp);
+   if (sysctl(mib, 2, &uvmexp, &len, NULL, 0) < 0)
+      memset(&uvmexp, 0, sizeof(uvmexp));
+
+   /* show only the pages located on the disk and not in memory */
+   swap_total = (guint64) (uvmexp.swpages << uvmexp.pageshift);
+   swap_used = (guint64) (uvmexp.swpgonly << uvmexp.pageshift);
+
+   /* For page in/out operations, uvmexp struct doesn't seem to be reliable */
+
+   /* if the number of swapped pages that are in memory (inuse - only) is
+    * greater that the previous value (pgin), we count this a "page in" */
+   if (uvmexp.swpginuse - uvmexp.swpgonly > pgin)
+      swapin += uvmexp.swpginuse - uvmexp.swpgonly - pgin;
+   pgin = uvmexp.swpginuse - uvmexp.swpgonly;
+
+   /* same for page out */
+   if (uvmexp.swpgonly > pgout)
+      swapout += uvmexp.swpgonly - pgout;
+   pgout = uvmexp.swpgonly;
+
+   gkrellm_swap_assign_data(swap_total, swap_used, swapin, swapout);
+}
+
+gboolean
+gkrellm_sys_mem_init(void)
+	{
+	return TRUE;
+	}
+
+
+/* ===================================================================== */
 /* Sensor monitor interface */
 
   /* Tables of voltage correction factors and offsets derived from the
@@ -295,7 +380,7 @@ gkrellm_sys_sensors_init(void)
    int fd;			/* file desc. for /dev/sysmon */
    int id = 0;			/* incremented for each sensor */
    int type;
-   char *s, base_name[32];
+   char *s, base_name[33];
    gboolean	found_sensors = FALSE;
 
    /* check if some sensor is configured */
@@ -336,3 +421,149 @@ gkrellm_sys_sensors_init(void)
    return found_sensors;
 }
 
+
+/* ===================================================================== */
+/* Disk monitor interface */
+
+#include <sys/dkstat.h>
+#include <sys/disk.h>
+
+gboolean
+gkrellm_sys_disk_init(void)
+{
+	int mib[3] = { CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl) };
+	size_t size;
+
+	/* Just test if the sysctl call works */
+	if (sysctl(mib, 3, NULL, &size, NULL, 0) == -1)
+		return (FALSE);
+
+	return (TRUE);
+}
+
+void
+gkrellm_sys_disk_read_data(void)
+{
+	int i, n_disks, mib[3] = { CTL_HW, HW_DISKSTATS, sizeof(struct disk_sysctl) };
+	size_t size;
+	guint64 rbytes, wbytes;
+	struct disk_sysctl *dk_drives;
+
+	if (sysctl(mib, 3, NULL, &size, NULL, 0) == -1)
+		return;
+	dk_drives = malloc(size);
+	if (dk_drives == NULL)
+		return;
+	n_disks = size / sizeof(struct disk_sysctl);
+
+	if (sysctl(mib, 3, dk_drives, &size, NULL, 0) == -1)
+		return;
+
+	for (i = 0; i < n_disks; i++) {
+#if __NetBSD_Version__ >= 106110000
+		rbytes = dk_drives[i].dk_rbytes;
+		wbytes = dk_drives[i].dk_wbytes;
+#else
+		rbytes = dk_drives[i].dk_bytes;
+		wbytes = 0;
+#endif
+
+		gkrellm_disk_assign_data_by_name(dk_drives[i].dk_name, rbytes, wbytes, FALSE);
+	}
+
+	free(dk_drives);
+}
+
+gchar *
+gkrellm_sys_disk_name_from_device(gint device_number, gint unit_number,
+			gint *order)
+	{
+	return NULL;	/* disk data by device not implemented */
+	}
+
+gint
+gkrellm_sys_disk_order_from_name(gchar *name)
+	{
+	return -1;  /* append disk charts as added */
+	}
+
+#if __NetBSD_Version__ >= 399000100
+
+#include "../inet.h"
+
+#include <errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp_fsm.h>
+
+static const struct gkrellm_inet_fam {
+	sa_family_t family;
+	const char *mib;
+} families[] = { {AF_INET, "net.inet.tcp.pcblist"},
+#ifdef INET6
+    {AF_INET6, "net.inet6.tcp6.pcblist"},
+#endif
+    {0, NULL} };
+
+void
+gkrellm_sys_inet_read_tcp_data()
+{
+	ActiveTCP tcp;
+	int mib[CTL_MAXNAME], i;
+	size_t sz;
+	u_int namelen;
+	struct kinfo_pcb *pcbt = NULL;
+	const struct gkrellm_inet_fam *pf = families;
+
+	while (pf->mib != NULL) {
+		sz = CTL_MAXNAME;
+		if (sysctlnametomib(pf->mib, mib, &sz) == -1)
+			return;
+		namelen = sz;
+
+		mib[namelen++] = PCB_ALL;
+		mib[namelen++] = 0;
+		mib[namelen++] = sizeof(struct kinfo_pcb);
+		mib[namelen++] = INT_MAX;
+
+		sz = 0;
+		pcbt = NULL;
+		if (sysctl(&mib[0], namelen, pcbt, &sz, NULL, 0) == -1)
+			return;
+		pcbt = malloc(sz);
+		if (pcbt == NULL)
+			return;
+		if (sysctl(&mib[0], namelen, pcbt, &sz, NULL, 0) == -1)
+			return;
+
+		sz /= sizeof(struct kinfo_pcb);
+		for (i = 0; i < sz; i++) {
+			tcp.family = pf->family;
+			if (pf->family == AF_INET) {
+				struct sockaddr_in *sin =
+				    (struct sockaddr_in *)&pcbt[i].ki_dst;
+				tcp.remote_addr.s_addr = sin->sin_addr.s_addr;
+				tcp.remote_port = sin->sin_port;
+
+				sin = (struct sockaddr_in *)&pcbt[i].ki_src;
+				tcp.local_port = sin->sin_port;
+#ifdef INET6
+			} else { /* AF_INET6 */
+				struct sockaddr_in6 *sin =
+				    (struct sockaddr_in6 *)&pcbt[i].ki_dst;
+				memcpy(&tcp.remote_addr6, &sin->sin6_addr,
+				    sizeof(struct in6_addr));
+				tcp.remote_port = sin->sin6_port;
+
+				sin = (struct sockaddr_in6 *)&pcbt[i].ki_src;
+				tcp.local_port = sin->sin6_port;
+#endif
+			}
+			if (pcbt[i].ki_tstate == TCPS_ESTABLISHED)
+				gkrellm_inet_log_tcp_port_data(&tcp);
+		}
+		free(pcbt);
+		pf++;
+	}
+}
+#endif