File Info: 11Min, 5MB.
Ogg link: http://cis01.uma.edu/~wbackman/bsdtalk/bsdtalk226.ogg
This is a bunch of links to the tools I talk about in my presenation
Tools:
Collectd: https://collectd.org/
Graphite: http://graphite.wikidot.com/
Nagios: http://www.nagios.org/
Poudriere: http://fossil.etoilebsd.net/poudriere
Config Management:
Salt Stack: http://saltstack.com/
Chef: http://www.opscode.com/chef/
Puppet: http://puppetlabs.com/
Subversion: http://subversion.apache.org/
LogStash: http://logstash.net/
Audit: http://www.freebsd.org/handbook/audit.html
CARP: http://www.freebsd.org/handbook/carp.html
OATH: http://www.openauthentication.org/
Serial Console: http://www.freebsd.org/handbook/serialconsole-setup.html
Generic Resources:
FreeBSD Handbook: http://freebsd.org/handbook
Everything Sysadmin Blog: http://everythingsysadmin.com/resources.html
It's that time of the year again - time for the biggest, bestest gathering of BSD geeks from around the world - BSDCan 2013. It was great to see old friends and new faces, exchange ideas and talk about the bright future.
Regular expressions are a powerful text transformation tool. Any UNIX geek will tell you that. It’s so deeply ingrained into our culture, that we even make jokes about it. Another thing that we also love is having a powerful extension language at hand, and Lisp is one of the most powerful extension languages around (and of course, we make jokes about that too).
Emacs, one of the most famous Lisp applications today, has for a while now the ability to combine both of these, to reach entirely new levels of usefulness. Combining regular expressions and Lisp can do really magical things.
An example that I recently used a few times is parsing & de-humanizing numbers in dstat output. The output of dstat includes numbers that are printed with a suffix, like ‘B’ for bytes, ‘k’ for kilobytes and ‘M’ for megabytes, e.g.:
----system---- ----total-cpu-usage---- --net/eth0- -dsk/total- sda-
time |usr sys idl wai hiq siq| recv send| read writ|util
16-05 08:36:15| 2 3 96 0 0 0| 66B 178B| 0 0 | 0
16-05 08:36:16| 42 14 37 0 0 7| 92M 1268k| 0 0 | 0
16-05 08:36:17| 45 11 36 0 0 7| 76M 1135k| 0 0 | 0
16-05 08:36:18| 27 55 8 0 0 11| 67M 754k| 0 99M|79.6
16-05 08:36:19| 29 41 16 5 0 10| 113M 2079k|4096B 63M|59.6
16-05 08:36:20| 28 48 12 4 0 8| 58M 397k| 0 95M|76.0
16-05 08:36:21| 38 37 14 1 0 10| 114M 2620k|4096B 52M|23.2
16-05 08:36:22| 37 54 0 1 0 8| 76M 1506k|8192B 76M|33.6
So if you want to graph one of the columns, it’s useful to convert all the numbers in the same unit. Bytes would be nice in this case.
Separating all columns with ‘|’ characters is a good start, so you can use e.g. a CSV-capable graphing tool, or even simple awk scripts to extract a specific column. ‘C-x r t’ can do that in Emacs, and you end up with something like this:
| time |cpu|cpu|cpu|cpu|cpu|cpu|eth0 |eth0 | disk| disk|sda-| | time |usr|sys|idl|wai|hiq|siq| recv| send| read| writ|util| |16-05 08:36:15| 2| 3| 96| 0| 0| 0| 66B| 178B| 0 | 0 | 0| |16-05 08:36:16| 42| 14| 37| 0| 0| 7| 92M|1268k| 0 | 0 | 0| |16-05 08:36:17| 45| 11| 36| 0| 0| 7| 76M|1135k| 0 | 0 | 0| |16-05 08:36:18| 27| 55| 8| 0| 0| 11| 67M| 754k| 0 | 99M|79.6| |16-05 08:36:19| 29| 41| 16| 5| 0| 10| 113M|2079k|4096B| 63M|59.6| |16-05 08:36:20| 28| 48| 12| 4| 0| 8| 58M| 397k| 0 | 95M|76.0| |16-05 08:36:21| 38| 37| 14| 1| 0| 10| 114M|2620k|4096B| 52M|23.2| |16-05 08:36:22| 37| 54| 0| 1| 0| 8| 76M|1506k|8192B| 76M|33.6|
The leading and trailing ‘|’ characters are there so we can later use orgtbl-mode, an awesome table editing and realignment tool of Emacs. Now to the really magical step: regular expressions and lisp working together.
What we would like to do is convert text like “408B” to just “408″, text like “1268k” to the value of (1268 * 1024), and finally text like “67M” to the value of (67 * 1024 * 1024). The first part is easy:
M-x replace-regexp RET \([0-9]+\)B RET \1 RET
This should just strip the “B” suffix from byte values.
For the kilobyte and megabyte values what we would like is to be able to evaluate an arithmetic expression that involves \1. Something like “replace \1 with the value of (expression \1)“. This is possible in Emacs by prefixing the substitution pattern with \,. This instructs Emacs to evaluate the rest of the substitution pattern as a Lisp expression, and use its string representation as the “real” substitution text.
So if we match all numeric values that are suffixed by ‘k’, we can use (string-to-number \1) to convert the matching digits to an integer, multiply by 1024 and insert the resulting value by using the following substitution pattern:
\,(* 1024 (string-to-number \1))
The full Emacs command would then become:
M-x replace-regexp RET \([0-9]+\)k RET \,(* 1024 (string-to-number \1)) RET
This, and the byte suffix removal, yield now the following text in our Emacs buffer:
| time |cpu|cpu|cpu|cpu|cpu|cpu|eth0 |eth0 | disk| disk|sda-| | time |usr|sys|idl|wai|hiq|siq| recv| send| read| writ|util| |16-05 08:36:15| 2| 3| 96| 0| 0| 0| 66| 178| 0 | 0 | 0| |16-05 08:36:16| 42| 14| 37| 0| 0| 7| 92M|1298432| 0 | 0 | 0| |16-05 08:36:17| 45| 11| 36| 0| 0| 7| 76M|1162240| 0 | 0 | 0| |16-05 08:36:18| 27| 55| 8| 0| 0| 11| 67M| 772096| 0 | 99M|79.6| |16-05 08:36:19| 29| 41| 16| 5| 0| 10| 113M|2128896|4096| 63M|59.6| |16-05 08:36:20| 28| 48| 12| 4| 0| 8| 58M| 406528| 0 | 95M|76.0| |16-05 08:36:21| 38| 37| 14| 1| 0| 10| 114M|2682880|4096| 52M|23.2| |16-05 08:36:22| 37| 54| 0| 1| 0| 8| 76M|1542144|8192| 76M|33.6|
Note: Some of the columns are indeed not aligned very well. We’ll fix that later. On to the megabyte conversion:
M-x replace-regexp RET \([0-9]+\)M RET \,(* 1024 1024 (string-to-number \1)) RET
Which produces a version that has no suffixes at all:
| time |cpu|cpu|cpu|cpu|cpu|cpu|eth0 |eth0 | disk| disk|sda-| | time |usr|sys|idl|wai|hiq|siq| recv| send| read| writ|util| |16-05 08:36:15| 2| 3| 96| 0| 0| 0| 66| 178| 0 | 0 | 0| |16-05 08:36:16| 42| 14| 37| 0| 0| 7| 96468992|1298432| 0 | 0 | 0| |16-05 08:36:17| 45| 11| 36| 0| 0| 7| 79691776|1162240| 0 | 0 | 0| |16-05 08:36:18| 27| 55| 8| 0| 0| 11| 70254592| 772096| 0 | 103809024|79.6| |16-05 08:36:19| 29| 41| 16| 5| 0| 10| 118489088|2128896|4096| 66060288|59.6| |16-05 08:36:20| 28| 48| 12| 4| 0| 8| 60817408| 406528| 0 | 99614720|76.0| |16-05 08:36:21| 38| 37| 14| 1| 0| 10| 119537664|2682880|4096| 54525952|23.2| |16-05 08:36:22| 37| 54| 0| 1| 0| 8| 79691776|1542144|8192| 79691776|33.6|
Finally, to align everything in neat, pipe-separated columns, we enable M-x orgtbl-mode, and type “C-c C-c” with the pointer somewhere inside the transformed dstat output. The buffer now becomes something usable for pretty-much any graphing tool out there:
| time | cpu | cpu | cpu | cpu | cpu | cpu | eth0 | eth0 | disk | disk | sda- | | time | usr | sys | idl | wai | hiq | siq | recv | send | read | writ | util | | 16-05 08:36:15 | 2 | 3 | 96 | 0 | 0 | 0 | 66 | 178 | 0 | 0 | 0 | | 16-05 08:36:16 | 42 | 14 | 37 | 0 | 0 | 7 | 96468992 | 1298432 | 0 | 0 | 0 | | 16-05 08:36:17 | 45 | 11 | 36 | 0 | 0 | 7 | 79691776 | 1162240 | 0 | 0 | 0 | | 16-05 08:36:18 | 27 | 55 | 8 | 0 | 0 | 11 | 70254592 | 772096 | 0 | 103809024 | 79.6 | | 16-05 08:36:19 | 29 | 41 | 16 | 5 | 0 | 10 | 118489088 | 2128896 | 4096 | 66060288 | 59.6 | | 16-05 08:36:20 | 28 | 48 | 12 | 4 | 0 | 8 | 60817408 | 406528 | 0 | 99614720 | 76.0 | | 16-05 08:36:21 | 38 | 37 | 14 | 1 | 0 | 10 | 119537664 | 2682880 | 4096 | 54525952 | 23.2 | | 16-05 08:36:22 | 37 | 54 | 0 | 1 | 0 | 8 | 79691776 | 1542144 | 8192 | 79691776 | 33.6 |
The trick of combining arbitrary Lisp expressions with regexp substitution patterns like \1, \2 … \9 is something I have found immensely useful in Emacs. Now that you know how it works, I hope you can find even more amusing use-cases for it.
Update: The Emacs manual has a few more useful examples of \, in action, as pointed out by tunixman on Twitter.
I’m trying to wrap up some project I started working on quite some time ago and this is first chunk of clean-up.
Patch contains:
I tested it only on evaluation module, although I think with proper panel/pinmux configuration it should work with BeagleBone’s LCD caps too.
Parts missing: adjusting clock to proper pixel frequency, proper allocation of framebuffer memory.
Writing new driver for FDT-based device always involves several simple steps:
I can’t say for other developers but I just copy existing driver, remove all device-specific stuff and rewrite generic stuff. Which is less time-consuming then writing it from scratch but time-consuming it is. Being huge fan of automation of any kind I decided to let computer do all this dumb work and leave creative part (copy-pasting registers definition from spec to code) to myself. the result is this script.
Developer feeds driver description in YAML format to the script and gets driver skeleton that requires minimal amount of editing to get it compiled. Driver description includes author name, prefix for macroses, prefix for newbus method-functions, FDT compatibility string, driver name and number of IRQ/MEMORY resources. A minute saved is a minute earned.
YAML example:
AUTHOR: Oleksandr Tymoshenko <[email protected]> PREFIX: am335x_pwm MACRO_PREFIX: PWM DRIVER: am335x_pwm FDT_COMPATIBLE: ti,am335x-pwm IRQ_RESOURCES: 0 MEM_RESOURCES: 4
LinuxFest NorthWest will be held April 27-28 at Bellingham Technical College in Bellingham, WA. This event is free to attend.
We’ll be giving out cool swag, PC-BSD DVDs, and FreeNAS CDs at the FreeBSD booth in the expo area. If you are attending the event, drop by and say hi.
Last week, Kris announced on the developers mailing list that the PC-BSD source repo has switched from subversion to github.
For those of you who like to compile new features in order to test them before they are incorporated into a release or a rolling release, the instructions for getting source have been updated. Any references to svn in the wiki version of the Handbook will also be switched to the git equivalent. If you have installed subversion before from System Manager -> System Packages -> Development -> Development VCS, you already have git as it is included in that meta-package.