From 918aa403396d214b68f49ea854d2b31a2a810d14 Mon Sep 17 00:00:00 2001 From: Bart Riemens Date: Sat, 27 Jul 2019 21:46:03 +0300 Subject: [PATCH] Altered version of the sys-mon-set widgets with more padding - Link to original version: http://tracesof.net/uebersicht-widgets/#sys-mon-set --- README.md | 5 + battery.widget/index.coffee | 27 +++++ mini-top-mem.widget/index.coffee | 47 +++++++++ netstat.widget/index.coffee | 54 ++++++++++ netstat.widget/scripts/netst | Bin 0 -> 9312 bytes netstat.widget/scripts/netst.c | 166 +++++++++++++++++++++++++++++++ public_ip.widget/index.coffee | 26 +++++ simple-clock.widget/index.coffee | 23 +++++ top-cpu.widget/index.coffee | 69 +++++++++++++ total-mem.widget/index.coffee | 74 ++++++++++++++ 10 files changed, 491 insertions(+) create mode 100644 README.md create mode 100644 battery.widget/index.coffee create mode 100644 mini-top-mem.widget/index.coffee create mode 100644 netstat.widget/index.coffee create mode 100755 netstat.widget/scripts/netst create mode 100644 netstat.widget/scripts/netst.c create mode 100644 public_ip.widget/index.coffee create mode 100644 simple-clock.widget/index.coffee create mode 100644 top-cpu.widget/index.coffee create mode 100644 total-mem.widget/index.coffee diff --git a/README.md b/README.md new file mode 100644 index 0000000..ce02e0f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Credits + +Authors of the various widgets include: + +George Irwin, mfam, Aliceljm, Johan Bleuzen, Spencer Oberstadt, Felix Hageloh diff --git a/battery.widget/index.coffee b/battery.widget/index.coffee new file mode 100644 index 0000000..01a3d96 --- /dev/null +++ b/battery.widget/index.coffee @@ -0,0 +1,27 @@ +command: "pmset -g batt | grep -o '[0-9]*%'" + +refreshFrequency: 60000 + +style: """ + bottom: 135px + left: 10px + color: #ccc + font-family: Helvetica Neue + + div + display: block + text-shadow: 0 0 1px rgba(#000, 0.5) + font-size: 24px + font-weight: 100 + + +""" + + +render: -> """ +
+""" + +update: (output, domEl) -> + $(domEl).find('.battery').html(output) + diff --git a/mini-top-mem.widget/index.coffee b/mini-top-mem.widget/index.coffee new file mode 100644 index 0000000..6eb4d43 --- /dev/null +++ b/mini-top-mem.widget/index.coffee @@ -0,0 +1,47 @@ +command: "ps axo \"rss,pid,ucomm\" | sort -nr | head -n3 | awk '{printf \"%8.0f,%s,%s\\n\", $1/1024, $3, $2}'" + +refreshFrequency: 5000 + +style: """ + bottom: 10px + left: 590px + color: #ccc + font-family: Helvetica Neue + + table + border-collapse: collapse + table-layout: fixed + margin-bottom: 4px + + td + font-size: 10px + font-weight: normal + width: 80px + max-width: 80px + overflow: ellipsis + text-shadow: 0 0 1px rgba(#000, 0.5) + + +""" + + +render: -> + """ + + + + +
+""" + +update: (output, domEl) -> + processes = output.split('\n') + table = $(domEl).find('table') + + renderProcess = (mem, name) -> + "#{name}#{mem} MB" + + for process, i in processes + args = process.split(',') + table.find("#row-#{i+1}").html renderProcess(args...) + diff --git a/netstat.widget/index.coffee b/netstat.widget/index.coffee new file mode 100644 index 0000000..1d7e8c0 --- /dev/null +++ b/netstat.widget/index.coffee @@ -0,0 +1,54 @@ +command: "sys-mon-set.widget/netstat.widget/scripts/netst" + +refreshFrequency: 1000 + +style: """ + bottom: 180px + left: 15px + color: #ccc + font-family: Helvetica Neue + + div + display: block + text-shadow: 0 0 1px rgba(#000, 0.5) + font-size: 16px + font-weight: 100 + + p + margin: 5px 0 0 0 + + p > span + font-weight: normal + + +""" + + +render: -> """ +
+

In:

+

Out:

