@@ -18,12 +18,14 @@ var logger = logging.GetLogger("metrics.plugin.jvm")
1818
1919// JVMPlugin plugin for JVM
2020type JVMPlugin struct {
21- Remote string
22- Lvmid string
23- JstatPath string
24- JinfoPath string
25- JavaName string
26- Tempfile string
21+ Remote string
22+ Lvmid string
23+ JstatPath string
24+ JinfoPath string
25+ JavaName string
26+ Tempfile string
27+ MetricKey string
28+ MetricLabel string
2729}
2830
2931// # jps
@@ -242,11 +244,20 @@ func (m JVMPlugin) FetchMetrics() (map[string]interface{}, error) {
242244
243245// GraphDefinition interface for mackerelplugin
244246func (m JVMPlugin ) GraphDefinition () map [string ]mp.Graphs {
245- rawJavaName := m .JavaName
246- lowerJavaName := strings .ToLower (m .JavaName )
247+ metricLabel := m .MetricLabel
248+ if metricLabel == "" {
249+ metricLabel = m .JavaName
250+ }
251+
252+ javaName := m .MetricKey
253+ if javaName == "" {
254+ javaName = m .JavaName
255+ }
256+ lowerJavaName := strings .ToLower (javaName )
257+
247258 return map [string ]mp.Graphs {
248259 fmt .Sprintf ("jvm.%s.gc_events" , lowerJavaName ): {
249- Label : fmt .Sprintf ("JVM %s GC events" , rawJavaName ),
260+ Label : fmt .Sprintf ("JVM %s GC events" , metricLabel ),
250261 Unit : "integer" ,
251262 Metrics : []mp.Metrics {
252263 {Name : "YGC" , Label : "Young GC event" , Diff : true },
@@ -255,7 +266,7 @@ func (m JVMPlugin) GraphDefinition() map[string]mp.Graphs {
255266 },
256267 },
257268 fmt .Sprintf ("jvm.%s.gc_time" , lowerJavaName ): {
258- Label : fmt .Sprintf ("JVM %s GC time (sec)" , rawJavaName ),
269+ Label : fmt .Sprintf ("JVM %s GC time (sec)" , metricLabel ),
259270 Unit : "float" ,
260271 Metrics : []mp.Metrics {
261272 {Name : "YGCT" , Label : "Young GC time" , Diff : true },
@@ -264,7 +275,7 @@ func (m JVMPlugin) GraphDefinition() map[string]mp.Graphs {
264275 },
265276 },
266277 fmt .Sprintf ("jvm.%s.gc_time_percentage" , lowerJavaName ): {
267- Label : fmt .Sprintf ("JVM %s GC time percentage" , rawJavaName ),
278+ Label : fmt .Sprintf ("JVM %s GC time percentage" , metricLabel ),
268279 Unit : "percentage" ,
269280 Metrics : []mp.Metrics {
270281 // gc_time_percentage is the percentage of gc time to 60 sec.
@@ -274,7 +285,7 @@ func (m JVMPlugin) GraphDefinition() map[string]mp.Graphs {
274285 },
275286 },
276287 fmt .Sprintf ("jvm.%s.new_space" , lowerJavaName ): {
277- Label : fmt .Sprintf ("JVM %s New Space memory" , rawJavaName ),
288+ Label : fmt .Sprintf ("JVM %s New Space memory" , metricLabel ),
278289 Unit : "float" ,
279290 Metrics : []mp.Metrics {
280291 {Name : "NGCMX" , Label : "New max" , Diff : false , Scale : 1024 },
@@ -285,7 +296,7 @@ func (m JVMPlugin) GraphDefinition() map[string]mp.Graphs {
285296 },
286297 },
287298 fmt .Sprintf ("jvm.%s.old_space" , lowerJavaName ): {
288- Label : fmt .Sprintf ("JVM %s Old Space memory" , rawJavaName ),
299+ Label : fmt .Sprintf ("JVM %s Old Space memory" , metricLabel ),
289300 Unit : "float" ,
290301 Metrics : []mp.Metrics {
291302 {Name : "OGCMX" , Label : "Old max" , Diff : false , Scale : 1024 },
@@ -294,7 +305,7 @@ func (m JVMPlugin) GraphDefinition() map[string]mp.Graphs {
294305 },
295306 },
296307 fmt .Sprintf ("jvm.%s.perm_space" , lowerJavaName ): {
297- Label : fmt .Sprintf ("JVM %s Permanent Space" , rawJavaName ),
308+ Label : fmt .Sprintf ("JVM %s Permanent Space" , metricLabel ),
298309 Unit : "float" ,
299310 Metrics : []mp.Metrics {
300311 {Name : "PGCMX" , Label : "Perm max" , Diff : false , Scale : 1024 },
@@ -303,7 +314,7 @@ func (m JVMPlugin) GraphDefinition() map[string]mp.Graphs {
303314 },
304315 },
305316 fmt .Sprintf ("jvm.%s.metaspace" , lowerJavaName ): {
306- Label : fmt .Sprintf ("JVM %s Metaspace" , rawJavaName ),
317+ Label : fmt .Sprintf ("JVM %s Metaspace" , metricLabel ),
307318 Unit : "float" ,
308319 Metrics : []mp.Metrics {
309320 {Name : "MCMX" , Label : "Metaspace capacity max" , Diff : false , Scale : 1024 },
@@ -315,7 +326,7 @@ func (m JVMPlugin) GraphDefinition() map[string]mp.Graphs {
315326 },
316327 },
317328 fmt .Sprintf ("jvm.%s.memorySpace" , lowerJavaName ): {
318- Label : fmt .Sprintf ("JVM %s MemorySpace" , rawJavaName ),
329+ Label : fmt .Sprintf ("JVM %s MemorySpace" , metricLabel ),
319330 Unit : "float" ,
320331 Metrics : []mp.Metrics {
321332 {Name : "oldSpaceRate" , Label : "GC Old Memory Space" , Diff : false },
@@ -373,6 +384,8 @@ func Do() {
373384 optJavaName := flag .String ("javaname" , "" , "Java app name" )
374385 optPidFile := flag .String ("pidfile" , "" , "pidfile path" )
375386 optTempfile := flag .String ("tempfile" , "" , "Temp file name" )
387+ optMetricKey := flag .String ("metric-key" , "" , "Specifying the Name field in the Graph Definition" )
388+ optMetricLabel := flag .String ("metric-label" , "" , "Specifying the Label field in the Graph Definition" )
376389 flag .Parse ()
377390
378391 var jvm JVMPlugin
@@ -409,6 +422,8 @@ func Do() {
409422 }
410423
411424 jvm .JavaName = * optJavaName
425+ jvm .MetricKey = * optMetricKey
426+ jvm .MetricLabel = * optMetricLabel
412427
413428 helper := mp .NewMackerelPlugin (jvm )
414429 helper .Tempfile = * optTempfile
0 commit comments