Trying to parse key value log lines in go

I want to build a honeytail parser that will take log lines that look like

key1=val1 key2=val2 key3=val3...

There are a few additional constraints

  • if the value is quoted, I'd like it to have the quotes stripped
  • if the value has an equals sign in it, that's cool
  • if the value is multiple words, that's fine even if it's not quoted.  (I won't go so far as to say that unquoted space separated strings should be allowed to have equals signs embedded.)

I found a library on the net to do this: github.com/kr/logfmt.

Here is the code playing with it

Unfortunately, it had a few other ideas.

  • a bare word (no equals sign attached) should be treated as a key with no value
  • equals signs embedded in strings should be treated as separators
You can see these rules coming through in test cases 2 and 4 in the output

Ah well.  It was an interesting attempt.

(one test case that's missing: does a number in quotes turn in to a number (float or int) or stay a string?)


Working with ulimits and open file descriptors

Yet another in the long list of things I always forget how to do between needing to do them...

Cheatsheet to working with ulimits and too many open files.
list how many open file descriptors a process has
lsof -P [pid] | wc -l
ls /proc/[pid]/fd | wc -l (cheaper)
look at limits for a specific process
cat /proc/[pid]/limits
set limits for a user
futz with /etc/security/limits.conf or /etc/security/limits.d/*
show ulimits for the current process
ulimit -a
set number of open file handle limit for the current process (and processes spawned from this one)
ulimit -n 16384 (note - only root can raise hard limits)
Hope that helps, future self.