Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workaround for Windows path and update README about plugin path #32

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
45 changes: 41 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,37 @@ CRITICAL (or WARNING) alert is issued if no metric has been posted since the min

## Setting for mackerel-agent
You can install the plugin by `mkr` command.

##### Linux
```
sudo mkr plugin install check-mackerel-metric
```

##### Windows
(by Administrator)

```
"C:\Program Files\Mackerel\mackerel-agent\mkr.exe" plugin install check-mackerel-metric
```

Add plugin configuration into mackerel-agent.conf.

##### Linux
```
[plugin.checks.metric-myhost]
command = ["/opt/mackerel-agent/plugins/bin/check-mackerel-metric", "-H", "HOST_ID", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]

[plugin.checks.metric-myservice]
command = ["/opt/mackerel-agent/plugins/bin/check-mackerel-metric", "-s", "SERVICE_NAME", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]
```

##### Windows
```
[plugin.checks.metric-myhost]
command = ["check-mackerel-metric", "-H", "HOST_ID", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]
command = ["plugins\\bin\\check-mackerel-metric.exe", "-H", "HOST_ID", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]

[plugin.checks.metric-myservice]
command = ["check-mackerel-metric", "-s", "SERVICE_NAME", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]
command = ["plugins\\bin\\check-mackerel-metric.exe", "-s", "SERVICE_NAME", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]
```

## Usage
Expand Down Expand Up @@ -75,18 +94,36 @@ check-mackerel-metric -s SERVICE_NAME -n METRIC_NAME -w WARNING_MINUTE -c CRITIC
## mackerel-agentでの設定
プラグインは `mkr` コマンドでインストールできます。

##### Linux
```
sudo mkr plugin install check-mackerel-metric
```

##### Windows
(管理者権限)

```
"C:\Program Files\Mackerel\mackerel-agent\mkr.exe" plugin install check-mackerel-metric
```

mackerel-agent.conf にプラグインの設定を記述してください。

##### Linux
```
[plugin.checks.metric-myhost]
command = ["/opt/mackerel-agent/plugins/bin/check-mackerel-metric", "-H", "HOST_ID", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]

[plugin.checks.metric-myservice]
command = ["/opt/mackerel-agent/plugins/bin/check-mackerel-metric", "-s", "SERVICE_NAME", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]
```

##### Windows
```
[plugin.checks.metric-myhost]
command = ["check-mackerel-metric", "-H", "HOST_ID", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]
command = ["plugins\\bin\\check-mackerel-metric.exe", "-H", "HOST_ID", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]

[plugin.checks.metric-myservice]
command = ["check-mackerel-metric", "-s", "SERVICE_NAME", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]
command = ["plugins\\bin\\check-mackerel-metric.exe", "-s", "SERVICE_NAME", "-n", "METRIC_NAME", "-w", "WARNING_MINUTE", "-c", "CRITICAL_MINUTE"]
```

## 使い方
Expand Down
14 changes: 13 additions & 1 deletion checkmackerelmetric/checkmackerelmetric.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package checkmackerelmetric
import (
"fmt"
"os"
"path/filepath"
"runtime"
"time"

"github.com/alexflint/go-arg"
Expand Down Expand Up @@ -85,7 +87,17 @@ func (opts *mackerelMetricOpts) run() *checkers.Checker {

conf, err := config.LoadConfig(config.DefaultConfig.Conffile)
if err != nil {
return checkers.Unknown(fmt.Sprintf("%v", err))
if runtime.GOOS == "windows" {
newpath := filepath.Join(config.DefaultConfig.Conffile, "../../../mackerel-agent.conf")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note]
It will probably be something like this:

C:\Program Files\Mackerel\mackerel-agent\plugins\bin\mackerel-agent.conf\..\..\..\mackerel-agent.conf
 ↓
C:\Program Files\Mackerel\mackerel-agent\mackerel-agent.conf

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! it looks ugly workaround, but it is hard to change mackerel-agent config logic.

conf, err = config.LoadConfig(newpath)
if err != nil {
return checkers.Unknown(fmt.Sprintf("%v", err))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the following kind of code would also be good.

Suggested change
return checkers.Unknown(fmt.Sprintf("%v", err))
return checkers.Unknown(err.Error())

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll apply it to other projects... 😻

}
conf.Conffile = newpath
conf.Root = filepath.Dir(newpath)
} else {
return checkers.Unknown(fmt.Sprintf("%v", err))
}
}
apibase := conf.Apibase
if apikey == "" {
Expand Down
Loading