Skip to content

Commit

Permalink
Merge pull request #1 from mtanda/develop
Browse files Browse the repository at this point in the history
add Makefile, etc.
  • Loading branch information
mtanda authored Dec 12, 2017
2 parents 48b774f + d02f5d8 commit cf27002
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 7 deletions.
31 changes: 31 additions & 0 deletions .promu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
go:
cgo: false
repository:
path: github.com/mtanda/rds_enhanced_monitoring_exporter
build:
binaries:
- name: rds_enhanced_monitoring_exporter
flags: -a -tags 'netgo static_build'
ldflags: |
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
files:
- LICENSE
- NOTICE
crossbuild:
platforms:
- linux/amd64
- linux/386
- darwin/amd64
- darwin/386
- netbsd/amd64
- netbsd/386
- linux/arm
- linux/arm64
# Temporarily deactivated as this does not currently build with promu.
#- linux/mips64
#- linux/mips64le
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM quay.io/prometheus/busybox:glibc
MAINTAINER Mitsuhiro Tanda <mitsuhiro.tanda@gmail.com>

COPY rds_enhanced_monitoring_exporter /bin/rds_enhanced_monitoring_exporter

EXPOSE 9100
USER nobody
ENTRYPOINT [ "/bin/rds_enhanced_monitoring_exporter" ]
73 changes: 73 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2015 The Prometheus Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

GO ?= GO15VENDOREXPERIMENT=1 go
GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
GOARCH := $(shell $(GO) env GOARCH)
GOHOSTARCH := $(shell $(GO) env GOHOSTARCH)

PROMU ?= $(GOPATH)/bin/promu
STATICCHECK ?= $(GOPATH)/bin/staticcheck
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)

PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_NAME ?= rds-enhanced-monitoring-exporter
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
MACH ?= $(shell uname -m)
DOCKERFILE ?= Dockerfile

all: format staticcheck build test

style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'

test:
@echo ">> running tests"
@$(GO) test -short $(pkgs)

format:
@echo ">> formatting code"
@$(GO) fmt $(pkgs)

staticcheck: $(STATICCHECK)
@echo ">> running staticcheck"
@$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)

build: $(PROMU)
@echo ">> building binaries"
@$(PROMU) build --prefix $(PREFIX)

tarball: $(PROMU)
@echo ">> building release tarball"
@$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)

docker:
@echo ">> building docker image from $(DOCKERFILE)"
@docker build --file $(DOCKERFILE) -t "$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_TAG)" .

$(GOPATH)/bin/promu promu:
@GOOS= GOARCH= $(GO) get -u github.com/prometheus/promu

$(GOPATH)/bin/staticcheck:
@GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck


.PHONY: all style format build test tarball docker promu staticcheck

# Declaring the binaries at their default locations as PHONY targets is a hack
# to ensure the latest version is downloaded on every make execution.
# If this is not desired, copy/symlink these binaries to a different path and
# set the respective environment variables.
.PHONY: $(GOPATH)/bin/promu $(GOPATH)/bin/staticcheck
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# RDS Enhanced Monitorijng Exporter for Prometheus

Export RDS Enhanced Monitoring Metrics.

## Getting Started

To run it:

```bash
./rds_enhanced_monitoring_exporter [flags]
```

Help on flags:

```bash
./rds_enhanced_monitoring_exporter --help
```

## Usage

### AWS IAM

Allow following API call for this exporter.

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:DescribeLogStreams",
"logs:GetLogEvents"
],
"Resource": [
"arn:aws:logs:*:*:RDSOSMetrics",
"arn:aws:logs:*:*:log-group:RDSOSMetrics:log-stream:*"
]
},
{
"Effect": "Allow",
"Action": [
"rds:DescribeDBInstances",
"tag:getResources"
],
"Resource": [
"*"
]
}
]
}
```

### Building

```bash
make
```

## License

Apache License 2.0, see [LICENSE](https://github.com/mtanda/rds_enhanced_monitoring_exporter/blob/master/LICENSE).
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
7 changes: 0 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ func outputMetrics(w http.ResponseWriter, m interface{}, format string, prefix s
switch field.Kind() {
case reflect.Float64:
fmt.Fprintf(w, format, prefix+mv.Type().Field(i).Name, label, field.Interface())
break
case reflect.String:
// ignore
break
case reflect.Slice:
for i := 0; i < field.Len(); i++ {
copiedLabel := make(Labels)
Expand All @@ -118,21 +116,16 @@ func outputMetrics(w http.ResponseWriter, m interface{}, format string, prefix s
switch sliceType {
case "DiskIO":
copiedLabel["__Device__"] = slice.FieldByName("Device").String()
break
case "FileSys":
copiedLabel["__MountPoint__"] = slice.FieldByName("MountPoint").String()
copiedLabel["__Name__"] = slice.FieldByName("Name").String()
break
case "Network":
copiedLabel["__Device__"] = slice.FieldByName("Device").String()
break
}
outputMetrics(w, slice.Interface(), format, prefix+sliceType+"_", copiedLabel)
}
break
default:
outputMetrics(w, field.Interface(), format, prefix+field.Type().Name()+"_", label)
break
}
}
}
Expand Down

0 comments on commit cf27002

Please sign in to comment.