@@ -11,7 +11,7 @@ import (
1111)
1212
1313const (
14- namespace = "namenode"
14+ namespace = "namenode"
1515 maxIdleConnections = 10
1616)
1717
@@ -22,39 +22,39 @@ var (
2222)
2323
2424type Exporter struct {
25- url string
26- MissingBlocks prometheus.Gauge
27- CapacityTotal prometheus.Gauge
28- CapacityUsed prometheus.Gauge
29- CapacityRemaining prometheus.Gauge
30- CapacityUsedNonDFS prometheus.Gauge
31- BlocksTotal prometheus.Gauge
32- FilesTotal prometheus.Gauge
33- CorruptBlocks prometheus.Gauge
34- ExcessBlocks prometheus.Gauge
35- StaleDataNodes prometheus.Gauge
36- pnGcCount prometheus.Gauge
37- pnGcTime prometheus.Gauge
38- cmsGcCount prometheus.Gauge
39- cmsGcTime prometheus.Gauge
40- heapMemoryUsageCommitted prometheus.Gauge
41- heapMemoryUsageInit prometheus.Gauge
42- heapMemoryUsageMax prometheus.Gauge
43- heapMemoryUsageUsed prometheus.Gauge
44- isActive prometheus.Gauge
45- BlockCapacity prometheus.Gauge
46- TotalLoad prometheus.Gauge
47- UnderReplicatedBlocks prometheus.Gauge
48- VolumeFailuresTotal prometheus.Gauge
49- NumLiveDataNodes prometheus.Gauge
50- NumDeadDataNodes prometheus.Gauge
51- GcCountConcurrentMarkSweep prometheus.Gauge
52- GcTimeMillisConcurrentMarkSweep prometheus.Gauge
53- MemNonHeapUsedM prometheus.Gauge
54- MemNonHeapCommittedM prometheus.Gauge
55- MemHeapUsedM prometheus.Gauge
56- MemHeapCommittedM prometheus.Gauge
57- MemHeapMaxM prometheus.Gauge
25+ url string
26+ MissingBlocks prometheus.Gauge
27+ CapacityTotal prometheus.Gauge
28+ CapacityUsed prometheus.Gauge
29+ CapacityRemaining prometheus.Gauge
30+ CapacityUsedNonDFS prometheus.Gauge
31+ BlocksTotal prometheus.Gauge
32+ FilesTotal prometheus.Gauge
33+ CorruptBlocks prometheus.Gauge
34+ ExcessBlocks prometheus.Gauge
35+ StaleDataNodes prometheus.Gauge
36+ pnGcCount prometheus.Gauge
37+ pnGcTime prometheus.Gauge
38+ cmsGcCount prometheus.Gauge
39+ cmsGcTime prometheus.Gauge
40+ heapMemoryUsageCommitted prometheus.Gauge
41+ heapMemoryUsageInit prometheus.Gauge
42+ heapMemoryUsageMax prometheus.Gauge
43+ heapMemoryUsageUsed prometheus.Gauge
44+ isActive prometheus.Gauge
45+ BlockCapacity prometheus.Gauge
46+ TotalLoad prometheus.Gauge
47+ UnderReplicatedBlocks prometheus.Gauge
48+ VolumeFailuresTotal prometheus.Gauge
49+ NumLiveDataNodes prometheus.Gauge
50+ NumDeadDataNodes prometheus.Gauge
51+ GcCountConcurrentMarkSweep prometheus.Gauge
52+ GcTimeMillisConcurrentMarkSweep prometheus.Gauge
53+ MemNonHeapUsedM prometheus.Gauge
54+ MemNonHeapCommittedM prometheus.Gauge
55+ MemHeapUsedM prometheus.Gauge
56+ MemHeapCommittedM prometheus.Gauge
57+ MemHeapMaxM prometheus.Gauge
5858}
5959
6060func NewExporter (url string ) * Exporter {
@@ -261,8 +261,8 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
261261
262262// Collect implements the prometheus.Collector interface.
263263func (e * Exporter ) Collect (ch chan <- prometheus.Metric ) {
264- tr := & http.Transport {MaxIdleConns : maxIdleConnections }
265- client := & http.Client {Transport : tr }
264+ tr := & http.Transport {MaxIdleConns : maxIdleConnections }
265+ client := & http.Client {Transport : tr }
266266 resp , err := client .Get (e .url )
267267 if err != nil {
268268 log .Error (err )
@@ -349,8 +349,12 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
349349 e .NumDeadDataNodes .Set (nameDataMap ["NumDeadDataNodes" ].(float64 ))
350350 }
351351 if nameDataMap ["name" ] == "Hadoop:service=NameNode,name=JvmMetrics" {
352- e .GcCountConcurrentMarkSweep .Set (nameDataMap ["GcCountConcurrentMarkSweep" ].(float64 ))
353- e .GcTimeMillisConcurrentMarkSweep .Set (nameDataMap ["GcTimeMillisConcurrentMarkSweep" ].(float64 ))
352+ if _ , ok := nameDataMap ["GcCountConcurrentMarkSweep" ]; ok {
353+ e .GcCountConcurrentMarkSweep .Set (nameDataMap ["GcCountConcurrentMarkSweep" ].(float64 ))
354+ }
355+ if _ , ok := nameDataMap ["GcTimeMillisConcurrentMarkSweep" ]; ok {
356+ e .GcTimeMillisConcurrentMarkSweep .Set (nameDataMap ["GcTimeMillisConcurrentMarkSweep" ].(float64 ))
357+ }
354358 e .MemNonHeapUsedM .Set (nameDataMap ["MemNonHeapUsedM" ].(float64 ))
355359 e .MemNonHeapCommittedM .Set (nameDataMap ["MemNonHeapCommittedM" ].(float64 ))
356360 e .MemHeapUsedM .Set (nameDataMap ["MemHeapUsedM" ].(float64 ))
@@ -448,4 +452,4 @@ func main() {
448452 if err != nil {
449453 log .Fatal (err )
450454 }
451- }
455+ }
0 commit comments