+
+""" + + +update: (output, domEl) -> + bytesToSize = (bytes) -> + return "0 Byte" if parseInt(bytes) is 0 + k = 1024 + sizes = [ + "b/s" + "kb/s" + "mb/s" + "gb/s" + "gb/s" + "pb/s" + "eb/s" + "zb/s" + "yb/s" + ] + i = Math.floor(Math.log(bytes) / Math.log(k)) + (bytes / Math.pow(k, i)).toPrecision(3) + " " + sizes[i] + values = output.split(' ') + $(domEl).find('#in').text(bytesToSize(values[0])) + $(domEl).find('#out').text(bytesToSize(values[1])) diff --git a/netstat.widget/scripts/netst b/netstat.widget/scripts/netst new file mode 100755 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WZ5O-ACNB#Bt(I5SJwGIB_ZB9w+WG;vOaLN#gbqcY-)d zICqP#xSN}(S+6UslRgxDLwgLJ`L>K0n$AkfI<`&7xAj@_Mr&jwl2p)Xy`)WLxQ=PD zCZ-!3!yB2K5Y!a6UdN(=NF*Lq1_I%T)(^+ZOCT|rjA}7M-&j}M zXei5TYrDfy%`))yKtwU(N-!QBN*dbTO20M`NJb3h9!1xJ@mN3o-mYy7E1SXtF+A73 zwZ77{gi8Z-va$-kuA=^WZEY7m=nN$h*sJJ90HHuZYKY&dL={vj3M$r){jSI9pzqjL z@KhheHzO6|k$U)TITyeEXe47N<}e5CeiR}2gkS+4+Rhxq^^W?5^J{WeSE;!%$;{ZNq0$l8i8sA zsu8G0pc;W{1ga7EUqql`nergnX=vkg6&?ug;la=zK9~$7`q_Pn`dk~24;eTmVYxQC z9uwE)ybm|XxZWO}#0ifmj+}HRq1Y_ZsSC@o#A+!|#DYU3GzSTrAPgAsF!8P6wc)Tq zd>iGAhk|;2=xLD(Gkl4p%9@YPFcVYf!8CN zHbh{Uz=$3+$Uo-bxKo_Rqaiq<1##YkJNy7WGl84bx#?x&8?o zrX#>|{r7D6M>hPT4WF^$U)k{QZTJs1JZZyu8>ahWx=W_G(=i&3p~U?$MX&*N2`Vkx zQdC-tPokoaR*)VZlI{4{0HGwbyWZW literal 0 HcmV?d00001 diff --git a/netstat.widget/scripts/netst.c b/netstat.widget/scripts/netst.c new file mode 100644 index 0000000..884df23 --- /dev/null +++ b/netstat.widget/scripts/netst.c @@ -0,0 +1,166 @@ +/* + * Print interface statistics in bytes per second + * + * Parameters: + * -t # Time interval to compute, default 2 seconds + * -i Interface name, defaults to 'en0' + * -s Print raw stats + * + * Output: Two numbers separated by a space. First value is input bytes per + * second. Second value is output bytes per second + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static u_int64_t opackets = 0; +static u_int64_t ipackets = 0; +static u_int64_t obytes = 0; +static u_int64_t ibytes = 0; +static int raw_stats = 0; + +int +get_stats(char *interface) +{ + int ret = 0; + char name [32]; + int mib [6]; + char *buf = NULL, *lim, *next; + size_t len; + struct if_msghdr *ifm; + unsigned int ifindex = 0; + + if (interface != 0) + ifindex = if_nametoindex(interface); + + mib[0] = CTL_NET; + mib[1] = PF_ROUTE; + mib[2] = 0; + mib[3] = 0; + mib[4] = NET_RT_IFLIST2; + mib[5] = 0; + + if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) + return ret; + if ((buf = malloc(len)) == NULL) { + printf("malloc failed\n"); + exit(1); + } + if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { + if (buf) + free(buf); + return ret; + } + lim = buf + len; + for (next = buf; next < lim;) { + ifm = (struct if_msghdr *)next; + next += ifm->ifm_msglen; + + if (ifm->ifm_type == RTM_IFINFO2) { + struct if_msghdr2 *if2m = (struct if_msghdr2 *)ifm; + struct sockaddr_dl *sdl = (struct sockaddr_dl *)(if2m + 1); + + strncpy(name, sdl->sdl_data, sdl->sdl_nlen); + name[sdl->sdl_nlen] = 0; + if (interface != 0 && if2m->ifm_index != ifindex) + continue; + + /* + * Get the interface stats. These may get overriden + * below on a per-interface basis. + */ + opackets = if2m->ifm_data.ifi_opackets; + ipackets = if2m->ifm_data.ifi_ipackets; + obytes = if2m->ifm_data.ifi_obytes; + ibytes = if2m->ifm_data.ifi_ibytes; + if (ret == 0) { + ret = 1; + if (raw_stats) { + printf("%5s %10s %14s ", + "Name", "Ipkts", "IBytes"); + printf("%10s %14s\n", "Opkts", "Obytes"); + } + } + if (raw_stats) { + printf("%-5s %10llu ", name, ipackets); + printf("%14llu ", ibytes); + printf("%10llu ", opackets); + printf("%14llu\n", obytes); + } + } + } + + free(buf); + + return ret; +} + +void +usage(void) +{ + printf("arguments:\n\t-t #\t\tTime interval to compute, default 2 seconds\n"); + printf("\t-i \tInterface name, defaults to 'en0'\n"); + printf("\t-s\t\tPrint raw stats\n"); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + char *ifname = "en0"; + int r; + int sleeptime = 2; + + int bflag , ch, fd; + + bflag = 0; + while ((ch = getopt(argc, argv, "st:i:")) != -1) { + switch (ch) { + case 't': + sleeptime = atoi(optarg); + if (sleeptime < 1) { + sleeptime = 1; + } + break; + case 'i': + ifname = optarg; + break; + case 's': + raw_stats = 1; + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + r = get_stats(ifname); + if (r) { + u_int64_t ib = ibytes; + u_int64_t ob = obytes; + u_int64_t diffo, diffi; + + sleep(sleeptime); + get_stats(ifname); + diffo = (obytes - ob) / (u_int64_t) sleeptime; + diffi = (ibytes - ib) / (u_int64_t) sleeptime; + printf("%llu %llu\n", diffi, diffo); + } else { + printf("No interface %s\n", ifname); + } +} diff --git a/public_ip.widget/index.coffee b/public_ip.widget/index.coffee new file mode 100644 index 0000000..4b60ab7 --- /dev/null +++ b/public_ip.widget/index.coffee @@ -0,0 +1,26 @@ +command: "curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'" + +refreshFrequency: 43200000 + +style: """ + bottom: 135px + left: 90px + color: #ccc + font-family: Helvetica Neue + + div + display: block + text-shadow: 0 0 1px rgba(#000, 0.5) + font-size: 24px + font-weight: 100 + +""" + + +render: -> """ +
+""" + +update: (output, domEl) -> + $(domEl).find('.ip_address').html(output) + diff --git a/simple-clock.widget/index.coffee b/simple-clock.widget/index.coffee new file mode 100644 index 0000000..06ae47e --- /dev/null +++ b/simple-clock.widget/index.coffee @@ -0,0 +1,23 @@ +format = '%d %a %H:%M' + +command: "date +\"#{format}\"" + +# the refresh frequency in milliseconds +refreshFrequency: 30000 + +render: (output) -> """ +

