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