Add build instructions
[khatus.git] / README.md
CommitLineData
756b9d5a
SK
1khatus
2======
a9038fad 3![mascot](mascot.jpg)
756b9d5a 4
44fc2f3d 5Experimental system-monitor and status (bar) reporter I use with
61c33dc2 6[dwm](https://dwm.suckless.org/) on GNU/Linux.
756b9d5a
SK
7
8![screenshot](screenshot.jpg)
55407653 9
44fc2f3d
SK
10Usage
11-----
12
7875d28d
SK
13`make build && make install`
14
15`make install` copies everything from `./bin` to `$HOME/bin`
16
44fc2f3d
SK
17In my `~/.xinitrc` I have something like the following:
18
19```sh
20( $BIN/khatus \
21 --wifi_interface 'wlp3s0' \
22| stdbuf -o L tee \
23 >(stdbuf -o L "$BIN"/khatus_bar \
24 -v Opt_Mpd_Song_Max_Chars=10 \
25 -v Opt_Net_Interfaces_To_Show=wlp3s0 \
26 -v Opt_Pulseaudio_Sink=0 \
ab9fe663
SK
27 -f <(./bin/khatus_gen_make_status_bar \
28 -v Status_Bar='@energy,@memory,@processes,@cpu,@disk,@net,@bluetooth,@backlight,@volume,@mpd,@weather,@datetime' \
29 ) \
44fc2f3d
SK
30 | "$BIN"/khatus_actuate_status_bar_to_xsetroot_name \
31 ) \
32 >(stdbuf -o L "$BIN"/khatus_monitor_energy \
33 | "$BIN"/khatus_actuate_alert_to_notify_send \
34 ) \
35 >(stdbuf -o L "$BIN"/khatus_monitor_errors \
36 | "$BIN"/khatus_actuate_alert_to_notify_send \
37 ) \
38) \
392> >($BIN/twrap.sh >> $HOME/var/log/khatus/main.log) \
401> /dev/null \
41&
42```
43(where `twrap` is a simple script which prefixes a timestamp to each line)
44
45The idea is to support appending any number of ad-hoc, experimental monitors by
46giving maximum flexibility for what to do with the sensor outputs, while
47maintaining some uniformity of msg formats (again, to ease ad-hoc combinations
48(e.g. Does the CPU get hotter when MPD is playing Wu-Tang?)). `khatus_bar`,
49`khatus_monitor_energy` and `khatus_monitor_errors` are just some initial
50examples.
55407653
SK
51
52Design
53------
54
44fc2f3d
SK
55### 2.0
56
57In an effort to simplify the components and their interfaces, I removed the
58concept of a global controller from the previous design (which, at least for
59now, is superfluous), so now it is essentially a pub-sub - parallel publishers
60(sensors) write to a pipe, which is then copied to any number of interested
61subscribers that can filter-out what they need and then do whatever they want
62with the data. Status bar is one such subscriber:
63
8acd36e8 64`P1 > pipe&; P2 > pipe&; ... PN > pipe&; tail -f pipe | tee >(S1) >(S2) ... >(SN) > /dev/null`
44fc2f3d
SK
65
66The cool thing is that, because the pipe is always read (`tail -f ... > /dev/null`),
09caa63e 67the publishers are never blocked, so we get a live stream of events to which we
44fc2f3d
SK
68can attach any number of interested subscribers (` ... tee ... `) and, because
69the pipe is named, if a subscriber needs to - it too can publish something to
70the pipe without being blocked.
71
72```
73parallel +----------+ +----------+ +----------+
74stateless | sensor_1 | | sensor_2 | ... | sensor_n |
75collectors +----------+ +----------+ +----------+
76 | | | |
77 data data data data
78 | | | |
79 V V V V
80multiplexing +-------------+-----------+---------+
81to a pipe |
82 |
83 V
84copying to +-------------+-+---------+---------+
85subscribers | | | |
86 V V V V
87 +------------+ ... +----------------+
88any number of | status bar | | energy monitor |
89parallel +------------+ +----------------+
90subscribers | |
91 V V
92 +----------------+ +-------------+
93 | xsetroot -name | | notify-send |
94 +----------------+ +-------------+
95```
96
97### 1.0
98
99This was an improvement of having everything in one script, but the controller
100was still way too complicated for no good reason.
101
55407653 102```
43e49903
SK
103parallel +----------+ +----------+ +----------+
104stateless | sensor_1 | | sensor_2 | ... | sensor_n |
105collectors +----------+ +----------+ +----------+
106 | | | |
107 data data data data
108 | | | |
109 V V V V
110serial +----------------------------------------------+
111stateful | controller |
112observer +----------------------------------------------+
113 |
114 decision messages
115decision |
116messages |
117copied to |
118any number |
119of interested |
120filter/actuator |
121combinations |
122 |
123 V
124 +-------------+-+---------+---------+
125 | | | |
126 V V V V
127parallel +------------+ +------------+ +------------+
128stateless | filter_1 | | filter_2 | ... | filter_n |
129filters +------------+ +------------+ +------------+
130 | | | |
131 V V V V
132parallel +------------+ +------------+ +------------+
133stateless | actuator_1 | | actuator_2 | ... | actuator_n |
134executors +------------+ +------------+ +------------+
135 | | | |
136 commands commands commands commands
137 | | | |
138 V V V V
139 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140 ~~~~~~~~~~~~~ operating system ~~~~~~~~~~~~~~~~~
141 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55407653 142```
7daecd24 143
44fc2f3d
SK
144### 0.x
145
146A single script, re-executed in a loop at some intervals, serially grabbing all
147the needed data and outputting a status bar string, then passed to `xsetroot -name`,
148while saving state in files (e.g. previous totals, to be converted to deltas).
149
150This actually worked surprisingly-OK, but had limitations:
151
152- I use an SSD and want to minimize disk writes
153- not flexible-enough to support my main goal - easy experimentation with
154 various ad-hoc monitors:
155 - I want to set different update intervals for different data sources
156 - I don't want long-running data collectors to block the main loop
157
ec80b440 158### Actuator
43e49903
SK
159Actuator is anything that takes action upon controller messages. A few generic
160ones are included:
161
162- `khatus_actuate_alert_to_notify_send`
163- `khatus_actuate_status_bar_to_xsetroot_name`
164
44fc2f3d
SK
165and, by default, are left disconnected from the data feed, so if desired - need
166to be manually attached when starting `khatus`. See usage section.
ec80b440
SK
167
168### Errors
7daecd24
SK
169Any errors encountered by any sensor are propagated as alerts by the
170controller, which are in turn actualized as desktop notifications by the
43e49903 171`khatus_actuate_alert_to_notify_send` actuator:
ec80b440 172
7daecd24 173![screenshot-self-error-propagation](screenshot-self-error-propagation.jpg)
1341dc96
SK
174
175TODO
176----
177
d6075e1b 178- formalize message format and protocol
696c47b9
SK
179- tests (design is starting to take shape, so it is time)
180- show how many Debian package updates are available
181- show how many Debian package security-updates are available
182- monitor disk usage rate of change and alert if suspiciously fast
183- bring back CPU usage monitor
184- actual METAR parser, to replace the flaky `metar` program
44fc2f3d 185- status bar templating language
1341dc96
SK
186- retry/cache for sensors fetching flaky remote resources (such as weather)
187- throttling of broken sensors (constantly returns errors)
188- alert specification language
189 - trigger threshold
190 - above/bellow/equal to threshold value
191 - priority
192 - snooze time (if already alerted, when to re-alert?)
193 - text: subject/body
476fcb1f 194- monitor processes
a0b7b67b 195 - totals (grand and per state)
476fcb1f 196 - zombies
a0b7b67b 197 - threads
476fcb1f
SK
198 - CPU hogs
199 - memory hogs
200 - memory leaks (if some process consistently grows)
a0b7b67b
SK
201 - is select process up?
202 - log resource usage of select processes
203- monitor arbitrary HTTP endpoint availability
204 - is status within expected range?
205 - response time
206 - is responce time within acceptable range?
b7601ee4
SK
207- report detailed status upon request (to a terminal)
208 - use color to indicate age of data
a0b7b67b
SK
209- monitor logins
210 - totals (per time period)
211 - failures
212 - successes
213 - most recent
214 - success
215 - failure
216- monitor battery time remaining
217 - monitor accuracy (is percentage change rate on track to meet estimate?)
218 - adjust estimate based on observed inaccuracies in past estimates (Kalman?)
7917538c
SK
219
220Redesign notes
221--------------
222
223- controller should not do formatting
224- need in-memory db for diskless feedback/throttling and cache
91ad8a2f
SK
225- decouple sensor execution from sleep, i.e. a sensor is blocked not by sleep
226 process directly, but by reading of a pipe, to where a sleep process will
227 write a message announcing interval completion and thus signaling execution.
228 This will allow us to manually signal a sensor to update (concretely - I just
229 openned my laptop from sleep and want to force the weather to update
230 immediately); likewise, the sleep process should be blocked on pipe-read
231 until sensor execution is complete - this will allow us to reconfigure
232 intervals at runtime (which seems like a better idea than the above in-memory
233 DB one).
696c47b9
SK
234
235Ideas
236-----
237
e46c8cdd
SK
238- track devices:
239 - alert when never before seen device is plugged-in
240 - report history and trends on when and how-often each
241 device/category is plugged-in, how-long it stays plaugged-in, etc.
63770b60
SK
242- daemonize `khatus`, so we don't have to re-launch `X11` to re-launch `khatus`
243- interoperate with other khatus instances
244 - prefix machine ID to each data source
245 (What should that ID be? Hostname? Pub key?)
246 - fetch remote data and process locally
247 - what transport to use?
248 - ssh + rsync + cache dumps per some interval?
249 - `A` can setup self penetration testing, by setting up probe of `A` on `B`
250 and fetching results from `B` to `A`
a0b7b67b
SK
251- offline mode - quick disable all network-using subsystems (sensors, monitors, etc)
252- classify each sensor as either "local" or "remote" (what about `iwconfig`, et al?)
696c47b9 253- store data with rrdtool
a0b7b67b 254- some kind of personal calendar thing integration
696c47b9 255- monitor tracking numbers (17track should be easiest to get started with)
c59126af 256- monitor password digests against known leaked password databases
696c47b9
SK
257- monitor stock prices
258- monitor some item price(s) at some store(s) (Amazon, etc.)
a0b7b67b
SK
259 - https://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_RetrievingPriceInformation.html
260 - https://docs.aws.amazon.com/AWSECommerceService/latest/DG/ReturningPrices.html
261 - https://developer.amazonservices.com/
262- monitor Amazon order status
263 - https://developer.amazonservices.com/gp/mws/api.html?group=orders&section=orders
264- monitor eBay order status
265 - http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/GetOrders.html
696c47b9
SK
266- monitor eBay auctions (https://en.wikipedia.org/wiki/EBay_API)
267- monitor PayPal (https://www.programmableweb.com/api/paypal)
268- monitor bank account balance and transactions
269 - https://communities.usaa.com/t5/Banking/Banking-via-API-Root/m-p/180789/highlight/true#M50758
270 - https://plaid.com/
271 - https://plaid.com/docs/api/
272 - https://plaid.com/docs/api/#institution-overview
273 - https://github.com/plaid
274 - https://www.bignerdranch.com/blog/online-banking-apis/
275- monitor/log road/traffic conditions
276 - travel times for some route over a course of time
277 - https://msdn.microsoft.com/en-us/library/hh441725
278 - https://cloud.google.com/maps-platform/
279 - https://cloud.google.com/maps-platform/routes/
280 - https://developer.mapquest.com/documentation/traffic-api/
281 - https://developer.here.com/api-explorer/rest/traffic/traffic-flow-bounding-box
282- monitor news sources for patterns/substrings
283 - http://developer.nytimes.com/
284 - https://news.ycombinator.com/
285 - https://lobste.rs/
286 - https://www.undeadly.org/
287 - http://openbsdnow.org/
288 - https://lwn.net/
289- monitor a git repository
290 - General
291 - total branches
292 - age of last change per branch
293 - change set sizes
294 - GitHub
295 - pull requests
296 - issues
297- monitor CI
298 - Travis
299 - Jenkins
300- pull/push data from/to other monitoring systems (Nagios, Graphite, etc.)
301- monitor file/directory age (can be used for email and other messaging systems)
302- monitor mailboxes for particular patterns/substrings
303- monitor IRC server(s)/channel(s) for particular patterns/substrings (use `ii`)
304- monitor iptables log
305 - auto-(un)block upon some threshold of violations
306- monitor changes in an arbitrary web resource
307 - deletions
308 - insertions
309 - delta = insertions - deletions
310- monitor/log LAN/WAN configurations (address, router, subnet)
311- monitor/log geolocation based on WAN IP address
312- correlate iptables violations with network/geolocation
313- monitor vulnerability databases
314 - https://nvd.nist.gov/
315 - https://vuldb.com/
316 - http://cve.mitre.org/
a0b7b67b
SK
317- vacation planning optimization
318 - I want to visit a set of places within some time period. Given the
319 current set of prices, a set of constraints (I need to stay some amount
320 of days at each, I must be in X at Y date, etc), which visiting dates for
321 each are cheapest?
696c47b9
SK
322- browse https://www.programmableweb.com/ for some more ideas
323- GC trick: instead of actually doing GC, do a dummy run of building a status
324 bar at `BEGIN`, to fill-in the atimes for keys we need, then use the atimes
325 keys to build a regular expression to accept messages only from keys we
326 actually use
327
328Many of the above will undoubtedly need non-standard-system dependencies
329(languages, libraries, etc.), in which case - would they be better off as
330separate projects/repos?
331
332With all these ideas, it is starting to sound very noisy, but no worries - to
333quickly and temporarily shut everything up - just kill `dunst` and or toggle
334the status bar (`Alt` + `B` in `dwm`). For a permanent change - just don't
335turn-on the unwanted monitors/sensors.
This page took 0.052489 seconds and 4 git commands to generate.