#{output}

+""" + +style: """ + color: #eee + font-family: Helvetica Neue + left: 10px + bottom: 50px + + h1 + font-size: 5em + font-weight: 100 + margin: 0 + padding: 0 + """ diff --git a/top-cpu.widget/index.coffee b/top-cpu.widget/index.coffee new file mode 100644 index 0000000..82b937d --- /dev/null +++ b/top-cpu.widget/index.coffee @@ -0,0 +1,69 @@ +command: "ps axro \"pid, %cpu, ucomm\" | awk 'FNR>1' | head -n 3 | awk '{ printf \"%5.1f%%,%s,%s\\n\", $2, $3, $1}'" + +refreshFrequency: 2000 + +style: """ + bottom: 10px + left: 10px + color: #ccc + font-family: Helvetica Neue + + table + border-collapse: collapse + table-layout: fixed + + td + font-size: 24px + font-weight: 100 + width: 100px + max-width: 100px + overflow: ellipsis + text-shadow: 0 0 1px rgba(#000, 0.5) + + .wrapper + padding: 4px 6px 4px 6px + position: relative + + p + padding: 0 + margin: 0 + font-size: 11px + font-weight: normal + max-width: 100% + color: #ddd + text-overflow: ellipsis + text-shadow: none + + .pid + position: absolute + top: 2px + right: 2px + font-size: 10px + font-weight: normal + +""" + + +render: -> """ + + + + + + +
+""" + +update: (output, domEl) -> + processes = output.split('\n') + table = $(domEl).find('table') + + renderProcess = (cpu, name, id) -> + "
" + + "#{cpu}

#{name}

" + + "
" + + for process, i in processes + args = process.split(',') + table.find(".col#{i+1}").html renderProcess(args...) + diff --git a/total-mem.widget/index.coffee b/total-mem.widget/index.coffee new file mode 100644 index 0000000..e43e551 --- /dev/null +++ b/total-mem.widget/index.coffee @@ -0,0 +1,74 @@ +# vm_stat returns pages (4096 bytes on mac). 256 pages per MB. +# To convert pages to GB: no. of pages / 256 / 1024 + +command: "vm_stat | awk 'NR==2 {print \"Free,\"($3 / 256) / 1024} NR==3 {print \"Active,\"($3 / 256) / 1024} NR==4 {print \"Inactive,\"($3 / 256) / 1024} NR==7 {print \"Wired,\"($4 / 256) / 1024}'" + +refreshFrequency: 1000 + +style: """ + bottom: 10px + left: 310px + color: #bbb + font-family: Helvetica Neue + + table + border-collapse: collapse + table-layout: fixed + + td + font-size: 24px + font-weight: 100 + width: 70px + max-width: 70px + overflow: hidden + text-shadow: 0 0 1px rgba(#000, 0.5) + + .wrapper + padding: 4px 6px 4px 6px + position: relative + + + p + padding: 0 + margin: 0 + font-size: 11px + font-weight: normal + max-width: 100% + color: #ddd + text-overflow: ellipsis + + .pid + position: absolute + top: 2px + right: 2px + font-size: 10px + font-weight: normal + +""" + + +render: -> + """ + + + + + + + +
+""" + +update: (output, domEl) -> + processes = output.split('\n') + table = $(domEl).find('table') + + renderProcess = (type, mem) -> + "
" + + "#{Math.round(mem * 100) / 100}

#{type}

" + + "
" + + for process, i in processes + args = process.split(',') + table.find(".col#{i+1}").html renderProcess(args...) +