mirror of
https://github.com/Brandon-Rozek/website.git
synced 2025-06-19 11:55:41 +00:00
Compare commits
5 commits
4173d48130
...
77232e4af3
Author | SHA1 | Date | |
---|---|---|---|
77232e4af3 | |||
0b58f4a592 | |||
6173816ab3 | |||
303a045f87 | |||
e2283c6d96 |
4 changed files with 188 additions and 1 deletions
108
content/blog/please-monitor-disk-usage.md
Normal file
108
content/blog/please-monitor-disk-usage.md
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
---
|
||||||
|
title: "Please monitor disk usage"
|
||||||
|
date: 2024-11-26T19:59:10-05:00
|
||||||
|
draft: false
|
||||||
|
tags: []
|
||||||
|
math: false
|
||||||
|
medium_enabled: false
|
||||||
|
---
|
||||||
|
|
||||||
|
You know one of the worst errors to deal with on Linux?
|
||||||
|
|
||||||
|
> No space left on device
|
||||||
|
|
||||||
|
Why? Because recovery becomes really annoying. Depending on your luck, Linux may try to cache to disk even when it's impossible causing quite a few commands to fail.
|
||||||
|
|
||||||
|
If you're already in this situation, the best thing you can do is try to locate files to remove. You can run `du -sh *` in any given directory to see the sizes of files and subfolders.
|
||||||
|
|
||||||
|
Common places that hold temporary files which may be removable are:
|
||||||
|
|
||||||
|
- `/tmp`
|
||||||
|
- `~/.cache`
|
||||||
|
|
||||||
|
An even better solution is to not get into this situation in the first place. For that, I introduce a bash script which sends a notification when the disk is getting full!
|
||||||
|
|
||||||
|
To see the amount of available and total space for a given `$MOUNTPOINT` (for example, `/`), we run the following:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
available_space=$(df "$MOUNTPOINT" | awk 'NR==2 {print $4}')
|
||||||
|
total_space=$(df "$MOUNTPOINT" | awk 'NR==2 {print $2}')
|
||||||
|
```
|
||||||
|
|
||||||
|
Add a couple if statements and we have ourselves a full-blown script:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
set -o nounset
|
||||||
|
|
||||||
|
MAX_USAGE_PERCENT=90
|
||||||
|
|
||||||
|
if [ -z "$MOUNTPOINT" ]; then
|
||||||
|
echo "MOUNTPOINT variable not set or empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get the available and total disk space for the specified mount point
|
||||||
|
available_space=$(df "$MOUNTPOINT" | awk 'NR==2 {print $4}')
|
||||||
|
total_space=$(df "$MOUNTPOINT" | awk 'NR==2 {print $2}')
|
||||||
|
|
||||||
|
# Check if the df command was successful
|
||||||
|
if [ -z "$available_space" ] || [ -z "$total_space" ]; then
|
||||||
|
echo "Error: Could not retrieve disk space for $MOUNTPOINT"
|
||||||
|
sendMsg "Error: Could not retrieve disk space for $MOUNTPOINT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
usage_percent=$(( (total_space - available_space) * 100 / total_space ))
|
||||||
|
|
||||||
|
if [ $usage_percent -ge $MAX_USAGE_PERCENT ]; then
|
||||||
|
host_name=$(hostname)
|
||||||
|
echo "Low Disk on $host_name at mountpoint $MOUNTPOINT. Currently using ${usage_percent}% of available space."
|
||||||
|
sendMsg "Low Disk on $host_name at mountpoint $MOUNTPOINT. Currently using ${usage_percent}% of available space."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Mountpoint $MOUNTPOINT is currently using ${usage_percent}% of available space."
|
||||||
|
```
|
||||||
|
|
||||||
|
The only part left undefined here is the `sendMsg` function. For me, I send a [webhook notification](https://brandonrozek.com/blog/webhook-notifications-on-systemd-service-failure/) to Zulip to both get notified and have a log of these messages.
|
||||||
|
|
||||||
|
To have this check regularly automatically, we create a systemd service and timer files.
|
||||||
|
|
||||||
|
`/etc/systemd/system/lowdiskcheck.service`
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[Unit]
|
||||||
|
Description=Check for low disk space
|
||||||
|
Requires=network-online.target
|
||||||
|
Wants=
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
# Feel free to change the mountpoint to one that you care about
|
||||||
|
Environment=MOUNTPOINT=/home
|
||||||
|
ExecStart=/usr/local/bin/lowdiskcheck.sh
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
`/etc/systemd/system/lowdiskcheck.timer`
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[Unit]
|
||||||
|
Description=Check for low disk space daily
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=daily
|
||||||
|
Persistent=true
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
```
|
||||||
|
|
||||||
|
Then enable the timer,
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl enable lowdiskcheck.timer
|
||||||
|
```
|
||||||
|
|
75
content/blog/vale-linter-human-prose.md
Normal file
75
content/blog/vale-linter-human-prose.md
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
---
|
||||||
|
title: "Linting my blog posts with Vale"
|
||||||
|
date: 2024-11-27T16:29:30-05:00
|
||||||
|
draft: false
|
||||||
|
tags: []
|
||||||
|
math: false
|
||||||
|
medium_enabled: false
|
||||||
|
---
|
||||||
|
|
||||||
|
How do you write *good*?
|
||||||
|
|
||||||
|
For some, the answer is Grammarly. This, however, falls short to me for the following reasons:
|
||||||
|
|
||||||
|
- Needing to rely on some third party service. Seriously, what if I want to draft my blog posts without Internet?
|
||||||
|
- Not configurable. Leave me alone, sometimes I like writing **my way**.
|
||||||
|
- Where's my beautiful terminal application?
|
||||||
|
|
||||||
|
I use [Vale](https://vale.sh/) ([GitHub](https://github.com/errata-ai/vale)) a linter for human prose. It runs locally on my computer ✔, is configurable by defining a rule set ✔, and offers not only a beautiful CLI application ✔, but even offers integrations to editors like VSCode.
|
||||||
|
|
||||||
|
To provide useful feedback, we'll need a strong collection of rules. Like a crazy person, I went onto the [Vale package hub](https://vale.sh/hub/) and looked at the rules of many different packages and compiled the ones I liked into [my own package](https://github.com/brandon-rozek/vale) for us to use.
|
||||||
|
|
||||||
|
All we need to do is specify the package in our Vale config. To see where this lives, you can run `vale ls-dirs`. For example, on my computer it is at `~/.config/vale/.vale.ini`
|
||||||
|
|
||||||
|
```ini
|
||||||
|
StylesPath = /home/rozek/.local/share/vale/styles
|
||||||
|
|
||||||
|
Vocab = brozek
|
||||||
|
|
||||||
|
MinAlertLevel = suggestion
|
||||||
|
|
||||||
|
Packages = https://github.com/Brandon-Rozek/vale/releases/download/0.1.0/brozek.zip
|
||||||
|
|
||||||
|
[*]
|
||||||
|
BasedOnStyles = Vale, brozek
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, Vale includes a spell-checker. As a technical writer, I often talk about products which Vale claims are typos. We can force Vale to not complain by creating a [Vocabulary](https://vale.sh/docs/topics/vocab/) (fancy word for dictionary).
|
||||||
|
|
||||||
|
`<StylesPath>/config/vocabularies/brozek/accept.txt`
|
||||||
|
|
||||||
|
```
|
||||||
|
BTRFS
|
||||||
|
[Bb]oolean
|
||||||
|
systemd
|
||||||
|
Zulip
|
||||||
|
```
|
||||||
|
|
||||||
|
These vocabularies are case-sensitive, which while may seen like a weird choice, I find useful in keeping capitalization consistent. To specify that something is not case sensitive you'll need to put square brackets around the upper and lower-case letter. For example, case-insensitive b is `[Bb]`.
|
||||||
|
|
||||||
|
With all this configured, we can then sync the configuration rules to our machine.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vale sync
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, lint a blog post!
|
||||||
|
|
||||||
|
```bash
|
||||||
|
vale vale-linter-human-prose.md
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
vale-linter-human-prose.md
|
||||||
|
14:48 warning Remove 'Seriously' if it's not brozek.Adverbs
|
||||||
|
important to the meaning of
|
||||||
|
the statement.
|
||||||
|
20:70 suggestion Try to keep sentences short (< brozek.SentenceLength
|
||||||
|
30 words).
|
||||||
|
48:91 warning Remove 'really' if it's not brozek.Adverbs
|
||||||
|
important to the meaning of
|
||||||
|
the statement.
|
||||||
|
```
|
||||||
|
|
||||||
|
From there you can choose which suggestions to keep and which to ignore ;)
|
||||||
|
|
4
static/files/images/blog/focalsets.svg
Normal file
4
static/files/images/blog/focalsets.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 42 KiB |
|
@ -1 +1 @@
|
||||||
Subproject commit 70f42b3d844d63b5833d983a9efa2dc55d145875
|
Subproject commit 864dce1ff9a5ab3a3160a4ab835abadd9589d45a
|
Loading…
Add table
Reference in a new issue