Debian Codegraph @

README.md

raw
1 # Nerdlog
2
3 ![Nerdlog](https://dmitryfrank.com/_media/projects/nerdlog/nerdlog_intro_3.png)
4
5 Nerdlog is a fast, remote-first, multi-host TUI log viewer with timeline
6 histogram and no central server. Loosely inspired by Graylog/Kibana, but
7 without the bloat. Pretty much no setup needed, either.
8
9 It's laser-focused on being efficient while querying logs from multiple remote
10 machines simultaneously, filtering them by time range and patterns, while also
11 drawing an interactive timeline histogram for quick visual insight.
12
13 Primary use case: reading system logs (from the files `/var/log/messages` or
14 `/var/log/syslog`, or straight from `journalctl`) from one or more remote
15 hosts. Very efficient even on large log files (like 1GB or more).
16
17 It does support some other log formats and can use any log files, but that was the primary use case which was driving the implementation: we were having our web service backend running as systemd services on a bunch of Linux instances, printing a lot of logs, and wanted to be able to read these logs efficiently and having the timeline histogram, much like tools like Graylog have.
18
19 ## Design highlights
20
21 - No centralized server required; nerdlog establishes an ssh connection to
22 every node that the user wants to collect logs from, and keeps them idle in
23 the background (although a separate server to store the log files might still
24 help in some cases; see the [Limitations](./docs/limitations.md) section in
25 the docs);
26 - Logs are not downloaded to the local machine in full: all the log analysis
27 is done on the remote nodes, and on each query, only the following data is
28 downloaded from each node: up to 250 messages from every logstream
29 (configurable), and data for the timeline histogram. It's obviously possible
30 to paginate over the logs, to get the next bunch of messages, etc. Nerdlog
31 then merges the responses from all nodes together, and presents to the user
32 in a unified form;
33 - Most of the data is gzipped in transit, thus saving the bandwidth as well.
34
35 ## Demo
36
37 Here’s a quick demo showing how Nerdlog works across four remote nodes:
38
39 ![Nerdlog](https://dmitryfrank.com/_media/projects/nerdlog/nerdlog_demo.gif?v=2)
40
41 ## Project history
42
43 It might be useful to know the history to understand the project motivation and
44 overall direction, you can read it in the article:
45 [Implementing a Radically Simple Alternative to Graylog](https://dmitryfrank.com/projects/nerdlog/article).
46
47 ## Project state
48
49 Originally hacked together in 2022 to replace painfully slow Splunk setups.
50 Revisited in 2025 to clean it up to a certain extent, and open source it.
51
52 Tested on various Linux distros, FreeBSD, MacOS and Windows (only the client
53 app can run on Windows though, we can't get logs from Windows hosts).
54
55 The code still has some traces of the hackathon style here and there, and could be more polished, but overall it matured significantly. There are [decent tests](./docs/tests.md) as well.
56
57 I've been using it at work and for my personal projects for a few years now, and I consider it ready to be used in the wild on production systems.
58
59 ## Installation
60
61 The easiest is to just use a prebuilt binary for your platform, see the
62 [releases page](https://github.com/dimonomid/nerdlog/releases).
63
64 To build it from source, you need [Go](https://go.dev/).
65
66 Also on Linux, the X11 dev package is required because of access to clipboard
67 ([here's the library that nerdlog
68 uses](https://github.com/golang-design/clipboard)), e.g. on Ubuntu it can be
69 installed with this:
70
71 ```
72 sudo apt install libx11-dev
73 ```
74
75 On MacOS and Windows, no extra dependencies are required.
76
77 ### Using `go install`
78
79 Latest release (might miss newest features which are not yet officially released):
80
81 ```
82 go install github.com/dimonomid/nerdlog/cmd/nerdlog@latest
83 ```
84
85 Latest master:
86
87 ```
88 go install github.com/dimonomid/nerdlog/cmd/nerdlog@master
89 ```
90
91 Unless you have custom `GOPATH` or `GOBIN` env vars set, it will install the
92 `nerdlog` binary to `$HOME/go/bin`.
93
94 ### Using `make`
95
96 To install `nerdlog` binary to your `/usr/local/bin`:
97
98 ```
99 $ make && sudo make install
100 ```
101
102 Or to build and run without installing:
103
104 ```
105 $ make && bin/nerdlog
106 ```
107
108 ## Usage
109
110 When you open the app (`nerdlog` binary), it'll show a query edit form with a
111 few fields:
112
113 ![Nerdlog](images/nerdlog_query_edit_form.png)
114
115 Time range is self-explanatory.
116
117 Next one is "Logstreams": shortly, as the name suggests, a logstream is a
118 contiguous stream of log messages, on a particular server accessible via ssh
119 (or on the local server).
120 As of now, two kinds of logstreams are supported:
121
122 - One or more _consecutive_ log files like `/var/log/syslog` and
123 `/var/log/syslog.1` (actually as of now there can be at most 2 files in a
124 logstream, but this limitation will hopefully be removed).
125 - Logs returned from `journalctl`
126
127 By default, nerdlog checks available logstreams in the following order:
128
129 - If available, use the `/var/log/messages` file (and the older `/var/log/messages.1`)
130 - If available, use the `/var/log/syslog` file (and the older `/var/log/syslog.1`)
131 - As the last resort, use `journalctl` if available.
132
133 Why preferring the logfiles instead of `journalctl`: shortly, because it's less
134 reliable and much slower. See
135 [FAQ](./docs/faq.md#why-does-nerdlog-default-to-log-files-instead-of-journalctl)
136 for details. However, `journalctl` is more universally available these days
137 (alas), and it often also has longer history, so nerdlog has full support for
138 it. So far there's no option to prefer `journalctl` instead of log files by
139 default, lmk if you need it; shouldn't be hard to implement.
140
141 So if you have a server like `myserver.com` accessible via ssh on port 22, then
142 the logstream to read its `/var/log/messages` file (or `/var/log/syslog` file,
143 or from `journalctl` if none of these files are present) could be:
144
145 ```
146 [email protected]
147 ```
148
149 If you need a different port and/or different log files, then a more explicit
150 form is:
151
152 ```
153 [email protected]:1234:/some/other/logfile
154 ```
155
156 To select `journalctl` explicitly, specify `journalctl` as the log file:
157
158 ```
159 [email protected]:1234:journalctl
160 ```
161
162 Multiple logstreams can be provided separated by commas, like this:
163
164 ```
165 [email protected], [email protected]:1234:/some/other/logfile
166 ```
167
168 Nerdlog also reads ssh config (`~/.ssh/config`) and can take the port, username
169 and hostname from there. It supports globs too, so e.g. in your ssh config you
170 have two hosts like `myhost-01` and `myhost-02`, then instead of specifying
171 your logstreams as `myhost-01,myhost-02` it can be simply `myhost-*`.
172
173 Obviously though, we can't specify the log files in the ssh config, so if you
174 need to configure a logstream for non-default log file on some host(s), you can
175 use the nerdlog's own logstreams config file `~/.config/nerdlog/logstreams.yaml`,
176 which can look like this:
177
178 ```
179 log_streams:
180 myhost-01:
181 hostname: actualhost1.com
182 port: 1234
183 user: myuser
184 log_files:
185 - /some/custom/logfile
186 myhost-02:
187 hostname: actualhost2.com
188 port: 7890
189 user: myuser
190 log_files:
191 - /some/custom/logfile
192 ```
193
194 The last thing on that query form is the "Select field expression", it looks
195 like this:
196
197 ```
198 time STICKY, lstream, message, *
199 ```
200
201 It only affects the presentation of the logs in the UI. The syntax somewhat
202 resembles the SQL `SELECT` syntax, although a lot more limited.
203
204 The `STICKY` here just means that when the table is scrolled to the right,
205 these sticky columns will remain visible at the left side.
206
207 Another supported keyword here is `AS`, so e.g. `message AS msg` is a valid
208 syntax.
209
210 For a more extensive discussion on the logstreams and other core concepts, and advanced options like using `sudo` to read log files, consider
211 reading the [Core concepts](./docs/core_concepts.md) section in the docs.
212
213 ## Requirements
214
215 - SSH access to the hosts is required (except for `localhost`). You can read about the related limitations and possible workarounds here: [Consequences of requiring SSH access](./docs/limitations.md#consequences-of-requiring-ssh-access);
216 - Gawk (GNU awk) is a requirement on the hosts, since nerlog relies on the `-b`
217 option. So notably, `mawk` will not work. You need `gawk`;
218
219 For more details, see [Requirements](./docs/requirements.md) and
220 [Limitations](./docs/limitations.md) in the docs.
221
222 ## UI
223
224 UI consists of a few key elements:
225
226 - Awk pattern input: just a filter for logs. Empty filter obviously means no filter, and some examples of valid filters are:
227 - Simple regexp: `/foo bar/`
228 - Regexps with complex conditions: `( /foo bar/ || /other stuff/ ) && !/baz/`
229 - Edit button: opens a complete query edit form discussed above.
230 - Menu button: just opens a menu with a few extra items:
231 - Back: Go to the previous query, just like in the browser
232 - Forward: Go to the next query, just like in the browser
233 - Copy query command: It's the equivalent of copying an URL in the browser, containing the link to the current logs query. See the `:xc[lip]` command below for more details on that.
234
235 - Time range histogram: similarly to some web-based log viewers, like Graylog or Kibana, Nerdlog also shows a timeline histogram, so you can quickly glance at the intensiveness of the logs accordingly to the current query. It's also easy to visually select and apply timerange (using arrow / PgUp / PgDown / Home / End / Enter keys or vim-like bindings)
236 - Logs table: obviously contains the actual logs. Like in the normal, old-school logs, **the latest message is on the bottom**. I don't know why modern web tools do it the other way around (latest message being on the top), to me it's nonsense. But let me know if you prefer it this modern way; it shouldn't be too hard to make it configurable.
237
238 Every line shows the timestamp and the message, and it can also be scrolled to the right to show the context tags parsed from a log line.
239
240 - Status line. On the left side, there are a few computer icons with numbers:
241 - Green: number of lstreams which we're fully connected to and which are idle
242 - Orange: number of lstreams which we're fully connected to and which are executing a query
243 - Red: number of lstreams which we're trying to connect to
244
245 And on the right side, there are 3 numbers like `1201 / 1455 / 2948122`. The rightmost number (2948122) is the total number of log messages that matched the query and the timerange (and included in the timeline histogram above). The next number (1455) is the number of actual log lines currently loaded in the nerdlog app, and the leftmost (1201) is just the cursor within those available logs.
246
247 - Command line: Vim-like command line. Hit `:` to enter command mode.
248
249 ## Navigation
250
251 There are multiple ways to navigate the app, and you can mix them as you wish.
252
253 The most conventional one is to just use Tab and Shift+Tab to switch between widgets (logs table, query input, Edit and Menu buttons, timeline histogram), arrows and keys like Home / End / PgUp / PgDn to move around within a widget, Enter to apply things, Escape to cancel things.
254
255 Some browser-like keyboard shortcuts are also supported (after all, one of the
256 inspirations for Nerdlog were browser-based tools like Graylog):
257
258 - `Alt+Left`: Go back in history
259 - `Alt+Right`: Go forward in history
260 - `F5` or `Ctrl+R`: Refresh (i.e. rerun the same query again)
261 - `Shift+F5` or `Alt+Ctrl+R`: Hard refresh, i.e. also rebuild the index for
262 every logstream (the index is only relevant for plain log files; so for
263 `journalctl`-powered logstreams, it's the same as regular Refresh)
264
265 If you know Vim though, you'll feel right at home in nerdlog too since it supports a bunch of Vim-like keybindings:
266
267 - Keys `h`, `j`, `k`, `l`, `g`, `G`, `Ctrl+U`, `Ctrl+D`, etc move cursor whenever you're not in some text-editing field, like query input or others
268 - Hitting Escape eventually brings you to the "Normal mode", which means that the logs table is focused (and all of those `h`, `j`, `k`, `l`, etc work there)
269 - `:` focuses the command line where you can input some commands (see below)
270 - `i` or `a` focuses the main query input field
271
272 When in an input field (command line, query input, etc), you can go through input history using `Up` / `Down` or `Ctrl+P` / `Ctrl+N`.
273
274 In the query edit form (the Edit button on the UI, or the `:e[dit]` command), the `Ctrl+K` / `Ctrl+J` iterates "full" query history (affecting not only one field like query, but all of them: time range, logstreams filter, query).
275
276 ## Commands
277
278 In addition to the UI which is self-discoverable, there is a vim-like command line
279 with a few commands supported.
280
281 `:xc[lip]` Copies to clipboard a command string which would open nerdlog with
282 the current logstreams filter, time range and query. This can be done from the Menu too (Menu -> Copy query command)
283
284 This is the equivalent of URL sharing for web-based logging tools: when you'd
285 normally copy the graylog URL and paste it in slack somewhere, with nerdlog you
286 can do the same by sharing this string.
287
288 The string would look like this:
289
290 ```
291 nerdlog --lstreams 'localhost' --time -3h --pattern '/something/'
292 ```
293
294 And it can be used in either the shell (which would open a new instance of
295 nerdlog), OR it can also be used in a currently running nerdlog instance: just
296 type `:` to go to the command mode, copypaste this command above, and nerdlog
297 will parse it and apply the query.
298
299 `:back` or `:prev` Go to the previous query, just like in the browser. This can be done from the Menu too (Menu -> Back), or using a keyboard shortcut `Alt+Left`.
300
301 `:fwd` or `:next` Go to the next query, just like in the browser. This can be done from the Menu too (Menu -> Forward), or using a keyboard shortcut `Alt+Right`.
302
303 `:e[dit]` Open query edit form; you can do the same if you just use Tab to navigate
304 to the Edit button in the UI.
305
306 `:w[rite] [filename]` Write all currently loaded log lines to the filename.
307 If filename is omitted, `/tmp/last_nerdlog` is used.
308
309 `:refresh` Rerun the same query again. This can be done from the Menu too (Menu -> Refresh), or using a keyboard shortcut `Ctrl+R` or `F5`.
310
311 `:refresh!` Hard refresh, i.e. also rebuild the index for every logstream. This
312 can be done from the Menu too, or using a keyboard shortcut `Alt+Ctrl+R` or
313 `Shift+F5`.
314
315 `:reconnect` Reconnect to all logstreams
316
317 `:disconnect` Disconnect from all logstreams
318
319 `:conndebug` or `:cdebug` Show debug info for the current logstream connections
320
321 `:querydebug` or `:qdebug` or just `:debug` Show debug info for the last query
322
323 `:version` or `:about` Show version info
324
325 `:set option?` Get current value of an option
326
327 `:set option=value` Set option to the new value
328
329 See the [full list of supported options here](./docs/options.md).
330
331 ---
332
333 `:q[uit]` Quit the app.
334
335 ## Noteworthy dependencies
336
337 - [tview](https://github.com/rivo/tview): A terminal UI library with rich, interactive widgets, written in Go
338 - [tcell](https://github.com/gdamore/tcell): A Go package that provides a cell based view for text terminals, like XTerm
339 - [clipboard](https://github.com/golang-design/clipboard): A cross-platform clipboard package that supports accessing text and images in Go
340 - [glob](https://github.com/gobwas/glob): A Go globbing library
341 - [ssh_config](https://github.com/kevinburke/ssh_config): A Go parser for `ssh_config` files *(Note: it doesn't support all the features we need and may be replaced; see [issue #12](https://github.com/dimonomid/nerdlog/issues/12) for details)*
342
343 **Huge thanks** to the maintainers of these libraries, Nerdlog wouldn't be possible without your work!
344
345 ## More details
346
347 [Check out the documentation](./docs/index.md) for more in-depth look at the core concepts, limitations and workarounds, implementation details, tests, FAQ, troubleshooting, etc.