Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix static binaries #15

Merged
merged 3 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .drone.star
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description = 'Prometheus HetznerCloud SD'
description = 'Prometheus Hetzner Cloud SD'

def main(ctx):
return [
Expand Down Expand Up @@ -194,6 +194,21 @@ def docker(ctx, arch):
'arch': agent,
},
'steps': [
{
'name': 'version',
'image': 'webhippie/golang:1.14',
'pull': 'always',
'environment': environment,
'commands': [
'go env',
],
'volumes': [
{
'name': 'gopath',
'path': '/srv/app',
},
],
},
{
'name': 'generate',
'image': 'webhippie/golang:1.14',
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ else
endif

ifeq ($(UNAME), Darwin)
GOBUILD ?= go build -i
GOBUILD ?= CGO_ENABLED=0 go build -i
else
GOBUILD ?= go build
GOBUILD ?= CGO_ENABLED=0 go build
endif

PACKAGES ?= $(shell go list ./...)
SOURCES ?= $(shell find . -name "*.go" -type f -not -path "./node_modules/*")
GENERATE ?= $(PACKAGES)

TAGS ?=
TAGS ?= netgo

ifndef OUTPUT
ifneq ($(DRONE_TAG),)
Expand All @@ -48,7 +48,7 @@ ifndef SHA
SHA := $(shell git rev-parse --short HEAD)
endif

LDFLAGS += -s -w -X "$(IMPORT)/pkg/version.String=$(VERSION)" -X "$(IMPORT)/pkg/version.Revision=$(SHA)" -X "$(IMPORT)/pkg/version.Date=$(DATE)"
LDFLAGS += -s -w -extldflags "-static" -X "$(IMPORT)/pkg/version.String=$(VERSION)" -X "$(IMPORT)/pkg/version.Revision=$(SHA)" -X "$(IMPORT)/pkg/version.Date=$(DATE)"
GCFLAGS += all=-N -l

.PHONY: all
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prometheus HetznerCloud SD
# Prometheus Hetzner Cloud SD

[![Build Status](http://cloud.drone.io/api/badges/promhippie/prometheus-hcloud-sd/status.svg)](http://cloud.drone.io/promhippie/prometheus-hcloud-sd)
[![Join the Matrix chat at https://matrix.to/#/#webhippie:matrix.org](https://img.shields.io/badge/matrix-%23webhippie-7bc9a4.svg)](https://matrix.to/#/#webhippie:matrix.org)
Expand All @@ -7,7 +7,7 @@
[![Go Report](http://goreportcard.com/badge/github.com/promhippie/prometheus-hcloud-sd)](http://goreportcard.com/report/github.com/promhippie/prometheus-hcloud-sd)
[![](https://images.microbadger.com/badges/image/promhippie/prometheus-hcloud-sd.svg)](http://microbadger.com/images/promhippie/prometheus-hcloud-sd "Get your own image badge on microbadger.com")

This project provides a server to automatically discover nodes within your HetznerCloud account in a Prometheus SD compatible format.
This project provides a server to automatically discover nodes within your Hetzner Cloud account in a Prometheus SD compatible format.

## Install

Expand Down
8 changes: 8 additions & 0 deletions changelog/0.4.1_2020-06-22/static-linked.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Binaries are not static linked

We fixed building properly static linked binaries, since the last release and a
major refactoring of the binaries and the CI pipeline we introduced binaries
which had been linked to muslc by mistake. With this change applied all binaries
will be properly static linked again.

https://github.com/promhippie/prometheus-hcloud-sd/issues/14
2 changes: 1 addition & 1 deletion docker/Dockerfile.linux.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk add --no-cache ca-certificates mailcap
FROM scratch

LABEL maintainer="Thomas Boerger <[email protected]>" \
org.label-schema.name="Prometheus HetznerCloud SD" \
org.label-schema.name="Prometheus Hetzner Cloud SD" \
org.label-schema.vendor="Thomas Boerger" \
org.label-schema.schema-version="1.0"

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.linux.arm32v6
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk add --no-cache ca-certificates mailcap
FROM scratch

LABEL maintainer="Thomas Boerger <[email protected]>" \
org.label-schema.name="Prometheus HetznerCloud SD" \
org.label-schema.name="Prometheus Hetzner Cloud SD" \
org.label-schema.vendor="Thomas Boerger" \
org.label-schema.schema-version="1.0"

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.linux.arm64v8
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk add --no-cache ca-certificates mailcap
FROM scratch

LABEL maintainer="Thomas Boerger <[email protected]>" \
org.label-schema.name="Prometheus HetznerCloud SD" \
org.label-schema.name="Prometheus Hetzner Cloud SD" \
org.label-schema.vendor="Thomas Boerger" \
org.label-schema.schema-version="1.0"

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.linux.i386
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk add --no-cache ca-certificates mailcap
FROM scratch

LABEL maintainer="Thomas Boerger <[email protected]>" \
org.label-schema.name="Prometheus HetznerCloud SD" \
org.label-schema.name="Prometheus Hetzner Cloud SD" \
org.label-schema.vendor="Thomas Boerger" \
org.label-schema.schema-version="1.0"

Expand Down
4 changes: 2 additions & 2 deletions docs/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
baseURL = "https://promhippie.github.io/prometheus-hcloud-sd/"
languageCode = "en-us"
title = "Prometheus HetznerCloud SD"
title = "Prometheus Hetzner Cloud SD"
pygmentsUseClasses = true

[blackfriday]
Expand All @@ -12,5 +12,5 @@ pygmentsUseClasses = true

[params]
author = "Thomas Boerger"
description = "Prometheus service discovery for HetznerCloud"
description = "Prometheus service discovery for Hetzner Cloud"
keywords = "prometheus, sd, service, discovery, hetzner, cloud"
100 changes: 95 additions & 5 deletions docs/content/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,113 @@ We won't cover further details how to properly setup [Prometheus](https://promet

First of all we need to prepare a configuration for [Prometheus](https://prometheus.io) that includes the service discovery which simply maps to a node exporter.

{{< gist tboerger b9c39b6571f48ce2b132de1531061531 "prometheus.yml" >}}
{{< highlight yaml >}}
global:
scrape_interval: 1m
scrape_timeout: 10s
evaluation_interval: 1m

scrape_configs:
- job_name: node
file_sd_configs:
- files: [ "/etc/sd/hcloud.json" ]
relabel_configs:
- source_labels: [__meta_hcloud_public_ipv4]
replacement: "${1}:9100"
target_label: __address__
- source_labels: [__meta_hcloud_datacenter]
target_label: datacenter
- source_labels: [__meta_hcloud_name]
target_label: instance
- job_name: hcloud-sd
static_configs:
- targets:
- hcloud-sd:9000
{{< / highlight >}}

After preparing the configuration we need to create the `docker-compose.yml` within the same folder, this `docker-compose.yml` starts a simple [Prometheus](https://prometheus.io) instance together with the service discovery. Don't forget to update the envrionment variables with the required credentials. If you are using a different volume for the service discovery you have to make sure that the container user is allowed to write to this volume.

{{< gist tboerger b9c39b6571f48ce2b132de1531061531 "docker-compose.yml" >}}
{{< highlight diff >}}
version: '2'

volumes:
prometheus:

services:
prometheus:
image: prom/prometheus:v2.6.0
restart: always
ports:
- 9090:9090
volumes:
- prometheus:/prometheus
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- ./service-discovery:/etc/sd

hcloud-exporter:
image: promhippie/prometheus-hcloud-sd:latest
restart: always
environment:
- PROMETHEUS_HCLOUD_LOG_PRETTY=true
- PROMETHEUS_HCLOUD_OUTPUT_FILE=/etc/sd/hcloud.json
- PROMETHEUS_HCLOUD_TOKEN=uDgX6TkZVGx7c94jPAff5cfJdym9MLekiveDgN7Oq5dyOXxl4Uu9qkpcC1muILGW
volumes:
- ./service-discovery:/etc/sd
{{< / highlight >}}

Since our `latest` Docker tag always refers to the `master` branch of the Git repository you should always use some fixed version. You can see all available tags at our [DockerHub repository](https://hub.docker.com/r/promhippie/prometheus-hcloud-sd/tags/), there you will see that we also provide a manifest, you can easily start the exporter on various architectures without any change to the image name. You should apply a change like this to the `docker-compose.yml`:

{{< gist tboerger b9c39b6571f48ce2b132de1531061531 "tag.diff" >}}
{{< highlight diff >}}
hcloud-exporter:
- image: promhippie/prometheus-hcloud-sd:latest
+ image: promhippie/prometheus-hcloud-sd:0.2.0
restart: always
environment:
- PROMETHEUS_HCLOUD_LOG_PRETTY=true
- PROMETHEUS_HCLOUD_OUTPUT_FILE=/etc/sd/hcloud.json
- PROMETHEUS_HCLOUD_TOKEN=uDgX6TkZVGx7c94jPAff5cfJdym9MLekiveDgN7Oq5dyOXxl4Uu9qkpcC1muILGW
volumes:
- ./service-discovery:/etc/sd
{{< / highlight >}}

Depending on how you have launched and configured [Prometheus](https://prometheus.io) it's possible that it's running as user `nobody`, in that case you should run the service discovery as this user as well, otherwise [Prometheus](https://prometheus.io) won't be able to read the generated JSON file:

{{< gist tboerger b9c39b6571f48ce2b132de1531061531 "userid.diff" >}}
{{< highlight diff >}}
hcloud-exporter:
image: promhippie/prometheus-hcloud-sd:latest
restart: always
+ user: '65534'
environment:
- PROMETHEUS_HCLOUD_LOG_PRETTY=true
- PROMETHEUS_HCLOUD_OUTPUT_FILE=/etc/sd/hcloud.json
- PROMETHEUS_HCLOUD_TOKEN=uDgX6TkZVGx7c94jPAff5cfJdym9MLekiveDgN7Oq5dyOXxl4Uu9qkpcC1muILGW
volumes:
- ./service-discovery:/etc/sd
{{< / highlight >}}

Finally the service discovery should be configured fine, let's start this stack with [docker-compose](https://docs.docker.com/compose/), you just need to execute `docker-compose up` within the directory where you have stored `prometheus.yml` and `docker-compose.yml`.

{{< gist tboerger b9c39b6571f48ce2b132de1531061531 "output.log" >}}
{{< highlight txt >}}
# docker-compose up
Creating network "hcloud-sd_default" with the default driver
Creating volume "hcloud-sd_prometheus" with default driver
Creating hcloud-sd_hcloud-sd_1 ... done
Creating hcloud-sd_prometheus_1 ... done
Attaching to hcloud-sd_hcloud-sd_1, hcloud-sd_prometheus_1
prometheus_1 | level=info ts=2018-10-07T15:49:32.5574151Z caller=main.go:238 msg="Starting Prometheus" version="(version=2.4.3, branch=HEAD, revision=167a4b4e73a8eca8df648d2d2043e21bdb9a7449)"
prometheus_1 | level=info ts=2018-10-07T15:49:32.5574847Z caller=main.go:239 build_context="(go=go1.11.1, user=root@1e42b46043e9, date=20181004-08:42:02)"
prometheus_1 | level=info ts=2018-10-07T15:49:32.5575116Z caller=main.go:240 host_details="(Linux 4.9.93-linuxkit-aufs #1 SMP Wed Jun 6 16:55:56 UTC 2018 x86_64 14ae580d073a (none))"
prometheus_1 | level=info ts=2018-10-07T15:49:32.5575347Z caller=main.go:241 fd_limits="(soft=1048576, hard=1048576)"
prometheus_1 | level=info ts=2018-10-07T15:49:32.5575521Z caller=main.go:242 vm_limits="(soft=unlimited, hard=unlimited)"
prometheus_1 | level=info ts=2018-10-07T15:49:32.5588845Z caller=main.go:554 msg="Starting TSDB ..."
prometheus_1 | level=info ts=2018-10-07T15:49:32.5590007Z caller=web.go:397 component=web msg="Start listening for connections" address=0.0.0.0:9090
prometheus_1 | level=info ts=2018-10-07T15:49:32.5639949Z caller=main.go:564 msg="TSDB started"
prometheus_1 | level=info ts=2018-10-07T15:49:32.5640454Z caller=main.go:624 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
prometheus_1 | level=info ts=2018-10-07T15:49:32.5674651Z caller=main.go:650 msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml
prometheus_1 | level=info ts=2018-10-07T15:49:32.5675144Z caller=main.go:523 msg="Server is ready to receive web requests."
hcloud-sd_1 | level=info ts=2018-10-07T15:49:32.5843003Z msg="Launching Prometheus HetznerCloud SD" version=0.0.0-master revision=00c6143 date=20180924 go=go1.11
hcloud-sd_1 | level=info ts=2018-10-07T15:49:32.5845589Z msg="Starting metrics server" addr=0.0.0.0:9000
{{< / highlight >}}

That's all, the service discovery should be up and running. You can access [Prometheus](https://prometheus.io) at [http://localhost:9090](http://localhost:9090).

Expand Down