Skip to content

Commit

Permalink
[mackerel-plugin-windows-server-sessions] add -legacymetricname optio…
Browse files Browse the repository at this point in the history
…n for compatibility
  • Loading branch information
Arthur1 committed Feb 29, 2024
1 parent 4847dba commit 280503b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mackerel-plugin-windows-server-sessions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Windows Server Sessions custom metrics plugin for mackerel-agent.
## Usage

```shell
mackerel-plugin-windows-server-sessions
mackerel-plugin-windows-server-sessions [-legacymetricname]
```

## Example of mackerel-agent.conf
Expand Down
10 changes: 9 additions & 1 deletion mackerel-plugin-windows-server-sessions/lib/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

// WindowsServerSessionsPlugin store the name of servers
type WindowsServerSessionsPlugin struct {
LegacyMetricName bool
}

// cf.) https://learn.microsoft.com/en-us/previous-versions/aa394265(v=vs.85)
Expand Down Expand Up @@ -56,8 +57,13 @@ func (m WindowsServerSessionsPlugin) FetchMetrics() (map[string]interface{}, err
}
stat := make(map[string]interface{}, len(counts))
for _, v := range counts {
var nodeMetricKey string
// node name of Windows can contain ".", which is the metric name delimiter on Mackerel.
nodeMetricKey := strings.ReplaceAll(v.Node, ".", "_")
if m.LegacyMetricName {
nodeMetricKey = v.Node
} else {
nodeMetricKey = strings.ReplaceAll(v.Node, ".", "_")
}
stat["windows.server.sessions."+nodeMetricKey+".count"] = v.ServerSessions
}
return stat, nil
Expand All @@ -79,9 +85,11 @@ func (m WindowsServerSessionsPlugin) GraphDefinition() map[string](mp.Graphs) {
// Do the plugin
func Do() {
optTempfile := flag.String("tempfile", "", "Temp file name")
legacyMetricName := flag.Bool("legacymetricname", false, `Prevent escaping "." in the node name for metric keys`)
flag.Parse()

var plugin WindowsServerSessionsPlugin
plugin.LegacyMetricName = *legacyMetricName

helper := mp.NewMackerelPlugin(plugin)

Expand Down

0 comments on commit 280503b

Please sign in to comment.