Skip to content

Commit 69cfc3e

Browse files
committed
Add timestamp and Schema
1 parent 7b72f59 commit 69cfc3e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

main.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"math"
66
"strings"
7+
"time"
78

89
corev2 "github.com/sensu/core/v2"
910
"github.com/sensu/sensu-plugin-sdk/sensu"
@@ -15,6 +16,7 @@ type Config struct {
1516
sensu.PluginConfig
1617
CPU float64
1718
Memory float32
19+
Scheme string
1820
}
1921

2022
var (
@@ -43,6 +45,14 @@ var (
4345
Usage: "Show metrics for processes above Memory x%",
4446
Value: &plugin.Memory,
4547
},
48+
&sensu.PluginConfigOption[string]{
49+
Path: "scheme",
50+
Argument: "scheme",
51+
Shorthand: "s",
52+
Default: "",
53+
Usage: "Scheme to prepend metric",
54+
Value: &plugin.Scheme,
55+
},
4656
}
4757
)
4858

@@ -58,6 +68,9 @@ func checkArgs(event *corev2.Event) (int, error) {
5868
if plugin.Memory == 100 {
5969
return sensu.CheckStateWarning, fmt.Errorf("that's just stupid")
6070
}
71+
if plugin.Scheme == "" {
72+
return sensu.CheckStateWarning, fmt.Errorf("scheme is required")
73+
}
6174

6275
return sensu.CheckStateOK, nil
6376
}
@@ -73,8 +86,8 @@ func executeCheck(event *corev2.Event) (int, error) {
7386
memory, _ := p.MemoryPercent()
7487
name, _ := p.Name()
7588
if cpu >= plugin.CPU || memory >= plugin.Memory {
76-
fmt.Printf("process.cpu_percent.%s: %f\n", strings.ReplaceAll(name, ".", "_"), Round(cpu, 0.1))
77-
fmt.Printf("process.memory_percent.%s: %f\n", strings.ReplaceAll(name, ".", "_"), Round(float64(memory), 0.1))
89+
fmt.Printf("%s.process.cpu_percent.%s: %f %d\n", plugin.Scheme, strings.ReplaceAll(name, ".", "_"), Round(cpu, 0.1), time.Now().Unix())
90+
fmt.Printf("%s.process.memory_percent.%s: %f %d\n", plugin.Scheme, strings.ReplaceAll(name, ".", "_"), Round(float64(memory), 0.1), time.Now().Unix())
7891
}
7992
}
8093
return sensu.CheckStateOK, nil

0 commit comments

Comments
 (0)