Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
VERSION=0.0.7
GITCOMMIT?=$(shell git describe --dirty --always 2>/dev/null)
LDFLAGS=-ldflags "-w -s -X main.version=${VERSION} -X main.commit=${GITCOMMIT}"
LDFLAGS=-ldflags "-w -s -X main.version=${VERSION}"
all: mackerel-plugin-linux-memory

.PHONY: mackerel-plugin-linux-process-status
.PHONY: mackerel-plugin-linux-memory linux check lint

mackerel-plugin-linux-memory: *.go
go build $(LDFLAGS) -o mackerel-plugin-linux-memory
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ linux-memory.free 989589504 1627264100
### オプション

```bash
$ ./mackerel-plugin-linux-memory --version
mackerel-plugin-linux-memory 0.0.7
Compiler: gc go1.25.0
Usage:
mackerel-plugin-linux-memory [OPTIONS]

Application Options:
-v, --version Show version

Help Options:
-h, --help Show this help message
```

## Metrics
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ module github.com/monitoring-forge/mackerel-plugin-linux-memory
go 1.25.0

require (
github.com/jessevdk/go-flags v1.6.1
github.com/mackerelio/go-mackerel-plugin v0.1.6
github.com/prometheus/procfs v0.22.0
github.com/stretchr/testify v1.12.1
)

require (
github.com/jessevdk/go-flags v1.6.1 // indirect
github.com/mackerelio/checkers v0.2.1 // indirect
)

require (
github.com/mackerelio/golib v1.2.2 // indirect
github.com/monitoring-forge/flagrun v0.0.8
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.41.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=
github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc=
github.com/mackerelio/checkers v0.2.1 h1:vRXzAT+CEyaLjSrHVxKUBjyWq1kfo8QcI8ZoSKZATQs=
github.com/mackerelio/checkers v0.2.1/go.mod h1:CW3k/5bvHhxDrfKgWvMvNH0R51zco141ZVxlI7o/KAc=
github.com/mackerelio/go-mackerel-plugin v0.1.6 h1:NKAutTQLxBH8/T0aeawIMfPSg4ZRf+TivkOwgUK2Yj0=
github.com/mackerelio/go-mackerel-plugin v0.1.6/go.mod h1:2OkQFK5HpUiVJ+p8Xa8wwxzaPusUFTNsj5OQjL9Mw7k=
github.com/mackerelio/golib v1.2.2 h1:fQfW1o2KvPyIsAH/7+M2J0gpf2jLu+NyYpDCN79zxW4=
github.com/mackerelio/golib v1.2.2/go.mod h1:itcSOfrsT5XvkzflFPebT43RrliaKDz2T6YGYt3jclw=
github.com/monitoring-forge/flagrun v0.0.8 h1:CEoMMdFpZ4KOTiBy2mAUQtlgFsTqpvpEoLjzanDgEtw=
github.com/monitoring-forge/flagrun v0.0.8/go.mod h1:yAwxGIEx81wU4JOMp6hz7SdSYWgT/Hr4JXEdHlEn1mw=
github.com/prometheus/procfs v0.22.0 h1:6q9+/JL9IKAPbCmBrv9n5O5Ty3NKnciV5X7YGw0oics=
github.com/prometheus/procfs v0.22.0/go.mod h1:CvmFr/GVhIjIvWJZW3tgkODBQMRIf0EyWMQLHCHab58=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
Expand Down
36 changes: 6 additions & 30 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package main

import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/jessevdk/go-flags"
mp "github.com/mackerelio/go-mackerel-plugin"
"github.com/monitoring-forge/flagrun"
)

var version string
var commit string

const (
OK = iota
Expand All @@ -24,32 +20,12 @@ type Opt struct {
Version bool `short:"v" long:"version" description:"Show version"`
}

func main() {
opt := Opt{}
psr := flags.NewParser(&opt, flags.HelpFlag|flags.PassDoubleDash)
_, err := psr.Parse()
if opt.Version {
if commit == "" {
commit = "dev"
}
fmt.Printf(
"%s-%s\n%s/%s, %s, %s\n",
filepath.Base(os.Args[0]),
version,
runtime.GOOS,
runtime.GOARCH,
runtime.Version(),
commit)
os.Exit(OK)
} else if flags.WroteHelp(err) {
fmt.Fprintf(os.Stdout, "%v\n", err)
os.Exit(OK)
} else if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(UNKNOWN)
}

func (o *Opt) Run(_ []string) {
u := LinuxMemoryPlugin{}
plugin := mp.NewMackerelPlugin(u)
plugin.Run()
}

func main() {
os.Exit(flagrun.Ship(&Opt{}, flagrun.Version(version)))
}
Loading