From c25e0f944fe63857b7f661d90f11565ad7059613 Mon Sep 17 00:00:00 2001 From: Marco Tulio R Braga Date: Sun, 21 Jul 2019 18:41:06 -0300 Subject: [PATCH 1/5] refact/builder: move each exporter to cmd dir --- .gitignore | 1 + Makefile | 29 +++++++++++++------ .../namenode-exporter/namenode_exporter.go | 0 .../resourcemanager_exporter.go | 0 go.sum | 22 ++++++++++++++ 5 files changed, 43 insertions(+), 9 deletions(-) rename namenode_exporter.go => cmd/namenode-exporter/namenode_exporter.go (100%) rename resourcemanager_exporter.go => cmd/resourcemanager-exporter/resourcemanager_exporter.go (100%) create mode 100644 go.sum diff --git a/.gitignore b/.gitignore index daf913b..0cdefe0 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ _testmain.go *.exe *.test *.prof +bin/ diff --git a/Makefile b/Makefile index 70a5c47..f196d05 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,26 @@ -all: namenode_exporter resourcemanager_exporter +# ############### +# Go Project +# ############### +CPWD ?= $(PWD) +BIN_PATH ?= ./cmd +BIN_NAMES ?= namenode-exporter resourcemanager-exporter +GO_FLAGS ?= GOOS=linux GOARCH=amd64 +export GO111MODULE=on + +all: build .PHONY: all deps: - go get github.com/prometheus/client_golang/prometheus - go get github.com/prometheus/log - -namenode_exporter: deps namenode_exporter.go - go build namenode_exporter.go + @mkdir ./bin || true -resourcemanager_exporter: deps resourcemanager_exporter.go - go build resourcemanager_exporter.go +build: deps + @for CMD in $(BIN_NAMES); do \ + cd $(CPWD)/$(BIN_PATH)/$${CMD}; \ + echo -e "** Building cmd: $${CMD} **"; \ + GOOS=linux GOARCH=amd64 \ + $(GO_FLAGS) go build -o $(CPWD)/bin/$${CMD}; \ + done + @cd $(CPWD) clean: - rm -rf namenode_exporter resourcemanager_exporter + rm -rfv bin/* diff --git a/namenode_exporter.go b/cmd/namenode-exporter/namenode_exporter.go similarity index 100% rename from namenode_exporter.go rename to cmd/namenode-exporter/namenode_exporter.go diff --git a/resourcemanager_exporter.go b/cmd/resourcemanager-exporter/resourcemanager_exporter.go similarity index 100% rename from resourcemanager_exporter.go rename to cmd/resourcemanager-exporter/resourcemanager_exporter.go diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0b83bb8 --- /dev/null +++ b/go.sum @@ -0,0 +1,22 @@ +github.com/Sirupsen/logrus v1.0.6 h1:HCAGQRk48dRVPA5Y+Yh0qdCSTzPOyU1tBJ7Q9YzotII= +github.com/Sirupsen/logrus v1.0.6/go.mod h1:rmk17hk6i8ZSAJkSDa7nOxamrG+SP4P0mm+DAvExv4U= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8= +github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e h1:n/3MEhJQjQxrOUCzh1Y3Re6aJUUWRp2M9+Oc3eVn/54= +github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/log v0.0.0-20151026012452-9a3136781e1f h1:G4tJ8/52J/rRmxob3LtolevHcHhCwtxo/2VD0unNM/E= +github.com/prometheus/log v0.0.0-20151026012452-9a3136781e1f/go.mod h1:1CWrwKZ/oqmOpg817WPlG88DKb9xKdpnq009SEKTgqQ= +github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273 h1:agujYaXJSxSo18YNX3jzl+4G6Bstwt+kqv47GS12uL0= +github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b h1:2b9XGzhjiYsYPnKXoEfL7klWZQIt8IfyRCz62gCqqlQ= +golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= From cd72c06606480eecbfa1ec3eec1459be046a4600 Mon Sep 17 00:00:00 2001 From: Marco Tulio R Braga Date: Sun, 21 Jul 2019 19:07:40 -0300 Subject: [PATCH 2/5] refact/builder: create release manager --- Makefile | 24 ++++++++++++++++++++++-- VERSION | 1 + hack/github-tag-attachment.sh | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 VERSION create mode 100755 hack/github-tag-attachment.sh diff --git a/Makefile b/Makefile index f196d05..cbe4830 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,20 @@ BIN_NAMES ?= namenode-exporter resourcemanager-exporter GO_FLAGS ?= GOOS=linux GOARCH=amd64 export GO111MODULE=on +# ####### +# General +clean: + rm -rfv bin/* + all: build .PHONY: all deps: @mkdir ./bin || true +# ####### +# Builder + build: deps @for CMD in $(BIN_NAMES); do \ cd $(CPWD)/$(BIN_PATH)/$${CMD}; \ @@ -22,5 +30,17 @@ build: deps done @cd $(CPWD) -clean: - rm -rfv bin/* +# ####### +# Release +tag: + $(call deps_tag,$@) + git tag -a $(shell cat VERSION) -m "$(message)" + git push origin $(shell cat VERSION) + +tag-attach: + @for CMD in $(BIN_NAMES); do \ + echo -e "** Publish bin to github: $${CMD} **"; \ + strip $(CPWD)/bin/$${CMD}; \ + ./hack/github-tag-attachment.sh $(shell cat VERSION) $(CPWD)/bin/$${CMD}; \ + done + @cd $(CPWD) diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..b82608c --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v0.1.0 diff --git a/hack/github-tag-attachment.sh b/hack/github-tag-attachment.sh new file mode 100755 index 0000000..3a0e3dc --- /dev/null +++ b/hack/github-tag-attachment.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Upload file as release attachment using ghr. +# go get -u github.com/tcnksm/ghr +# https://github.com/tcnksm/ghr + +RELEASE=$1 +UPLOAD_FILE=$2 +GH_FILE=$(basename $UPLOAD_FILE) + +export GIT_REPO_URL=$(git config -l |awk -F'remote.origin.url=' '{print$2}' |grep -v ^$) +export GIT_USER=$(echo $GIT_REPO_URL |awk -F':' '{print$2}' |awk -F'/' '{print$1}') +export GIT_REPO=$(echo $GIT_REPO_URL |awk -F':' '{print$2}' |awk -F'/' '{print$2}' |sed 's/.git//') + +ghr -u ${GIT_USER} -r ${GIT_REPO} \ + --replace "${RELEASE}" ${UPLOAD_FILE} From 7340fcdb3c9c23b99ed40d2b853721577e9aa7c4 Mon Sep 17 00:00:00 2001 From: yuriymalygin Date: Mon, 28 Jan 2019 16:44:22 +0300 Subject: [PATCH 3/5] Add transport layer for connection managing --- cmd/namenode-exporter/namenode_exporter.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/namenode-exporter/namenode_exporter.go b/cmd/namenode-exporter/namenode_exporter.go index 97114f2..46bc365 100644 --- a/cmd/namenode-exporter/namenode_exporter.go +++ b/cmd/namenode-exporter/namenode_exporter.go @@ -12,6 +12,7 @@ import ( const ( namespace = "namenode" + maxIdleConnections = 10 ) var ( @@ -169,7 +170,9 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { // Collect implements the prometheus.Collector interface. func (e *Exporter) Collect(ch chan<- prometheus.Metric) { - resp, err := http.Get(e.url) + tr := &http.Transport {MaxIdleConns: maxIdleConnections} + client := &http.Client{Transport: tr} + resp, err := client.Get(e.url) if err != nil { log.Error(err) } From 200cac85689ad4bbc53dfaf799c38ff57c4d834a Mon Sep 17 00:00:00 2001 From: yuriymalygin Date: Mon, 28 Jan 2019 23:22:17 +0300 Subject: [PATCH 4/5] Add more NameNode metrics. --- cmd/namenode-exporter/namenode_exporter.go | 164 ++++++++++++++++++--- 1 file changed, 143 insertions(+), 21 deletions(-) diff --git a/cmd/namenode-exporter/namenode_exporter.go b/cmd/namenode-exporter/namenode_exporter.go index 46bc365..5f108eb 100644 --- a/cmd/namenode-exporter/namenode_exporter.go +++ b/cmd/namenode-exporter/namenode_exporter.go @@ -22,26 +22,39 @@ var ( ) type Exporter struct { - url string - MissingBlocks prometheus.Gauge - CapacityTotal prometheus.Gauge - CapacityUsed prometheus.Gauge - CapacityRemaining prometheus.Gauge - CapacityUsedNonDFS prometheus.Gauge - BlocksTotal prometheus.Gauge - FilesTotal prometheus.Gauge - CorruptBlocks prometheus.Gauge - ExcessBlocks prometheus.Gauge - StaleDataNodes prometheus.Gauge - pnGcCount prometheus.Gauge - pnGcTime prometheus.Gauge - cmsGcCount prometheus.Gauge - cmsGcTime prometheus.Gauge - heapMemoryUsageCommitted prometheus.Gauge - heapMemoryUsageInit prometheus.Gauge - heapMemoryUsageMax prometheus.Gauge - heapMemoryUsageUsed prometheus.Gauge - isActive prometheus.Gauge + url string + MissingBlocks prometheus.Gauge + CapacityTotal prometheus.Gauge + CapacityUsed prometheus.Gauge + CapacityRemaining prometheus.Gauge + CapacityUsedNonDFS prometheus.Gauge + BlocksTotal prometheus.Gauge + FilesTotal prometheus.Gauge + CorruptBlocks prometheus.Gauge + ExcessBlocks prometheus.Gauge + StaleDataNodes prometheus.Gauge + pnGcCount prometheus.Gauge + pnGcTime prometheus.Gauge + cmsGcCount prometheus.Gauge + cmsGcTime prometheus.Gauge + heapMemoryUsageCommitted prometheus.Gauge + heapMemoryUsageInit prometheus.Gauge + heapMemoryUsageMax prometheus.Gauge + heapMemoryUsageUsed prometheus.Gauge + isActive prometheus.Gauge + BlockCapacity prometheus.Gauge + TotalLoad prometheus.Gauge + UnderReplicatedBlocks prometheus.Gauge + VolumeFailuresTotal prometheus.Gauge + NumLiveDataNodes prometheus.Gauge + NumDeadDataNodes prometheus.Gauge + GcCountConcurrentMarkSweep prometheus.Gauge + GcTimeMillisConcurrentMarkSweep prometheus.Gauge + MemNonHeapUsedM prometheus.Gauge + MemNonHeapCommittedM prometheus.Gauge + MemHeapUsedM prometheus.Gauge + MemHeapCommittedM prometheus.Gauge + MemHeapMaxM prometheus.Gauge } func NewExporter(url string) *Exporter { @@ -142,6 +155,71 @@ func NewExporter(url string) *Exporter { Name: "isActive", Help: "isActive", }), + BlockCapacity: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "BlockCapacity", + Help: "BlockCapacity", + }), + TotalLoad: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "TotalLoad", + Help: "TotalLoad", + }), + UnderReplicatedBlocks: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "UnderReplicatedBlocks", + Help: "UnderReplicatedBlocks", + }), + VolumeFailuresTotal: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "VolumeFailuresTotal", + Help: "VolumeFailuresTotal", + }), + NumLiveDataNodes: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "NumLiveDataNodes", + Help: "NumLiveDataNodes", + }), + NumDeadDataNodes: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "NumDeadDataNodes", + Help: "NumDeadDataNodes", + }), + GcCountConcurrentMarkSweep: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "GcCountConcurrentMarkSweep", + Help: "GcCountConcurrentMarkSweep", + }), + GcTimeMillisConcurrentMarkSweep: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "GcTimeMillisConcurrentMarkSweep", + Help: "GcTimeMillisConcurrentMarkSweep", + }), + MemNonHeapUsedM: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "MemNonHeapUsedM", + Help: "MemNonHeapUsedM", + }), + MemNonHeapCommittedM: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "MemNonHeapCommittedM", + Help: "MemNonHeapCommittedM", + }), + MemHeapUsedM: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "MemHeapUsedM", + Help: "MemHeapUsedM", + }), + MemHeapCommittedM: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "MemHeapCommittedM", + Help: "MemHeapCommittedM", + }), + MemHeapMaxM: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "MemHeapMaxM", + Help: "MemHeapMaxM", + }), } } @@ -166,6 +244,19 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { e.heapMemoryUsageMax.Describe(ch) e.heapMemoryUsageUsed.Describe(ch) e.isActive.Describe(ch) + e.BlockCapacity.Describe(ch) + e.TotalLoad.Describe(ch) + e.UnderReplicatedBlocks.Describe(ch) + e.VolumeFailuresTotal.Describe(ch) + e.NumLiveDataNodes.Describe(ch) + e.NumDeadDataNodes.Describe(ch) + e.GcCountConcurrentMarkSweep.Describe(ch) + e.GcTimeMillisConcurrentMarkSweep.Describe(ch) + e.MemNonHeapUsedM.Describe(ch) + e.MemNonHeapCommittedM.Describe(ch) + e.MemHeapUsedM.Describe(ch) + e.MemHeapCommittedM.Describe(ch) + e.MemHeapMaxM.Describe(ch) } // Collect implements the prometheus.Collector interface. @@ -248,6 +339,23 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { e.CorruptBlocks.Set(nameDataMap["CorruptBlocks"].(float64)) e.ExcessBlocks.Set(nameDataMap["ExcessBlocks"].(float64)) e.StaleDataNodes.Set(nameDataMap["StaleDataNodes"].(float64)) + e.BlockCapacity.Set(nameDataMap["BlockCapacity"].(float64)) + e.TotalLoad.Set(nameDataMap["TotalLoad"].(float64)) + e.UnderReplicatedBlocks.Set(nameDataMap["UnderReplicatedBlocks"].(float64)) + } + if nameDataMap["name"] == "Hadoop:service=NameNode,name=FSNamesystemState" { + e.VolumeFailuresTotal.Set(nameDataMap["VolumeFailuresTotal"].(float64)) + e.NumLiveDataNodes.Set(nameDataMap["NumLiveDataNodes"].(float64)) + e.NumDeadDataNodes.Set(nameDataMap["NumDeadDataNodes"].(float64)) + } + if nameDataMap["name"] == "Hadoop:service=NameNode,name=JvmMetrics" { + e.GcCountConcurrentMarkSweep.Set(nameDataMap["GcCountConcurrentMarkSweep"].(float64)) + e.GcTimeMillisConcurrentMarkSweep.Set(nameDataMap["GcTimeMillisConcurrentMarkSweep"].(float64)) + e.MemNonHeapUsedM.Set(nameDataMap["MemNonHeapUsedM"].(float64)) + e.MemNonHeapCommittedM.Set(nameDataMap["MemNonHeapCommittedM"].(float64)) + e.MemHeapUsedM.Set(nameDataMap["MemHeapUsedM"].(float64)) + e.MemHeapCommittedM.Set(nameDataMap["MemHeapCommittedM"].(float64)) + e.MemHeapMaxM.Set(nameDataMap["MemHeapMaxM"].(float64)) } if nameDataMap["name"] == "java.lang:type=GarbageCollector,name=ParNew" { e.pnGcCount.Set(nameDataMap["CollectionCount"].(float64)) @@ -303,6 +411,19 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { e.heapMemoryUsageMax.Collect(ch) e.heapMemoryUsageUsed.Collect(ch) e.isActive.Collect(ch) + e.BlockCapacity.Collect(ch) + e.TotalLoad.Collect(ch) + e.UnderReplicatedBlocks.Collect(ch) + e.VolumeFailuresTotal.Collect(ch) + e.NumLiveDataNodes.Collect(ch) + e.NumDeadDataNodes.Collect(ch) + e.GcCountConcurrentMarkSweep.Collect(ch) + e.GcTimeMillisConcurrentMarkSweep.Collect(ch) + e.MemNonHeapUsedM.Collect(ch) + e.MemNonHeapCommittedM.Collect(ch) + e.MemHeapUsedM.Collect(ch) + e.MemHeapCommittedM.Collect(ch) + e.MemHeapMaxM.Collect(ch) } func main() { @@ -318,6 +439,7 @@ func main() { NameNode Exporter

