Skip to content

Commit

Permalink
* Improve build and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
blaubaer committed Aug 3, 2016
1 parent a47b10e commit 5e0d8c0
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 22 deletions.
37 changes: 21 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
FROM java:8-jdk-alpine
MAINTAINER coontact@echocat.org
FROM alpine:3.4
MAINTAINER contact@echocat.org

# Prepare build environment
ENV LANG C.UTF-8
RUN apk update \
&& apk add --no-cache bash go openjdk8
COPY . /tmp/buildroot/site24x7_exporter
RUN apk update && \
apk add bash go

# Build exporter
RUN cd /tmp/buildroot/site24x7_exporter && \
export GOROOT=/usr/lib/go && \
chmod +x /tmp/buildroot/site24x7_exporter/gradlew && \
./gradlew --stacktrace --info -Dplatforms=linux-amd64 build && \
cp /tmp/buildroot/site24x7_exporter/build/out/site24x7_exporter-linux-amd64 /usr/bin/site24x7_exporter && \
chmod +x /usr/bin/site24x7_exporter
RUN cd /tmp/buildroot/site24x7_exporter \
&& export GOROOT=/usr/lib/go \
&& export JAVA_HOME=/usr/lib/jvm/default-jvm \
&& chmod +x /tmp/buildroot/site24x7_exporter/gradlew \
&& ./gradlew --stacktrace --info -Dplatforms=linux-amd64 build \
&& cp /tmp/buildroot/site24x7_exporter/build/out/site24x7_exporter-linux-amd64 /usr/bin/site24x7_exporter \
&& chmod +x /usr/bin/site24x7_exporter

# Clean up build environment
RUN apk del bash go readline ncurses-libs ncurses-terminfo ncurses-terminfo-base && \
rm -rf /var/cache/* && \
rm -rf /root/.go && \
rm -rf /root/.gradle && \
rm -rf /media && \
rm -rf /tmp/*
RUN apk del \
bash readline ncurses-libs ncurses-terminfo ncurses-terminfo-base \
go \
libffi libtasn1 p11-kit p11-kit-trust ca-certificates java-cacerts libxau libxdmcp libxcb libx11 libxi libxrender libxtst libpng freetype libgcc giflib openjdk8-jre-lib java-common alsa-lib openjdk8-jre-base openjdk8-jre openjdk8 \
&& rm -rf /var/cache/* \
&& rm -rf /root/.go \
&& rm -rf /root/.gradle \
&& rm -rf /media \
&& rm -rf /tmp/*

ENTRYPOINT ["/usr/bin/site24x7_exporter"]
68 changes: 65 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ site24x7 exporter for prometheus.io, written in go.

## Get it

### Binary distribution

Download your version from the [releases page](https://github.com/echocat/site24x7_exporter/releases/latest). For older version see [archive page](https://github.com/echocat/site24x7_exporter/releases).

Example:
Expand All @@ -13,6 +15,12 @@ sudo curl -SL https://github.com/echocat/site24x7_exporter/releases/download/v0.
sudo chmod +x /usr/bin/site24x7_exporter
```

### Docker image

Image: ``docker pull echocat/site24x7_exporter``

You can go to [Docker Hub Tags page](https://hub.docker.com/r/echocat/site24x7_exporter/tags/) to see all available tags or you can simply use ``latest``.

## Use it

### Usage
Expand Down Expand Up @@ -44,23 +52,77 @@ Flags:

### Examples

#### Binary distribution

```bash
# Simply start the exporter with your token and listen on 0.0.0.0:9112
site24x7_exporter -site24x7.token=mySecrectToken
site24x7_exporter \
-site24x7.token=mySecrectToken

# Start the exporter with your token and listen on 0.0.0.0:9112
# ...it also secures the connector via SSL
site24x7_exporter -listen.address=:8443 \
site24x7_exporter \
-listen.address=:8443 \
-web.tls-cert=my.server.com.pem

# Simply start the exporter with your token and listen on 0.0.0.0:9112
# ...secures the connector via SSL
# ...and requires client certificates signed by your authority
site24x7_exporter -listen.address=:8443 \
site24x7_exporter \
-listen.address=:8443 \
-web.tls-cert=my.server.com.pem \
-web.tls-client-ca=ca.pem
```

#### Docker image

```bash
# Simply start the exporter with your token and listen on 0.0.0.0:9112
docker run -p9112:9112 echocat/site24x7_exporter \
-site24x7.token=mySecrectToken

# Start the exporter with your token and listen on 0.0.0.0:9112
# ...it also secures the connector via SSL
docker run -p9112:9112 -v/etc/certs:/etc/certs:ro echocat/site24x7_exporter \
-listen.address=:8443 \
-web.tls-cert=/etc/certs/my.server.com.pem

# Simply start the exporter with your token and listen on 0.0.0.0:9112
# ...secures the connector via SSL
# ...and requires client certificates signed by your authority
docker run -p9112:9112 -v/etc/certs:/etc/certs:ro echocat/site24x7_exporter \
-listen.address=:8443 \
-web.tls-cert=my.server.com.pem \
-web.tls-client-ca=ca.pem
```

## Metrics

### ``site24x7.monitor.status``

**Type**: Counter

#### Labels

| Name | Example | Description |
| -- | -- | -- |
| ``monitorId`` | ``123456789012345678`` | Internal ID assigned by site24x7 of monitor |
| ``monitorDisplayName`` | ``My service`` | Display name assigned by you of monitor |
| ``monitorGroupId`` | ``123456789012345678`` | Internal ID assigned by site24x7 of monitor group (optional) |
| ``monitorGroupDisplayName`` | ``My data center`` | Display name assigned by you of monitor group (optional) |

#### Possible values

| Value | Description |
| -- | -- |
| ``0`` | Down |
| ``1`` | Up |
| ``2`` | Trouble |
| ``5`` | Suspended |
| ``7`` | Maintenance |
| ``9`` | Discovery |
| ``10`` | Discovery Error |

## Build it

### Precondition
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "org.echocat.golang" version "0.1.3"
id "org.echocat.golang" version "0.1.4"
id "co.riiid.gradle" version "0.4.2"
}

Expand Down
7 changes: 5 additions & 2 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewSite24x7Exporter(accessToken string, timeout time.Duration) *Site24x7Exp
status: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "status",
Help: "Was is the status of the target monitor?",
Help: "What is the status of the target monitor?",
}),
client: &http.Client{
Transport: &http.Transport{
Expand Down Expand Up @@ -76,7 +76,10 @@ func (instance *Site24x7Exporter) createRequestFor(url *url.URL) *http.Request {
func (instance *Site24x7Exporter) executeAndEvaluate(request *http.Request, target interface{}) error {
response, err := instance.client.Do(request)
if err != nil {
return fmt.Errorf("Could not execute request %v. Got: %d - %v", request.URL, response.StatusCode, response.Status)
return fmt.Errorf("Could not execute request %v. Got: %v", request.URL, err)
}
if response.StatusCode < 200 || response.StatusCode >= 400 {
return fmt.Errorf("Could not execute request %v. Got: %v - %v", request.URL, response.StatusCode, response.Status)
}
decoder := json.NewDecoder(response.Body)
err = decoder.Decode(target)
Expand Down

0 comments on commit 5e0d8c0

Please sign in to comment.