Permalink
Browse files

Merge pull request #21 from mackerelio/mackerel_plugin_workdir

MACKEREL_PLUGIN_WORKDIR
  • Loading branch information...
2 parents 28e053d + 42f2139 commit 04727eebfbb32b6ba54880d497fcaf94f18be810 @Songmu Songmu committed on GitHub Sep 14, 2016
Showing with 7 additions and 2 deletions.
  1. +7 −2 mackerel-plugin.go
View
@@ -124,7 +124,8 @@ func (h *MackerelPlugin) saveValues(values map[string]interface{}, now time.Time
if !h.hasDiff() {
return nil
}
- f, err := os.Create(h.tempfilename())
+ fname := h.tempfilename()
+ f, err := os.Create(fname)
if err != nil {
return err
}
@@ -190,7 +191,11 @@ func (h *MackerelPlugin) tempfilename() string {
prefix = p.MetricKeyPrefix()
}
filename := fmt.Sprintf("mackerel-plugin-%s", prefix)
- h.Tempfile = filepath.Join(os.TempDir(), filename)
+ dir := os.Getenv("MACKEREL_PLUGIN_WORKDIR")
+ if dir == "" {
+ dir = os.TempDir()
+ }
+ h.Tempfile = filepath.Join(dir, filename)
}
return h.Tempfile
}

0 comments on commit 04727ee

Please sign in to comment.