Skip to content

Commit

Permalink
mirrors/monitor: Split files out using the Snippets syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
iBug committed Dec 31, 2023
1 parent 2ed59ce commit 81963b0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
6 changes: 6 additions & 0 deletions docs/assets/mirrors/connection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

port_list_input=${1//:/|}
port_list=${port_list_input:-"80|443"}
netstat -ntW | gawk '{print tolower($6),gensub(/^(.+):([^:]+)$/,"\\1 \\2","g",$4)}' | grep -P " ($port_list)\$" | sort | uniq -c | sort -k 4 -k 3 | awk "{printf(\"connection,protocol=tcp,port=%s,address=%s %s=%s\n\",\$4,\$3,\$2,\$1)}"
netstat -ntW | gawk '{print tolower($6),gensub(/^(.+):([^:]+)$/,"\\2","g",$4)}' | grep -P " ($port_list)\$" | sort | uniq -c | sort -k 3 | awk "{printf(\"connection,protocol=tcp,port=%s,address=any %s=%s\n\",\$3,\$2,\$1)}"
3 changes: 3 additions & 0 deletions docs/assets/mirrors/nfacct.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sudo nfacct list | awk '-F[ ,;]' "{printf(\"nfacct,object=%s bytes=%i,pkgs=%i\n\",\$11,\$8,\$4)}"
3 changes: 3 additions & 0 deletions docs/assets/mirrors/process.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

ps -e -o s= -o comm= | grep -v '^S' | sort | uniq -c | awk '{printf("process,state=%s,name=%s count=%i\n",$2,$3,$1)}'
8 changes: 8 additions & 0 deletions docs/assets/mirrors/telegraf-exec.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[inputs.exec]]
commands = [
"/opt/monitor/telegraf/connection.sh 21:80:443:873:9418",
"/opt/monitor/telegraf/nfacct.sh",
"/opt/monitor/telegraf/process.sh",
]
timeout = "5s"
data_format = "influx"
24 changes: 4 additions & 20 deletions docs/services/mirrors/monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,17 @@
## Connections (Users online)

```toml title="/etc/telegraf/telegraf.d/exec.conf"
[[inputs.exec]]
commands = [
"/opt/monitor/telegraf/connection.sh 21:80:443:873:9418",
"/opt/monitor/telegraf/nfacct.sh",
"/opt/monitor/telegraf/process.sh",
]
timeout = "5s"
data_format = "influx"
--8<-- "mirrors/telegraf-exec.conf"
```

```shell title="/opt/monitor/telegraf/connection.sh"
#!/bin/bash

port_list_input=${1//:/|}
port_list=${port_list_input:-"80|443"}
netstat -ntW | gawk '{print tolower($6),gensub(/^(.+):([^:]+)$/,"\\1 \\2","g",$4)}' | grep -P " ($port_list)\$" | sort | uniq -c | sort -k 4 -k 3 | awk "{printf(\"connection,protocol=tcp,port=%s,address=%s %s=%s\n\",\$4,\$3,\$2,\$1)}"
netstat -ntW | gawk '{print tolower($6),gensub(/^(.+):([^:]+)$/,"\\2","g",$4)}' | grep -P " ($port_list)\$" | sort | uniq -c | sort -k 3 | awk "{printf(\"connection,protocol=tcp,port=%s,address=any %s=%s\n\",\$3,\$2,\$1)}"
--8<-- "mirrors/connection.sh"
```

```shell title="/opt/monitor/telegraf/nfacct.sh"
#!/bin/bash

sudo nfacct list | awk '-F[ ,;]' "{printf(\"nfacct,object=%s bytes=%i,pkgs=%i\n\",\$11,\$8,\$4)}"
--8<-- "mirrors/nfacct.sh"
```

```shell title="/opt/monitor/telegraf/process.sh"
#!/bin/bash

ps -e -o s= -o comm= | grep -v '^S' | sort | uniq -c | awk '{printf("process,state=%s,name=%s count=%i\n",$2,$3,$1)}'
--8<-- "mirrors/process.sh"
```
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ markdown_extensions:
emoji_generator: !!python/name:material.extensions.emoji.to_svg
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.snippets:
base_path: [docs/assets/]
- pymdownx.superfences
- pymdownx.tilde
- toc:
Expand Down

0 comments on commit 81963b0

Please sign in to comment.