Date: Mon, 27 Sep 1999 21:03:40 -0400 (EDT) From: jack@germanium.xtalwind.net To: FreeBSD-gnats-submit@freebsd.org Subject: ports/14008: New port of asmon-0.60 system monitor for X Message-ID: <199909280103.VAA19388@germanium.xtalwind.net>
next in thread | raw e-mail | index | archive | help
>Number: 14008 >Category: ports >Synopsis: New port of asmon-0.60 system monitor for X >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Sep 27 18:10:01 PDT 1999 >Closed-Date: >Last-Modified: >Originator: >Release: FreeBSD 3.3-STABLE i386 >Organization: >Environment: >Description: The asmon tool is an AfterStep look-n-feel memory, swap, cpu, and load average monitor for X Windows. "Lights" indicate swap and vm paging. Also displays system uptime or X memory usage. >How-To-Repeat: >Fix: # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # asmon # asmon/pkg # asmon/pkg/COMMENT # asmon/pkg/DESCR # asmon/pkg/PLIST # asmon/patches # asmon/patches/patch-ab # asmon/patches/patch-aa # asmon/files # asmon/files/md5 # asmon/Makefile # echo c - asmon mkdir -p asmon > /dev/null 2>&1 echo c - asmon/pkg mkdir -p asmon/pkg > /dev/null 2>&1 echo x - asmon/pkg/COMMENT sed 's/^X//' >asmon/pkg/COMMENT << 'END-of-asmon/pkg/COMMENT' XA swallowable applet monitors the CPU usage, memory and swap, etc END-of-asmon/pkg/COMMENT echo x - asmon/pkg/DESCR sed 's/^X//' >asmon/pkg/DESCR << 'END-of-asmon/pkg/DESCR' XThe asmon tool is an AfterStep look-n-feel memory, swap, cpu, and load Xaverage monitor for X Windows. "Lights" indicate swap and vm paging. XAlso displays system uptime or X memory usage. END-of-asmon/pkg/DESCR echo x - asmon/pkg/PLIST sed 's/^X//' >asmon/pkg/PLIST << 'END-of-asmon/pkg/PLIST' Xbin/asmon END-of-asmon/pkg/PLIST echo c - asmon/patches mkdir -p asmon/patches > /dev/null 2>&1 echo x - asmon/patches/patch-ab sed 's/^X//' >asmon/patches/patch-ab << 'END-of-asmon/patches/patch-ab' X--- asmon/asmon.c.orig Sun Jun 27 15:38:26 1999 X+++ asmon/asmon.c Mon Sep 27 19:58:05 1999 X@@ -21,6 +21,19 @@ X #include "asmon-master.xpm" X #include "asmon-mask.xbm" X X+#ifdef __FreeBSD__ X+#include <err.h> X+#include <kvm.h> X+#include <nlist.h> X+#include <sys/rlist.h> X+#include <sys/conf.h> X+#include <sys/user.h> X+#include <sys/vmmeter.h> X+#include <sys/sysctl.h> X+#include <vm/vm_param.h> X+#include <sys/time.h> X+#endif X+ X #ifdef __solaris__ X #include <utmp.h> X #endif X@@ -47,6 +60,39 @@ X #define B_RED (1) X #define B_GREEN (2) X X+#ifdef __FreeBSD__ X+kvm_t *kd; X+ X+#define SVAR(var) __STRING(var) /* to force expansion */ X+#define KGET(idx, var) \ X+ KGET1(idx, &var, sizeof(var), SVAR(var)) X+#define KGET1(idx, p, s, msg) \ X+ KGET2(nl[idx].n_value, p, s, msg) X+#define KGET2(addr, p, s, msg) \ X+ if (kvm_read(kd, (u_long)(addr), p, s) != s) \ X+ warnx("cannot read %s: %s", msg, kvm_geterr(kd)) X+ X+struct nlist nl[] = { X+#define VM_SWAPLIST 0 X+ { "_swaplist" },/* list of free swap areas */ X+#define VM_SWDEVT 1 X+ { "_swdevt" }, /* list of swap devices and sizes */ X+#define VM_NSWAP 2 X+ { "_nswap" }, /* size of largest swap device */ X+#define VM_NSWDEV 3 X+ { "_nswdev" }, /* number of swap devices */ X+#define VM_DMMAX 4 X+ { "_dmmax" }, /* maximum size of a swap block */ X+#define X_CNT 5 X+ { "_cnt" }, X+#define X_BUFSPACE 6 X+ { "_bufspace" }, /* K in buffer cache */ X+#define X_CP_TIME 7 X+ { "_cp_time" }, X+ { "" } X+}; X+#endif X+ X /* Evil globals I haven't removed yet */ X long last_pageins=0, last_pageouts=0; X long last_swapins=0, last_swapouts=0; X@@ -77,6 +123,11 @@ X float DrawMemSwap(float total, int allmem); X #endif X X+#ifdef __FreeBSD__ X+void open_kvm(void); X+void close_kvm(void); X+#endif X+ X int main(int argc, char *argv[]) X { X FILE *fp; X@@ -151,7 +202,17 @@ X #endif X /* Open 64x64 window */ X openXwindow(argc, argv, asmon_master_xpm, asmon_mask_bits, asmon_mask_width, asmon_mask_height); X+ X+#ifdef __FreeBSD__ X+ open_kvm(); X+#endif X+ X asmon_routine(Xpid, allmem); X+ X+#ifdef __FreeBSD__ X+ close_kvm(); X+#endif X+ X return(0); X } X X@@ -160,7 +221,11 @@ X void usage(void) { X fprintf(stderr, "\nasmon %s - by Brad Hall (brad@rio.dhs.org)\n\t\toriginally based on Timecop's wmcpu\n\n", ASMON_VERSION); X fprintf(stderr, "The top bar: left is the CPU usage, right is the load average\n"); X+#ifdef __FreeBSD__ X+ fprintf(stderr, "The middle bar: left memory usage devided by ticks into active, inactive,\n\t\twired, cached + buffers, respectively, and the number\n\t\tof megs used\n"); X+#else X fprintf(stderr, "The middle bar: left memory usage devided by ticks into shared, buffers, and\n\t\t cached, respectively, and the number of megs used\n"); X+#endif X fprintf(stderr, "The lower bar: the left swap usage and the number of megs swappedd avg\n"); X fprintf(stderr, "The bottom: the left is a set of LED's marking page's and swap's, the right is\n\t\t a bar representing the amount of memory that the X server \n\t\t is taking up, and the exact megs\n\n usage:\n"); X fprintf(stderr, "\t-display <display name>\n"); X@@ -168,8 +233,13 @@ X fprintf(stderr, "\t-v\tprint the version number\n"); X #ifndef __solaris__ X fprintf(stderr, "\t-u\tforce asmon to show uptime, rather than X mem use\n"); X+#else X+#ifdef __FreeBSD__ X+ fprintf(stderr, "\t-m\tmake asmon show only active mem\n"); X+#else X fprintf(stderr, "\t-m\tmake asmon show only shared mem, like most other mem meters\n"); X #endif X+#endif X #ifdef EXEC_ON_CLICK X fprintf(stderr, "\t-e cmd\texecute 'cmd' on mouse click\n"); X #endif X@@ -323,12 +393,13 @@ X /* CPU Usage Meter */ X void DrawCPU(void) X { X- FILE *fp; X static float cpustat[4]; /* remember the statistics read last time */ X float fields[4], info[4], cputotal=0.0; X long pageins=0, pageouts=0, swapins=0, swapouts=0; X- char buf[128]; X int i; X+#ifndef __FreeBSD__ X+ char buf[128]; X+ FILE *fp; X X if( (fp = fopen("/proc/stat", "r")) != NULL) X { X@@ -345,7 +416,15 @@ X sscanf(buf, "swap %ld %ld", &swapins, &swapouts); X } X fclose(fp); X- X+#else X+ { X+ long cputime[4]; X+ struct vmmeter sum; X+ X+ kvm_read(kd, nl[X_CP_TIME].n_value, &cputime, sizeof(cputime)); X+ for(i = 0; i < 4; i++) X+ info[i] = (float)cputime[i]; X+#endif X // Calculate CPU stuff X for(i = 0; i < 4; i++) X { X@@ -365,6 +444,13 @@ X } X X // Page In/Out X+#ifdef __FreeBSD__ X+ KGET(X_CNT, sum); X+ pageins = sum.v_vnodepgsin; X+ pageouts = sum.v_vnodepgsout; X+ swapins = sum.v_swappgsin; X+ swapouts = sum.v_swappgsout; X+#endif X if (pageins > last_pageins) X { X DrawLite(B_RED, 5, 48); X@@ -414,12 +500,19 @@ X #ifdef __solaris__ X if (getLoad(&ftmp) != -1) X { X-#else X+#else X+#ifndef __FreeBSD__ X FILE *fp; X if( (fp = fopen("/proc/loadavg", "r")) != NULL) X { X fscanf(fp, "%f", &ftmp); X fclose(fp); X+#else X+ { X+ double avg[1]; X+ getloadavg(avg, 1); X+ ftmp = (float)avg[0]; X+#endif X #endif X if(oldv != ftmp) X { X@@ -540,6 +633,7 @@ X /* Mem/Swap Meter */ X float DrawMemSwap(float total, int allmem) X { X+#ifndef __FreeBSD__ X FILE *fp; X if( (fp = fopen("/proc/meminfo", "r")) != NULL) X { X@@ -553,6 +647,112 @@ X fgets(junk, 80, fp); X fscanf(fp, "Mem: %f %f %f %f %f %f\nSwap: %f %f %f", &total, &used, &freeM, &shared, &buffers, &cached, &swaptotal, &swapused, &swapfreeM); X fclose(fp); X+#else X+ { X+ static float stotal=0.0, sshared=0.0, sbuffers=0.0, scached=0.0; X+ float used, active, inactive, wired, buffers, cached, swaptotal, X+ swapused, shared; X+ unsigned long MEMactive,MEMinactive,MEMwired,MEMbuff,MEMcach, MEMswap; X+ int tempy, tempa; X+ int nswap, nswdev, dmmax; X+ int i, avail, nfree, kmemused, bufspace = 0; X+ struct swdevt *sw; X+ long *perdev; X+ struct vmmeter sum; X+ struct rlist head; X+ struct rlisthdr swaplist; X+ struct rlist *swapptr; X+ u_long ptr; X+ X+ KGET(VM_NSWAP, nswap); X+ KGET(VM_NSWDEV, nswdev); X+ KGET(VM_DMMAX, dmmax); X+ KGET1(VM_SWAPLIST, &swaplist, sizeof swaplist, "swaplist"); X+ if ((sw = (struct swdevt*)malloc(nswdev * sizeof(*sw))) == NULL || X+ (perdev = (long *)malloc(nswdev * sizeof(*perdev))) == NULL) X+ errx(1, "malloc"); X+ KGET1(VM_SWDEVT, &ptr, sizeof ptr, "swdevt"); X+ KGET2(ptr, sw, nswdev * sizeof(*sw), "*swdevt"); X+ X+ /* Count up swap space. */ X+ nfree = 0; X+ memset(perdev, 0, nswdev * sizeof(*perdev)); X+ swapptr = swaplist.rlh_list; X+ while (swapptr) { X+ int top, bottom, next_block; X+ X+ KGET2(swapptr, &head, sizeof(struct rlist), "swapptr"); X+ X+ top = head.rl_end; X+ bottom = head.rl_start; X+ X+ nfree += top - bottom + 1; X+ X+ /* X+ * Swap space is split up among the configured disks. X+ * X+ * For interleaved swap devices, the first dmmax blocks X+ * of swap space some from the first disk, the next dmmax X+ * blocks from the next, and so on up to nswap blocks. X+ * X+ * The list of free space joins adjacent free blocks, X+ * ignoring device boundries. If we want to keep track X+ * of this information per device, we'll just have to X+ * extract it ourselves. X+ */ X+ while (top / dmmax != bottom / dmmax) { X+ next_block = ((bottom + dmmax) / dmmax); X+ perdev[(bottom / dmmax) % nswdev] += X+ next_block * dmmax - bottom; X+ bottom = next_block * dmmax; X+ } X+ perdev[(bottom / dmmax) % nswdev] += X+ top - bottom + 1; X+ X+ swapptr = head.rl_next; X+ } X+ X+ avail = 0; X+ for (i = 0; i < nswdev; i++) { X+ int xsize, xfree; X+ X+ /* X+ * Don't report statistics for partitions which have not X+ * yet been activated via swapon(8). X+ */ X+ if (!(sw[i].sw_flags & SW_FREED)) X+ continue; X+ X+ /* The first dmmax is never allocated to avoid trashing of X+ * disklabels X+ */ X+ xsize = sw[i].sw_nblks - dmmax; X+ xfree = perdev[i]; X+ kmemused = xsize - xfree; X+ avail += xsize; X+ } X+ X+ /* X+ * If only one partition has been set up via swapon(8), we don't X+ * need to bother with totals. X+ */ X+ kmemused = avail - nfree; X+ KGET(X_CNT, sum); X+ KGET(X_BUFSPACE, bufspace); X+ free(sw); X+ free(perdev); X+ X+ total = sum.v_page_size * sum.v_page_count; X+ cached = sum.v_page_size * sum.v_cache_count; X+ used = sum.v_page_size * (sum.v_page_count - sum.v_free_count); X+ buffers = bufspace; X+ active = sum.v_page_size * sum.v_active_count; X+ inactive = sum.v_page_size * sum.v_inactive_count; X+ wired = sum.v_page_size * sum.v_wire_count; X+ X+ swaptotal = avail * 512; X+ swapused = kmemused * 512; X+#endif X X if ( allmem == 1) { X /* All mem areas */ X@@ -561,11 +761,23 @@ X stotal = total; sshared = shared; sbuffers = buffers; scached = cached; X if ( (total/101048576) >= 1) X { X+#ifdef __FreeBSD__ X+ MEMactive=(active/total)*27; X+ MEMinactive=(inactive/total)*27; X+ MEMwired=(wired/total)*27; X+#else X MEMshar=(shared/total)*27; X+#endif X MEMbuff=(buffers/total)*27; X MEMcach=(cached/total)*27; X } else { X+#ifdef __FreeBSD__ X+ MEMactive=(active/total)*33; X+ MEMinactive=(inactive/total)*33; X+ MEMwired=(wired/total)*33; X+#else X MEMshar=(shared/total)*33; X+#endif X MEMbuff=(buffers/total)*33; X MEMcach=(cached/total)*33; X } X@@ -579,9 +791,15 @@ X copyXPMArea(3,75,((used/total)*34),9,5,19); X } X // Separators X+#ifdef __FreeBSD__ X+ copyXPMArea(15,105,1,9,5+MEMactive,19); X+ copyXPMArea(15,105,1,9,6+MEMactive+MEMinactive,19); X+ copyXPMArea(15,105,1,9,7+MEMactive+MEMinactive+MEMwired,19); X+#else X copyXPMArea(15,105,1,9,5+MEMshar,19); X copyXPMArea(15,105,1,9,7+MEMshar+MEMbuff,19); X copyXPMArea(15,105,(36-(used/total)*34),9,(5+(used/total)*34),19); X+#endif X // Numbers X tempa=used/1048576; X tempy=tempa%10; X@@ -601,6 +819,16 @@ X if(stotal != total || sshared != shared) X { X stotal = total; sshared = shared; sbuffers = buffers; scached = cached; X+#ifdef __FreeBSD__ X+ if ( (total/101048576) >= 1) { X+ MEMactive=(active/total)*27; X+ } else { X+ MEMactive=(active/total)*35; X+ } X+ // Bar X+ copyXPMArea(3,75,MEMactive,9,5,19); X+ copyXPMArea(3,102,(36-(active/total)*36),9,(5+(active/total)*36),19) ; X+#else X if ( (total/101048576) >= 1) { X MEMshar=(shared/total)*27; X } else { X@@ -609,8 +837,13 @@ X // Bar X copyXPMArea(3,75,MEMshar,9,5,19); X copyXPMArea(15,105,(36-(shared/total)*36),9,(5+(shared/total)*36),19); X+#endif X // Numbers X+#ifdef __FreeBSD__ X+ tempa=active/1048576; X+#else X tempa=shared/1048576; X+#endif X tempy=tempa%10; X copyXPMArea(3+(tempy*6),66,6,9,50,19); X tempy=(tempa/10)%10; X@@ -662,10 +895,11 @@ X /* X Mem Usage */ X void DrawXmem(int Xpid, float total) X { X- FILE *fp; X- char buf[128], XFileName[256]; X float ratio; X long old_Xsize=-1, Xsize=0; X+#ifndef __FreeBSD__ X+ FILE *fp; X+ char buf[128], XFileName[256]; X X sprintf(XFileName, "/proc/%d/status", Xpid); X X@@ -676,6 +910,15 @@ X if (strstr(buf, "VmSize")) X sscanf(buf, "VmSize: %ld", &Xsize); X } X+#else X+ { X+ struct kinfo_proc *kproc; X+ int kcnt; X+ X+ kproc = kvm_getprocs(kd, KERN_PROC_PID, Xpid, &kcnt); X+ X+ Xsize = kproc->kp_eproc.e_vm.vm_map.size / 1024; X+#endif X if(old_Xsize!=Xsize) X { X int tempy, tempa; X@@ -692,7 +935,9 @@ X copyXPMArea(3,84,((ratio)*22),11,18,47); X copyXPMArea(15,105,(23-((ratio)*22)),11,(18+(ratio*22)),47); X } X+#ifndef __FreeBSD__ X fclose(fp); X+#endif X } X } X X@@ -713,10 +958,28 @@ X pUtmp = getutid(&idUtmp); X upt = (time(0) - pUtmp->ut_time); X #else X+#ifndef __FreeBSD__ X FILE *fp; X if( (fp = fopen("/proc/uptime", "r")) != NULL) X fscanf(fp, "%d",&upt); X fclose(fp); X+#else X+ int mib[2]; X+ struct timeval boottime; X+ size_t bt_size; X+ X+ bt_size = sizeof(boottime); X+ mib[0] = CTL_KERN; X+ mib[1] = KERN_BOOTTIME; X+ X+ if (sysctl(mib, 2, &boottime, &bt_size, NULL, 0) != -1 && X+ boottime.tv_sec != 0) { X+ upt = time(NULL) - boottime.tv_sec; X+ upt += 30; /* top(1) does this ???? */ X+ } else { X+ upt = 0; X+ } X+#endif X #endif X mins=(upt/60)%60; X hours=(upt/3600)%24; X@@ -777,6 +1040,31 @@ X break; X } X X+} X+ X+void X+open_kvm() X+{ X+ if (kd == 0) { X+ kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, 0); X+ if (kd != NULL) { X+ if (kvm_nlist(kd, nl) < 0) { X+ errx(1, "kvm_nlist: %s", kvm_geterr(kd)); X+ } X+ if (nl[0].n_type == 0) { X+ errx(1, "no namelist"); X+ } X+ } else { X+ warnx("kvm not available"); X+ } X+ } X+} X+ X+void X+close_kvm() X+{ X+ kvm_close(kd); X+ kd = NULL; X } X X /* EOF */ END-of-asmon/patches/patch-ab echo x - asmon/patches/patch-aa sed 's/^X//' >asmon/patches/patch-aa << 'END-of-asmon/patches/patch-aa' X*** Makefile.orig Tue Jun 8 15:54:04 1999 X--- Makefile Tue Jun 8 15:54:36 1999 X*************** X*** 0 **** X--- 1,20 ---- X+ LIBDIR = -L/usr/X11R6/lib X+ LIBS = -lXpm -lXext -lX11 -lkvm X+ OBJS = asmon/asmon.o \ X+ wmgeneral/wmgeneral.o \ X+ wmgeneral/misc.o \ X+ wmgeneral/list.o X+ X+ all: asmon X+ X+ .c.o: X+ cc -c -Wall -I/usr/X11R6/include $< -o $*.o X+ X+ asmon: $(OBJS) X+ cc -o asmon/asmon $^ $(LIBDIR) $(LIBS) X+ X+ clean:: X+ for i in $(OBJS) ; do \ X+ rm $$i;\ X+ done X+ rm asmon/asmon END-of-asmon/patches/patch-aa echo c - asmon/files mkdir -p asmon/files > /dev/null 2>&1 echo x - asmon/files/md5 sed 's/^X//' >asmon/files/md5 << 'END-of-asmon/files/md5' XMD5 (asmon-0.60.tar.gz) = d33e59597f56368f180ca1b4b4c126e8 END-of-asmon/files/md5 echo x - asmon/Makefile sed 's/^X//' >asmon/Makefile << 'END-of-asmon/Makefile' X# New ports collection makefile for: asfsm X# Version required: asmon-0.60 X# Date created: 27 Sep 1999 X# Whom: jack X# X XDISTNAME= asmon-0.60 XCATEGORIES= sysutils afterstep XMASTER_SITES= ftp://ftp.afterstep.org/apps/asmem/ \ X http://www.tigr.net/afterstep/as-apps/download/asmon/ X XMAINTAINER= jack@germanium.xtalwind.net X XLIB_DEPENDS= Xpm.4:${PORTSDIR}/graphics/xpm X X.include <bsd.port.pre.mk> X.if ${OSVERSION} >= 400000 XBROKEN= 'Sorry, asmom can't (yet) handle 4.0+ new VM system interfaces' X.endif X XUSE_X_PREFIX= yes XUSE_GMAKE= yes X X# Clean the cruft out of the distibution :( Xpre-build: X @(cd ${WRKSRC}; ${GMAKE} ${MAKEFILE} clean) X Xdo-install: X ${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g kmem -m 2755 ${WRKSRC}/asmon/asmon ${PREFIX}/bin X X.include <bsd.port.mk> END-of-asmon/Makefile exit >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909280103.VAA19388>