mirror of
https://codeberg.org/scip/io-exporter.git
synced 2025-12-18 21:11:01 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b3cf64e96 | ||
| 755e79b72d | |||
| 9b75f96207 | |||
| 03e1deb89c | |||
| 7a15530855 | |||
| c7eb782b88 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -31,4 +31,10 @@ go.work.sum
|
|||||||
# .idea/
|
# .idea/
|
||||||
# .vscode/
|
# .vscode/
|
||||||
|
|
||||||
|
# build residue
|
||||||
io-exporter
|
io-exporter
|
||||||
|
|
||||||
|
# test deployments
|
||||||
|
*.yaml
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ WORKDIR /work
|
|||||||
COPY go.mod .
|
COPY go.mod .
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
RUN go build
|
RUN make
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
LABEL maintainer="Thomas von Dein <git@daemon.de>"
|
LABEL maintainer="Thomas von Dein <git@daemon.de>"
|
||||||
|
|||||||
2
Makefile
Normal file
2
Makefile
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
all:
|
||||||
|
CGO_LDFLAGS='-static' go build -tags osusergo,netgo -ldflags "-extldflags=-static" -o io-exporter
|
||||||
@@ -67,9 +67,14 @@ To run locally:
|
|||||||
```default
|
```default
|
||||||
mkdir t
|
mkdir t
|
||||||
chmod 1777 t
|
chmod 1777 t
|
||||||
docker compose run -v ./t:/pvc ioexporter /pvc/blah
|
docker compose run -v ./t:/pvc ioexporter /pvc/testfile
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or use the pre-build image:
|
||||||
|
|
||||||
|
```default
|
||||||
|
docker run -u `id -u $USER` -v ./t:/pvc ghcr.io/tlinden/io-exporter:latest /pvc/testfile
|
||||||
|
```
|
||||||
|
|
||||||
# Report bugs
|
# Report bugs
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = `v0.0.2`
|
Version = `v0.0.4`
|
||||||
SLEEP = 5
|
SLEEP = 5
|
||||||
Usage = `io-exporter [options] <file>
|
Usage = `io-exporter [options] <file>
|
||||||
Options:
|
Options:
|
||||||
@@ -23,6 +23,7 @@ Options:
|
|||||||
-s --sleeptime <int> Time to sleep between checks (default: 5s)
|
-s --sleeptime <int> Time to sleep between checks (default: 5s)
|
||||||
-l --label <label=value> Add label to exported metric
|
-l --label <label=value> Add label to exported metric
|
||||||
-i --internals Also add labels about resource usage
|
-i --internals Also add labels about resource usage
|
||||||
|
-d --debug Enable debug log level
|
||||||
-h --help Show help
|
-h --help Show help
|
||||||
-v --version Show program version`
|
-v --version Show program version`
|
||||||
)
|
)
|
||||||
@@ -32,10 +33,11 @@ type Config struct {
|
|||||||
Showversion bool `koanf:"version"` // -v
|
Showversion bool `koanf:"version"` // -v
|
||||||
Showhelp bool `koanf:"help"` // -h
|
Showhelp bool `koanf:"help"` // -h
|
||||||
Internals bool `koanf:"internals"` // -i
|
Internals bool `koanf:"internals"` // -i
|
||||||
|
Debug bool `koanf:"debug"` // -d
|
||||||
Label []string `koanf:"label"` // -v
|
Label []string `koanf:"label"` // -v
|
||||||
Timeout int `koanf:"timeout"` // -t
|
Timeout int `koanf:"timeout"` // -t
|
||||||
Port int `koanf:"port"` // -p
|
Port int `koanf:"port"` // -p
|
||||||
Sleeptime int `koanf:"sleep"` // -s
|
Sleeptime int `koanf:"sleeptime"` // -s
|
||||||
|
|
||||||
File string
|
File string
|
||||||
Labels []Label
|
Labels []Label
|
||||||
@@ -56,6 +58,7 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
// parse commandline flags
|
// parse commandline flags
|
||||||
flagset.BoolP("version", "v", false, "show program version")
|
flagset.BoolP("version", "v", false, "show program version")
|
||||||
flagset.BoolP("help", "h", false, "show help")
|
flagset.BoolP("help", "h", false, "show help")
|
||||||
|
flagset.BoolP("debug", "d", false, "enable debug logs")
|
||||||
flagset.BoolP("internals", "i", false, "add internal metrics")
|
flagset.BoolP("internals", "i", false, "add internal metrics")
|
||||||
flagset.StringArrayP("label", "l", nil, "additional labels")
|
flagset.StringArrayP("label", "l", nil, "additional labels")
|
||||||
flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds")
|
flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds")
|
||||||
|
|||||||
@@ -7,14 +7,18 @@ import (
|
|||||||
"github.com/lmittmann/tint"
|
"github.com/lmittmann/tint"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setLogger(output io.Writer) {
|
func setLogger(output io.Writer, debug bool) {
|
||||||
logLevel := &slog.LevelVar{}
|
logLevel := &slog.LevelVar{}
|
||||||
opts := &tint.Options{
|
opts := &tint.Options{
|
||||||
Level: logLevel,
|
Level: logLevel,
|
||||||
AddSource: false,
|
AddSource: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
logLevel.Set(slog.LevelDebug)
|
if debug {
|
||||||
|
logLevel.Set(slog.LevelDebug)
|
||||||
|
} else {
|
||||||
|
logLevel.Set(slog.LevelInfo)
|
||||||
|
}
|
||||||
|
|
||||||
handler := tint.NewHandler(output, opts)
|
handler := tint.NewHandler(output, opts)
|
||||||
logger := slog.New(handler)
|
logger := slog.New(handler)
|
||||||
|
|||||||
@@ -18,10 +18,15 @@ func Run() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.Showversion {
|
||||||
|
fmt.Printf("This is io-exporter version %s\n", Version)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
metrics := NewMetrics(conf)
|
metrics := NewMetrics(conf)
|
||||||
alloc := NewAlloc()
|
alloc := NewAlloc()
|
||||||
|
|
||||||
setLogger(os.Stdout)
|
setLogger(os.Stdout, conf.Debug)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@@ -32,6 +37,7 @@ func Run() {
|
|||||||
// ns => s
|
// ns => s
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
elapsed := float64(now.Sub(start).Nanoseconds()) / 10000000000
|
elapsed := float64(now.Sub(start).Nanoseconds()) / 10000000000
|
||||||
|
slog.Debug("elapsed time", "elapsed", elapsed, "result", result)
|
||||||
|
|
||||||
metrics.Set(result, elapsed)
|
metrics.Set(result, elapsed)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user