mirror of
https://codeberg.org/scip/io-exporter.git
synced 2025-12-18 04:51:02 +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/
|
||||
# .vscode/
|
||||
|
||||
# build residue
|
||||
io-exporter
|
||||
|
||||
# test deployments
|
||||
*.yaml
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ WORKDIR /work
|
||||
COPY go.mod .
|
||||
COPY . .
|
||||
RUN go mod download
|
||||
RUN go build
|
||||
RUN make
|
||||
|
||||
FROM alpine:latest
|
||||
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
|
||||
mkdir 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
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Version = `v0.0.2`
|
||||
Version = `v0.0.4`
|
||||
SLEEP = 5
|
||||
Usage = `io-exporter [options] <file>
|
||||
Options:
|
||||
@@ -23,6 +23,7 @@ Options:
|
||||
-s --sleeptime <int> Time to sleep between checks (default: 5s)
|
||||
-l --label <label=value> Add label to exported metric
|
||||
-i --internals Also add labels about resource usage
|
||||
-d --debug Enable debug log level
|
||||
-h --help Show help
|
||||
-v --version Show program version`
|
||||
)
|
||||
@@ -32,10 +33,11 @@ type Config struct {
|
||||
Showversion bool `koanf:"version"` // -v
|
||||
Showhelp bool `koanf:"help"` // -h
|
||||
Internals bool `koanf:"internals"` // -i
|
||||
Debug bool `koanf:"debug"` // -d
|
||||
Label []string `koanf:"label"` // -v
|
||||
Timeout int `koanf:"timeout"` // -t
|
||||
Port int `koanf:"port"` // -p
|
||||
Sleeptime int `koanf:"sleep"` // -s
|
||||
Sleeptime int `koanf:"sleeptime"` // -s
|
||||
|
||||
File string
|
||||
Labels []Label
|
||||
@@ -56,6 +58,7 @@ func InitConfig(output io.Writer) (*Config, error) {
|
||||
// parse commandline flags
|
||||
flagset.BoolP("version", "v", false, "show program version")
|
||||
flagset.BoolP("help", "h", false, "show help")
|
||||
flagset.BoolP("debug", "d", false, "enable debug logs")
|
||||
flagset.BoolP("internals", "i", false, "add internal metrics")
|
||||
flagset.StringArrayP("label", "l", nil, "additional labels")
|
||||
flagset.IntP("timeout", "t", 1, "timeout for file operation in seconds")
|
||||
|
||||
@@ -7,14 +7,18 @@ import (
|
||||
"github.com/lmittmann/tint"
|
||||
)
|
||||
|
||||
func setLogger(output io.Writer) {
|
||||
func setLogger(output io.Writer, debug bool) {
|
||||
logLevel := &slog.LevelVar{}
|
||||
opts := &tint.Options{
|
||||
Level: logLevel,
|
||||
AddSource: false,
|
||||
}
|
||||
|
||||
logLevel.Set(slog.LevelDebug)
|
||||
if debug {
|
||||
logLevel.Set(slog.LevelDebug)
|
||||
} else {
|
||||
logLevel.Set(slog.LevelInfo)
|
||||
}
|
||||
|
||||
handler := tint.NewHandler(output, opts)
|
||||
logger := slog.New(handler)
|
||||
|
||||
@@ -18,10 +18,15 @@ func Run() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if conf.Showversion {
|
||||
fmt.Printf("This is io-exporter version %s\n", Version)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
metrics := NewMetrics(conf)
|
||||
alloc := NewAlloc()
|
||||
|
||||
setLogger(os.Stdout)
|
||||
setLogger(os.Stdout, conf.Debug)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
@@ -32,6 +37,7 @@ func Run() {
|
||||
// ns => s
|
||||
now := time.Now()
|
||||
elapsed := float64(now.Sub(start).Nanoseconds()) / 10000000000
|
||||
slog.Debug("elapsed time", "elapsed", elapsed, "result", result)
|
||||
|
||||
metrics.Set(result, elapsed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user