1.0.1 • Published 1 year ago

@matchory/hetzner-cloud-prometheus-sd v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Prometheus: Hetzner Service Discovery Current Release License Build Weekly Downloads Docker Build Status

A server to provide automatic node discovery for Hetzner Cloud to Prometheus via HTTP service discovery.

In contrary to the integrated Hetzner SD configuration, this lets you use internal IPs and filter the node list using Hetzner labels or node filters, for example.

Installation

The easiest option will be using our Docker image matchory/hetzner-cloud-prometheus-sd:

docker run -p 127.0.0.1:7764:7764 matchory/hetzner-cloud-prometheus-sd --hetzner-api-token $HETZNER_API_TOKEN

You can also install the npm package globally:

npx @matchory/hetzner-cloud-prometheus-sd --hetzner-api-token $HETZNER_API_TOKEN

Usage

Upon starting the server, it will continuously synchronize its list of Hetzner cloud nodes with the Hetzner API, and return those to requests on the /sd endpoint. Additionally, the server also provides its own metrics endpoint.

Configuration

The server may be configured using command-line options, environment variables, or its configuration file. The following table shows all available settings:

CLI optionEnvironment variableDefault valueDescription
-t, --api-tokenHETZNER_SD_API_TOKEN-API token obtained from Hetzner Cloud (required).
-h, --hostnameHETZNER_SD_HOSTNAMElocalhostHostname to listen on.
-a, --auth-bearerHETZNER_SD_AUTH_BEARER-Bearer token to verify on incoming requests. Mutually exclusive with --auth-basic.
-A, --auth-basicHETZNER_SD_AUTH_BASIC-Basic auth credentials to verify on incoming requests, provided as user:pass. Mutually exclusive with --auth-bearer.
-p, --portHETZNER_SD_PORT7764Port to listen on.
-H, --httpsHETZNER_SD_HTTPSfalseUse HTTPS for the listening socket. Required for mTLS.
--m-tls-caHETZNER_SD_MTLS_CA-Path to the mTLS certificate authority file. Ignored unless https is enabled.
-r, --refresh-intervalHETZNER_SD_REFRESH_INTERVAL30000 (30s)How often to synchronize with the Hetzner API in ms.
--metrics-endpointHETZNER_SD_METRICS_ENDPOINT/metricsEndpoint to provide server metrics on.
--node-portHETZNER_SD_NODE_PORT9090Port on the nodes Prometheus should connect to.
--node-networkHETZNER_SD_NODE_NETWORK-Name, ID, or CIDR range of the network to prefer when resolving nodes. If omitted, the public IP will be preferred.
--node-label-prefixHETZNER_SD_NODE_LABEL_PREFIXhetznerPrefix for labels attached to discovered nodes-
--log-levelHETZNER_SD_LOG_LEVELdebugLog level for the server (must be one of debug, info, warn or error).
--debugHETZNER_SD_DEBUGfalseEnable debug mode. This will also include additional debugging information in HTTP responses.

Note:
You can provide token parameters in secret files using the environment variables with a _FILE suffix, e.g. HETZNER_SD_API_TOKEN_FILE. This variable is expected to contain an absolute path to a file on the filesystem which contains the secret. Trailing whitespace will be removed; the secret will be read once, and cached for the runtime of the server. This works for the API token and authentication credentials, so currently we support the following secret files:

  • HETZNER_SD_API_TOKEN_FILE
  • HETZNER_SD_AUTH_BEARER_FILE
  • HETZNER_SD_AUTH_BASIC_FILE

Development

For local development, you'll want to use yarn dev to compile the TypeScript sources and start the server.

Contributing

We welcome all contributions. If you need help or would like to see a feature implemented, please get in touch.

Releasing

To publish a new release, use the np utility on the command line.