-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 889e1f5
Showing
18 changed files
with
1,045 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
dist/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This is an example .goreleaser.yml file with some sensible defaults. | ||
# Make sure to check the documentation at https://goreleaser.com | ||
|
||
project_name: "diskscript" | ||
before: | ||
hooks: | ||
# You may remove this if you don't use go modules. | ||
- go mod tidy | ||
# you may remove this if you don't need go generate | ||
- go generate ./... | ||
builds: | ||
- binary: diskscript | ||
main: ./cmd/diskscript/main.go | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
|
||
archives: | ||
- format: tar.gz | ||
# this name template makes the OS and Arch compatible with the results of uname. | ||
name_template: >- | ||
{{ .ProjectName }}_ | ||
{{- title .Os }}_ | ||
{{- if eq .Arch "amd64" }}x86_64 | ||
{{- else if eq .Arch "386" }}i386 | ||
{{- else }}{{ .Arch }}{{ end }} | ||
{{- if .Arm }}v{{ .Arm }}{{ end }} | ||
# use zip for windows archives | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ incpatch .Version }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
# The lines beneath this are called `modelines`. See `:help modeline` | ||
# Feel free to remove those if you don't want/use them. | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
自用的一个服务器磁盘监控工具,根据磁盘占用执行对应的脚本,可以结合alertmanager发送报警。 | ||
- 挂载设备百分比监控 | ||
- 目录大小监控 | ||
- 文件大小监控 | ||
- 支持发送到alertmanager报警,自定义labels和报警名称 | ||
- 二进制直接使用 | ||
|
||
`config.yml` 配置文件示例 | ||
```yml | ||
console: true # 是否输出脚本执行信息 | ||
alert: # alertmanager | ||
enable: true # 启用报警 | ||
url: "http://localhost:9093" | ||
labels: ["env=dev","sp=aliyun"] # 全局labels,添加到所有报警中 | ||
mount: # 挂载设备 | ||
- mount: "/" # 根分区超过90%占用报警 | ||
threshold: 90 | ||
alert: true # 超过阈值报警 | ||
labels: ["disk=/"] # 自定义alertmanager labels (可选) | ||
alertname: "根分区磁盘占用过大" # 自定义报警名称(可选) | ||
scripts: # 可选 | ||
- "/bin/sh /data/scripts/xxx.sh" | ||
directory: # 挂载目录 | ||
- directory: "/data/logs/nginx/" | ||
threshold: 5g # 限制5g 超过5g报警 | ||
alert: true | ||
scripts: # 执行脚本 | ||
- "/data/scripts/nginx-log.sh" | ||
- directory: "/data/logs/ets2/" | ||
threshold: 5g # 限制 | ||
scripts: # 执行脚本 | ||
- "find /data/logs/xxx -mtime +7 -delete" | ||
- "find /data/logs/xxx -mtime +7 -delete" | ||
file: # 文件占用检查 | ||
- file: "/mnt/d/ISO/Windows.iso" | ||
threshold: 5g # 限制 | ||
alert: true | ||
scripts: # 执行脚本 | ||
- "find /data/logs/xxx -mtime +7 -delete" | ||
- "find /data/logs/xxx -mtime +7 -delete" | ||
- file: "/mnt/d/ISO/ubuntu-21.10-desktop-amd64.iso" | ||
threshold: 4g # 限制 | ||
alert: true | ||
scripts: # 执行脚本 | ||
- "cat /dev/null > /data/logs/nginx/blog_access.log" | ||
- "/data/scripts/1.py" | ||
``` | ||
可作为定时任务使用 | ||
```shell | ||
* * * * * cd /data/xxx && ./diskscript | ||
``` | ||
|
||
#### 下载使用 | ||
```shell | ||
tar xvf diskscript_Linux_x86_64.tar.gz | ||
chmod +x diskscript | ||
# 编辑config.yml文件 | ||
# 执行程序 | ||
./diskscript | ||
# 指定配置文件 | ||
./diskscript -conf xxx.yml | ||
``` | ||
![](images/1.png) | ||
![](images/2.png) | ||
![](images/3.png) | ||
![](images/4.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
console: true # script 脚本输出 | ||
alert: # alertmanager | ||
enable: true | ||
url: "http://192.168.100.192:9093" | ||
labels: ["env2=dev"] # 全局labels | ||
mount: # 挂载设备 | ||
- mount: "/" | ||
threshold: 60 # 限制 60% | ||
alert: true | ||
alertname: "根磁盘挂载超过限制" | ||
labels: ["env=dev"] | ||
scripts: # 执行脚本 | ||
- "/tmp/1.sh args1" | ||
- "/tmp/2.sh" | ||
- mount: "/boot" | ||
threshold: 60 | ||
scripts: | ||
- "/tmp/1.sh pars" | ||
- mount: "/home" | ||
threshold: 60 | ||
scripts: | ||
- "/tmp/1.sh pars" | ||
directory: | ||
- directory: "/data/logs/nginx/89.log" | ||
threshold: 20m # 限制 | ||
alert: true | ||
scripts: # 执行脚本 | ||
- "cat /dev/null > /data/logs/nginx/blog_access.log && cat /dev/null > /data/logs/nginx/access_music.log" | ||
- "/data/scripts/1.py" | ||
- directory: "/data/logs" | ||
threshold: 1g # 限制 | ||
scripts: # 执行脚本 | ||
- "/tmp/1.sh pars" | ||
- "/data/scripts/1.py" | ||
- directory: "/data/mysql-backu" | ||
threshold: 100m | ||
scripts: | ||
- "/tmp/1.sh pars" | ||
- "/data/scripts/1.py" | ||
- "/data/scripts/logs-rm.sh" | ||
- directory: "/data/mysql-backup" | ||
threshold: 100m | ||
scripts: | ||
- "/tmp/1.sh pars" | ||
- "/data/scripts/1.py" | ||
- "/data/scripts/logs-rm.sh" | ||
file: | ||
- file: "/mnt/d/ISO/Windows.iso" | ||
threshold: 5g # 限制 | ||
alert: true | ||
scripts: # 执行脚本 | ||
- "cat /dev/null > /data/logs/nginx/blog_access.log && cat /dev/null > /data/logs/nginx/access_music.log" | ||
- "/data/scripts/1.py" | ||
- file: "/mnt/d/ISO/ubuntu-21.10-desktop-amd64.iso" | ||
threshold: 4g # 限制 | ||
alert: true | ||
scripts: # 执行脚本 | ||
- "cat /dev/null > /data/logs/nginx/blog_access.log && cat /dev/null > /data/logs/nginx/access_music.log" | ||
- "/data/scripts/1.py" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"diskscript/pkg/diskscript" | ||
"flag" | ||
) | ||
|
||
var configfile string | ||
|
||
func init() { | ||
flag.StringVar(&configfile, "conf", "config.yml", "指定配置文件") | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
diskscript.Execute(configfile) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module diskscript | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/go-openapi/runtime v0.25.0 | ||
github.com/go-openapi/strfmt v0.21.3 | ||
github.com/prometheus/alertmanager v0.25.0 | ||
github.com/prometheus/common v0.39.0 | ||
github.com/shirou/gopsutil v3.21.11+incompatible | ||
golang.org/x/mod v0.7.0 | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
) | ||
|
||
require ( | ||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect | ||
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect | ||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/go-logr/logr v1.2.3 // indirect | ||
github.com/go-logr/stdr v1.2.2 // indirect | ||
github.com/go-ole/go-ole v1.2.6 // indirect | ||
github.com/go-openapi/analysis v0.21.4 // indirect | ||
github.com/go-openapi/errors v0.20.3 // indirect | ||
github.com/go-openapi/jsonpointer v0.19.5 // indirect | ||
github.com/go-openapi/jsonreference v0.20.0 // indirect | ||
github.com/go-openapi/loads v0.21.2 // indirect | ||
github.com/go-openapi/spec v0.20.7 // indirect | ||
github.com/go-openapi/swag v0.22.3 // indirect | ||
github.com/go-openapi/validate v0.22.0 // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/jpillora/backoff v1.0.0 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect | ||
github.com/oklog/ulid v1.3.1 // indirect | ||
github.com/opentracing/opentracing-go v1.2.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/prometheus/client_golang v1.14.0 // indirect | ||
github.com/prometheus/client_model v0.3.0 // indirect | ||
github.com/prometheus/procfs v0.8.0 // indirect | ||
github.com/yusufpapurcu/wmi v1.2.2 // indirect | ||
go.mongodb.org/mongo-driver v1.11.0 // indirect | ||
go.opentelemetry.io/otel v1.11.1 // indirect | ||
go.opentelemetry.io/otel/trace v1.11.1 // indirect | ||
golang.org/x/net v0.4.0 // indirect | ||
golang.org/x/oauth2 v0.3.0 // indirect | ||
golang.org/x/sys v0.3.0 // indirect | ||
golang.org/x/text v0.5.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.28.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) |
Oops, something went wrong.