Use code-blocks for bash fragments
This commit is contained in:
@@ -45,21 +45,27 @@ User Journey
|
|||||||
- Problem/Motivation: Each time an ACME project is finished it is
|
- Problem/Motivation: Each time an ACME project is finished it is
|
||||||
desirable to make a backup of the entire database. Given that the
|
desirable to make a backup of the entire database. Given that the
|
||||||
database server is a critical machine we don't want to grant SSH
|
database server is a critical machine we don't want to grant SSH
|
||||||
access to lowly developers. The script is very fast because the
|
access to lowly developers. The script is fast because the
|
||||||
database is small (for now).
|
database is small (for now).
|
||||||
- pre-Kapow! solution: Launching the script via SSH shell.
|
- pre-Kapow! solution: Launching the script via SSH shell.
|
||||||
```
|
|
||||||
ssh user@server
|
.. code-block:: console
|
||||||
$ ./backup_db.sh
|
|
||||||
```
|
$ ssh user@server
|
||||||
|
Password:
|
||||||
|
(server)$ ./backup_db.sh
|
||||||
|
|
||||||
- Kapow!-enabled solution: Provide an HTTP endpoint that when accessed
|
- Kapow!-enabled solution: Provide an HTTP endpoint that when accessed
|
||||||
triggers the run of the backup script.
|
triggers the run of the backup script.
|
||||||
```
|
|
||||||
curl -X PUT http://server:8080/db/backup
|
.. code-block:: console
|
||||||
```
|
|
||||||
```
|
$ curl -X PUT http://server:8080/db/backup
|
||||||
kapow route add -X PUT /db/backup -e ./backup_db.sh
|
|
||||||
```
|
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
$ kapow route add -X PUT /db/backup -e ./backup_db.sh
|
||||||
|
|
||||||
#. Basic server monitoring
|
#. Basic server monitoring
|
||||||
|
|
||||||
@@ -71,9 +77,10 @@ User Journey
|
|||||||
- pre-Kapow! solution: SSH into the host + cat /tmp/backup_db.log.
|
- pre-Kapow! solution: SSH into the host + cat /tmp/backup_db.log.
|
||||||
- Kapow!-enabled solution: Provide an endpoint that returns the contents of
|
- Kapow!-enabled solution: Provide an endpoint that returns the contents of
|
||||||
/tmp/backup_db.log.
|
/tmp/backup_db.log.
|
||||||
```
|
|
||||||
cat /var/log/backup_db.log | kapow set /response/body
|
.. code-block:: console
|
||||||
```
|
|
||||||
|
$ cat /var/log/backup_db.log | kapow set /response/body
|
||||||
|
|
||||||
#. Filter over basic monitoring
|
#. Filter over basic monitoring
|
||||||
|
|
||||||
@@ -89,13 +96,14 @@ User Journey
|
|||||||
this task.
|
this task.
|
||||||
|
|
||||||
- Kapow!-enabled solution:
|
- Kapow!-enabled solution:
|
||||||
```
|
|
||||||
LINES="$(kapow get /request/params/lines)"
|
.. code-block:: sh
|
||||||
FILTER="$(kapow get /request/params/filter)"
|
|
||||||
grep "$FILTER" /var/log/backup_db.log \
|
LINES="$(kapow get /request/params/lines)"
|
||||||
| tail -n"$LINES" \
|
FILTER="$(kapow get /request/params/filter)"
|
||||||
| kapow set /response/body
|
grep "$FILTER" /var/log/backup_db.log \
|
||||||
```
|
| tail -n"$LINES" \
|
||||||
|
| kapow set /response/body
|
||||||
|
|
||||||
#. Advanced database monitoring
|
#. Advanced database monitoring
|
||||||
|
|
||||||
@@ -104,36 +112,57 @@ User Journey
|
|||||||
- Problem/Motivation:
|
- Problem/Motivation:
|
||||||
- pre-Kapow! solution:
|
- pre-Kapow! solution:
|
||||||
- Kapow!-enabled solution:
|
- Kapow!-enabled solution:
|
||||||
```
|
|
||||||
{
|
From this:
|
||||||
echo Memory:
|
|
||||||
free -m
|
.. code-block:: sh
|
||||||
echo ================================================================================
|
|
||||||
echo Load:
|
echo Date: | kapow set /response/body
|
||||||
uptime
|
echo ======...==== | kapow set /response/body
|
||||||
echo ================================================================================
|
echo Memory | kapow set /response/body
|
||||||
echo Disk:
|
# ...
|
||||||
df -h
|
|
||||||
} | kapow set /response/body
|
|
||||||
```
|
To this:
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
{
|
||||||
|
echo Date:
|
||||||
|
date
|
||||||
|
echo ================================================================================
|
||||||
|
echo Memory:
|
||||||
|
free -m
|
||||||
|
echo ================================================================================
|
||||||
|
echo Load:
|
||||||
|
uptime
|
||||||
|
echo ================================================================================
|
||||||
|
echo Disk:
|
||||||
|
df -h
|
||||||
|
} | kapow set /response/body
|
||||||
|
|
||||||
#. Share your achievements
|
#. Share your achievements
|
||||||
|
|
||||||
- User Learns: Format a complex HTTP response with JSON format to feed the corporate dashboard.
|
- User Learns: Format a complex HTTP response with JSON format to feed the corporate dashboard.
|
||||||
- Kapow! Concepts: backtick interpolation and `kapow set /response/headers`
|
- Kapow! Concepts: backtick interpolation and `kapow set /response/headers`
|
||||||
- Problem/Motivation:
|
- Problem/Motivation:
|
||||||
- pre-Kapow! solution:
|
- pre-Kapow! solution: Write a php/perl/python script to serve this
|
||||||
- Kapow!-enabled solution:
|
- Kapow!-enabled solution:
|
||||||
``` DON'T HANDWRITE JSON
|
|
||||||
echo "{memory: `free -m`, ...uups..}' | kapow set /response/body
|
|
||||||
```
|
|
||||||
|
|
||||||
``` USE JQ
|
Don't handwrite JSON
|
||||||
MEMORY=$(free -m)
|
|
||||||
LOAD=$(uptime)
|
.. code-block:: sh
|
||||||
DISK=$(df -h)
|
|
||||||
jq -nc --arg memory "$MEMORY" '{"memory": $memory}'
|
echo "{memory: `free -m`, ...uups..}" | kapow set /response/body
|
||||||
```
|
|
||||||
|
Use jq
|
||||||
|
|
||||||
|
.. code-block:: sh
|
||||||
|
|
||||||
|
MEMORY=$(free -m)
|
||||||
|
LOAD=$(uptime)
|
||||||
|
DISK=$(df -h)
|
||||||
|
jq -nc --arg memory "$MEMORY" '{"memory": $memory}'
|
||||||
|
|
||||||
Ideas
|
Ideas
|
||||||
-----
|
-----
|
||||||
|
|||||||
Reference in New Issue
Block a user