Add build instructions
[khatus.git] / README.md
1 khatus
2 ======
3 ![mascot](mascot.jpg)
4
5 Experimental system-monitor and status (bar) reporter I use with
6 [dwm](https://dwm.suckless.org/) on GNU/Linux.
7
8 ![screenshot](screenshot.jpg)
9
10 Usage
11 -----
12
13 `make build && make install`
14
15 `make install` copies everything from `./bin` to `$HOME/bin`
16
17 In 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 \
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 ) \
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 ) \
39 2> >($BIN/twrap.sh >> $HOME/var/log/khatus/main.log) \
40 1> /dev/null \
41 &
42 ```
43 (where `twrap` is a simple script which prefixes a timestamp to each line)
44
45 The idea is to support appending any number of ad-hoc, experimental monitors by
46 giving maximum flexibility for what to do with the sensor outputs, while
47 maintaining 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
50 examples.
51
52 Design
53 ------
54
55 ### 2.0
56
57 In an effort to simplify the components and their interfaces, I removed the
58 concept of a global controller from the previous design (which, at least for
59 now, 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
61 subscribers that can filter-out what they need and then do whatever they want
62 with the data. Status bar is one such subscriber:
63
64 `P1 > pipe&; P2 > pipe&; ... PN > pipe&; tail -f pipe | tee >(S1) >(S2) ... >(SN) > /dev/null`
65
66 The cool thing is that, because the pipe is always read (`tail -f ... > /dev/null`),
67 the publishers are never blocked, so we get a live stream of events to which we
68 can attach any number of interested subscribers (` ... tee ... `) and, because
69 the pipe is named, if a subscriber needs to - it too can publish something to
70 the pipe without being blocked.
71
72 ```
73 parallel +----------+ +----------+ +----------+
74 stateless | sensor_1 | | sensor_2 | ... | sensor_n |
75 collectors +----------+ +----------+ +----------+
76 | | | |
77 data data data data
78 | | | |
79 V V V V
80 multiplexing +-------------+-----------+---------+
81 to a pipe |
82 |
83 V
84 copying to +-------------+-+---------+---------+
85 subscribers | | | |
86 V V V V
87 +------------+ ... +----------------+
88 any number of | status bar | | energy monitor |
89 parallel +------------+ +----------------+
90 subscribers | |
91 V V
92 +----------------+ +-------------+
93 | xsetroot -name | | notify-send |
94 +----------------+ +-------------+
95 ```
96
97 ### 1.0
98
99 This was an improvement of having everything in one script, but the controller
100 was still way too complicated for no good reason.
101
102 ```
103 parallel +----------+ +----------+ +----------+
104 stateless | sensor_1 | | sensor_2 | ... | sensor_n |
105 collectors +----------+ +----------+ +----------+
106 | | | |
107 data data data data
108 | | | |
109 V V V V
110 serial +----------------------------------------------+
111 stateful | controller |
112 observer +----------------------------------------------+
113 |
114 decision messages
115 decision |
116 messages |
117 copied to |
118 any number |
119 of interested |
120 filter/actuator |
121 combinations |
122 |
123 V
124 +-------------+-+---------+---------+
125 | | | |
126 V V V V
127 parallel +------------+ +------------+ +------------+
128 stateless | filter_1 | | filter_2 | ... | filter_n |
129 filters +------------+ +------------+ +------------+
130 | | | |
131 V V V V
132 parallel +------------+ +------------+ +------------+
133 stateless | actuator_1 | | actuator_2 | ... | actuator_n |
134 executors +------------+ +------------+ +------------+
135 | | | |
136 commands commands commands commands
137 | | | |
138 V V V V
139 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140 ~~~~~~~~~~~~~ operating system ~~~~~~~~~~~~~~~~~
141 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142 ```
143
144 ### 0.x
145
146 A single script, re-executed in a loop at some intervals, serially grabbing all
147 the needed data and outputting a status bar string, then passed to `xsetroot -name`,
148 while saving state in files (e.g. previous totals, to be converted to deltas).
149
150 This 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
158 ### Actuator
159 Actuator is anything that takes action upon controller messages. A few generic
160 ones are included:
161
162 - `khatus_actuate_alert_to_notify_send`
163 - `khatus_actuate_status_bar_to_xsetroot_name`
164
165 and, by default, are left disconnected from the data feed, so if desired - need
166 to be manually attached when starting `khatus`. See usage section.
167
168 ### Errors
169 Any errors encountered by any sensor are propagated as alerts by the
170 controller, which are in turn actualized as desktop notifications by the
171 `khatus_actuate_alert_to_notify_send` actuator:
172
173 ![screenshot-self-error-propagation](screenshot-self-error-propagation.jpg)
174
175 TODO
176 ----
177
178 - formalize message format and protocol
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
185 - status bar templating language
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
194 - monitor processes
195 - totals (grand and per state)
196 - zombies
197 - threads
198 - CPU hogs
199 - memory hogs
200 - memory leaks (if some process consistently grows)
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?
207 - report detailed status upon request (to a terminal)
208 - use color to indicate age of data
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?)
219
220 Redesign notes
221 --------------
222
223 - controller should not do formatting
224 - need in-memory db for diskless feedback/throttling and cache
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).
234
235 Ideas
236 -----
237
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.
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`
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?)
253 - store data with rrdtool
254 - some kind of personal calendar thing integration
255 - monitor tracking numbers (17track should be easiest to get started with)
256 - monitor password digests against known leaked password databases
257 - monitor stock prices
258 - monitor some item price(s) at some store(s) (Amazon, etc.)
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
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/
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?
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
328 Many of the above will undoubtedly need non-standard-system dependencies
329 (languages, libraries, etc.), in which case - would they be better off as
330 separate projects/repos?
331
332 With all these ideas, it is starting to sound very noisy, but no worries - to
333 quickly and temporarily shut everything up - just kill `dunst` and or toggle
334 the status bar (`Alt` + `B` in `dwm`). For a permanent change - just don't
335 turn-on the unwanted monitors/sensors.
This page took 0.07635 seconds and 5 git commands to generate.