NameNode Exporter

+

Parsing JMX counters over HTTP/HTTPS.

Metrics

`)) @@ -326,4 +448,4 @@ func main() { if err != nil { log.Fatal(err) } -} +} \ No newline at end of file From e4ea16359eb14768b72a4ee0fe2c0016d98c86fb Mon Sep 17 00:00:00 2001 From: Marco Tulio R Braga Date: Mon, 22 Jul 2019 00:29:26 -0300 Subject: [PATCH 5/5] fix/namenode: keeping backward compability with old JVM Check if newer JVM metrics exists - GcCountConcurrentMarkSweep - GcTimeMillisConcurrentMarkSweep --- VERSION | 2 +- cmd/namenode-exporter/namenode_exporter.go | 82 ++++++++++++---------- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/VERSION b/VERSION index b82608c..1474d00 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.1.0 +v0.2.0 diff --git a/cmd/namenode-exporter/namenode_exporter.go b/cmd/namenode-exporter/namenode_exporter.go index 5f108eb..cc5d6b6 100644 --- a/cmd/namenode-exporter/namenode_exporter.go +++ b/cmd/namenode-exporter/namenode_exporter.go @@ -11,7 +11,7 @@ import ( ) const ( - namespace = "namenode" + namespace = "namenode" maxIdleConnections = 10 ) @@ -22,39 +22,39 @@ var ( ) type Exporter struct { - url string - MissingBlocks prometheus.Gauge - CapacityTotal prometheus.Gauge - CapacityUsed prometheus.Gauge - CapacityRemaining prometheus.Gauge - CapacityUsedNonDFS prometheus.Gauge - BlocksTotal prometheus.Gauge - FilesTotal prometheus.Gauge - CorruptBlocks prometheus.Gauge - ExcessBlocks prometheus.Gauge - StaleDataNodes prometheus.Gauge - pnGcCount prometheus.Gauge - pnGcTime prometheus.Gauge - cmsGcCount prometheus.Gauge - cmsGcTime prometheus.Gauge - heapMemoryUsageCommitted prometheus.Gauge - heapMemoryUsageInit prometheus.Gauge - heapMemoryUsageMax prometheus.Gauge - heapMemoryUsageUsed prometheus.Gauge - isActive prometheus.Gauge - BlockCapacity prometheus.Gauge - TotalLoad prometheus.Gauge - UnderReplicatedBlocks prometheus.Gauge - VolumeFailuresTotal prometheus.Gauge - NumLiveDataNodes prometheus.Gauge - NumDeadDataNodes prometheus.Gauge - GcCountConcurrentMarkSweep prometheus.Gauge - GcTimeMillisConcurrentMarkSweep prometheus.Gauge - MemNonHeapUsedM prometheus.Gauge - MemNonHeapCommittedM prometheus.Gauge - MemHeapUsedM prometheus.Gauge - MemHeapCommittedM prometheus.Gauge - MemHeapMaxM prometheus.Gauge + url string + MissingBlocks prometheus.Gauge + CapacityTotal prometheus.Gauge + CapacityUsed prometheus.Gauge + CapacityRemaining prometheus.Gauge + CapacityUsedNonDFS prometheus.Gauge + BlocksTotal prometheus.Gauge + FilesTotal prometheus.Gauge + CorruptBlocks prometheus.Gauge + ExcessBlocks prometheus.Gauge + StaleDataNodes prometheus.Gauge + pnGcCount prometheus.Gauge + pnGcTime prometheus.Gauge + cmsGcCount prometheus.Gauge + cmsGcTime prometheus.Gauge + heapMemoryUsageCommitted prometheus.Gauge + heapMemoryUsageInit prometheus.Gauge + heapMemoryUsageMax prometheus.Gauge + heapMemoryUsageUsed prometheus.Gauge + isActive prometheus.Gauge + BlockCapacity prometheus.Gauge + TotalLoad prometheus.Gauge + UnderReplicatedBlocks prometheus.Gauge + VolumeFailuresTotal prometheus.Gauge + NumLiveDataNodes prometheus.Gauge + NumDeadDataNodes prometheus.Gauge + GcCountConcurrentMarkSweep prometheus.Gauge + GcTimeMillisConcurrentMarkSweep prometheus.Gauge + MemNonHeapUsedM prometheus.Gauge + MemNonHeapCommittedM prometheus.Gauge + MemHeapUsedM prometheus.Gauge + MemHeapCommittedM prometheus.Gauge + MemHeapMaxM prometheus.Gauge } func NewExporter(url string) *Exporter { @@ -261,8 +261,8 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { // Collect implements the prometheus.Collector interface. func (e *Exporter) Collect(ch chan<- prometheus.Metric) { - tr := &http.Transport {MaxIdleConns: maxIdleConnections} - client := &http.Client{Transport: tr} + tr := &http.Transport{MaxIdleConns: maxIdleConnections} + client := &http.Client{Transport: tr} resp, err := client.Get(e.url) if err != nil { log.Error(err) @@ -349,8 +349,12 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { e.NumDeadDataNodes.Set(nameDataMap["NumDeadDataNodes"].(float64)) } if nameDataMap["name"] == "Hadoop:service=NameNode,name=JvmMetrics" { - e.GcCountConcurrentMarkSweep.Set(nameDataMap["GcCountConcurrentMarkSweep"].(float64)) - e.GcTimeMillisConcurrentMarkSweep.Set(nameDataMap["GcTimeMillisConcurrentMarkSweep"].(float64)) + if _, ok := nameDataMap["GcCountConcurrentMarkSweep"]; ok { + e.GcCountConcurrentMarkSweep.Set(nameDataMap["GcCountConcurrentMarkSweep"].(float64)) + } + if _, ok := nameDataMap["GcTimeMillisConcurrentMarkSweep"]; ok { + e.GcTimeMillisConcurrentMarkSweep.Set(nameDataMap["GcTimeMillisConcurrentMarkSweep"].(float64)) + } e.MemNonHeapUsedM.Set(nameDataMap["MemNonHeapUsedM"].(float64)) e.MemNonHeapCommittedM.Set(nameDataMap["MemNonHeapCommittedM"].(float64)) e.MemHeapUsedM.Set(nameDataMap["MemHeapUsedM"].(float64)) @@ -448,4 +452,4 @@ func main() { if err != nil { log.Fatal(err) } -} \ No newline at end of file +}