Skip to content

Commit

Permalink
Merge pull request #1 from ContaAzul/init
Browse files Browse the repository at this point in the history
Initial structure
  • Loading branch information
diogonicoleti committed Nov 21, 2017
2 parents aa49bcb + a322963 commit 72a0038
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 9 deletions.
13 changes: 4 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
# Output of the go coverage tool
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
# Project specific
vendor
newrelic_exporter
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
EXPOSE 9112
WORKDIR /
COPY newrelic_exporter .
ENTRYPOINT ["./newrelic_exporter"]
51 changes: 51 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added Gopkg.toml
Empty file.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# newrelic_exporter

Exports New Relic applications metrics data as prometheus metrics.

### Running

```console
./newrelic_exporter --api-key=${NEWRELIC_API_KEY}
```

Or with docker:

```console
docker run -p 9112:9112 -e "NEWRELIC_API_KEY=${NEWRELIC_API_KEY}" caninjas/newrelic_exporter
```

### Flags

Name | Description
--------|---------------------------------------------
addr | Address to bind the server (default :9112)
api-key | Your New Relic API key (required)
45 changes: 45 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"fmt"
"net/http"

"github.com/prometheus/common/log"
"gopkg.in/alecthomas/kingpin.v2"
)

var (
version = "dev"
addr = kingpin.Flag("addr", "Address to bind the server").Default(":9112").OverrideDefaultFromEnvar("SERVER_ADDR").String()
apiKey = kingpin.Flag("api-key", "New Relic API key").OverrideDefaultFromEnvar("NEWRELIC_API_KEY").String()
)

func main() {
kingpin.Version(version)
kingpin.HelpFlag.Short('h')
kingpin.Parse()

log.Info("Starting newrelic_exporter ", version)

if *apiKey == "" {
log.Fatal("You must provide your New Relic API key")
}

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w,
`
<html>
<head><title>NewRelic Exporter</title></head>
<body>
<h1>NewRelic Exporter</h1>
<p><a href="/metrics">Metrics</a></p>
</body>
</html>
`)
})

log.Infof("Server listening on %s", *addr)
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatalf("Error starting server: %s", err)
}
}

0 comments on commit 72a0038

Please sign in to comment.