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