Skip to content

Commit

Permalink
1.9.0 (#60)
Browse files Browse the repository at this point in the history
* Update jars
* Update README.md
* Remove no-cache HTTP directive and update jars
* Upgrade to Kotlin 1.5.0
* Code cleanup
  • Loading branch information
pambrose authored May 1, 2021
1 parent becd296 commit 929d84a
Show file tree
Hide file tree
Showing 38 changed files with 679 additions and 640 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
target/
build/
out/

.run/
*.iml
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jdk:
before_script:
- chmod +x gradlew

script:
- ./gradlew check jacocoTestReport
#script:
# - ./gradlew check jacocoTestReport

after_success:
- bash <(curl -s https://codecov.io/bash)
- ./gradlew jacocoTestReport coveralls
#after_success:
# - bash <(curl -s https://codecov.io/bash)
# - ./gradlew jacocoTestReport coveralls

notifications:
email:
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.8.8
VERSION=1.9.0

default: compile

Expand All @@ -17,7 +17,7 @@ jars:
./gradlew agentJar proxyJar

tests:
./gradlew --rerun-tasks check jacocoTestReport
./gradlew --rerun-tasks check

config:
java -jar ./etc/jars/tscfg-0.9.98.jar --spec etc/config/config.conf --pn io.prometheus.common --cn ConfigVals --dd src/main/java/io/prometheus/common
Expand Down Expand Up @@ -63,4 +63,4 @@ refresh:
./gradlew --refresh-dependencies

upgrade-wrapper:
./gradlew wrapper --gradle-version=6.8.1 --distribution-type=bin
./gradlew wrapper --gradle-version=6.8.3 --distribution-type=bin
123 changes: 75 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@
[![Coverage Status](https://coveralls.io/repos/github/pambrose/prometheus-proxy/badge.svg?branch=master)](https://coveralls.io/github/pambrose/prometheus-proxy?branch=master)
[![Kotlin](https://img.shields.io/badge/%20language-Kotlin-red.svg)](https://kotlinlang.org/)

[Prometheus](https://prometheus.io) is an excellent systems monitoring and alerting toolkit, which uses a pull model for
collecting metrics. The pull model is problematic when a firewall separates a Prometheus server and its metrics endpoints.
[Prometheus Proxy](https://github.com/pambrose/prometheus-proxy) enables Prometheus to reach metrics endpoints
running behind a firewall and preserves the pull model.
[Prometheus](https://prometheus.io) is an excellent systems monitoring and alerting toolkit, which uses a pull model for
collecting metrics. The pull model is problematic when a firewall separates a Prometheus server and its metrics
endpoints.
[Prometheus Proxy](https://github.com/pambrose/prometheus-proxy) enables Prometheus to reach metrics endpoints running
behind a firewall and preserves the pull model.

The `prometheus-proxy` runtime comprises 2 services:

* `proxy`: runs in the same network domain as Prometheus server (outside the firewall) and proxies calls from Prometheus to the `agent` behind the firewall.
* `agent`: runs in the same network domain as all the monitored hosts/services/apps (inside the firewall). It maps the scraping queries coming from the `proxy` to the actual `/metrics` scraping endpoints of the hosts/services/apps.
* `proxy`: runs in the same network domain as Prometheus server (outside the firewall) and proxies calls from Prometheus
to the `agent` behind the firewall.
* `agent`: runs in the same network domain as all the monitored hosts/services/apps (inside the firewall). It maps the
scraping queries coming from the `proxy` to the actual `/metrics` scraping endpoints of the hosts/services/apps.

Here's a simplified network diagram of how the deployed `proxy` and `agent` work:

![network diagram](https://github.com/pambrose/prometheus-proxy/raw/master/docs/prometheus-proxy.png)

Endpoints running behind a firewall require a `prometheus-agent` (the agent) to be run inside the firewall.
An agent can run as a stand-alone server, embedded in another java server, or as a java agent.
Agents connect to a `prometheus-proxy` (the proxy) and register the paths for which they will provide data.
One proxy can work one or many agents.
Endpoints running behind a firewall require a `prometheus-agent` (the agent) to be run inside the firewall. An agent can
run as a stand-alone server, embedded in another java server, or as a java agent. Agents connect to
a `prometheus-proxy` (the proxy) and register the paths for which they will provide data. One proxy can work one or many
agents.

## Requirements

Requires Java 11 or newer.

## CLI Usage
Expand All @@ -40,14 +44,15 @@ Start a `proxy` with:
java -jar prometheus-proxy.jar
```

Start an `agent` with:
Start an `agent` with:

```bash
java -jar prometheus-agent.jar -Dagent.proxy.hostname=mymachine.local --config https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/myapps.conf
```

If the prometheus-proxy were running on a machine named *mymachine.local* and the
`agent.pathConfigs` value in the [myapps.conf](https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/myapps.conf)
`agent.pathConfigs` value in
the [myapps.conf](https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/myapps.conf)
config file had the contents:

```hocon
Expand Down Expand Up @@ -85,23 +90,24 @@ scrape_configs:
- job_name: 'app1 metrics'
metrics_path: '/app1_metrics'
static_configs:
- targets: ['mymachine.local:8080']
- targets: [ 'mymachine.local:8080' ]
- job_name: 'app2 metrics'
metrics_path: '/app2_metrics'
static_configs:
- targets: ['mymachine.local:8080']
- targets: [ 'mymachine.local:8080' ]
- job_name: 'app3 metrics'
metrics_path: '/app3_metrics'
static_configs:
- targets: ['mymachine.local:8080']
- targets: [ 'mymachine.local:8080' ]
```
## Docker Usage
The docker images are available via:
```bash
docker pull pambrose/prometheus-proxy:1.8.8
docker pull pambrose/prometheus-agent:1.8.8
docker pull pambrose/prometheus-proxy:1.9.0
docker pull pambrose/prometheus-agent:1.9.0
```

Start a proxy container with:
Expand All @@ -110,47 +116,61 @@ Start a proxy container with:
docker run --rm -p 8082:8082 -p 8092:8092 -p 50051:50051 -p 8080:8080 \
--env ADMIN_ENABLED=true \
--env METRICS_ENABLED=true \
pambrose/prometheus-proxy:1.8.8
pambrose/prometheus-proxy:1.9.0
```

Start an agent container with:

```bash
docker run --rm -p 8083:8083 -p 8093:8093 \
--env AGENT_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \
pambrose/prometheus-agent:1.8.8
pambrose/prometheus-agent:1.9.0
```

Using the config file [simple.conf](https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf),
the proxy and the agent metrics would be available from the proxy on *localhost* at:
Using the config
file [simple.conf](https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf), the proxy
and the agent metrics would be available from the proxy on *localhost* at:

* http://localhost:8082/proxy_metrics
* http://localhost:8083/agent_metrics

If you want to use a local config file with a docker container (instead of the above HTTP-served config file),
use the docker [mount](https://docs.docker.com/storage/bind-mounts/) option. Assuming the config file `prom-agent.conf`
If you want to use a local config file with a docker container (instead of the above HTTP-served config file), use the
docker [mount](https://docs.docker.com/storage/bind-mounts/) option. Assuming the config file `prom-agent.conf`
is in your current directory, run an agent container with:

```bash
docker run --rm -p 8083:8083 -p 8093:8093 \
--mount type=bind,source="$(pwd)"/prom-agent.conf,target=/app/prom-agent.conf \
--env AGENT_CONFIG=prom-agent.conf \
pambrose/prometheus-agent:1.8.8
pambrose/prometheus-agent:1.9.0
```

**Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure
to use `/app` as the base directory in the target for `--mount` options.
**Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure to use `/app` as the base directory in the
target for `--mount` options.

## Embedded Agent Usage

If you are running a JVM-based program, you can run with the agent embedded directly in your app and not use an external
agent:

```Java
EmbeddedAgentInfo agentInfo = startAsyncAgent("configFile.conf", true);
```

## Configuration

The proxy and agent use the [Typesafe Config](https://github.com/typesafehub/config) library for configuration.
Highlights include:
* support for files in three formats: Java properties, JSON, and a human-friendly JSON superset ([HOCON](https://github.com/typesafehub/config#using-hocon-the-json-superset))

* support for files in three formats: Java properties, JSON, and a human-friendly JSON
superset ([HOCON](https://github.com/typesafehub/config#using-hocon-the-json-superset))
* config files can be files or urls
* config values can come from CLI options, environment vars, Java system properties, and/or config files.
* config files can reference environment variables

All the proxy and agent properties are described [here](https://github.com/pambrose/prometheus-proxy/blob/master/etc/config/config.conf).
The only required argument is an agent config value, which should have an `agent.pathConfigs` value.

All the proxy and agent properties are
described [here](https://github.com/pambrose/prometheus-proxy/blob/master/etc/config/config.conf). The only required
argument is an agent config value, which should have an `agent.pathConfigs` value.

### Proxy CLI Options

Expand All @@ -171,7 +191,6 @@ The only required argument is an agent config value, which should have an `agent
| --usage, -u | | | Print usage message and exit |
| -D | | | Dynamic property assignment |


### Agent CLI Options

| Options | ENV VAR<br>Property |Default | Description |
Expand All @@ -197,81 +216,89 @@ The only required argument is an agent config value, which should have an `agent
| -D | | | Dynamic property assignment |

Misc notes:

* If you want to customize the logging, include the java arg `-Dlogback.configurationFile=/path/to/logback.xml`
* JSON config files must have a *.json* suffix
* Java Properties config files must have a *.properties* or *.prop* suffix
* HOCON config files must have a *.conf* suffix
* Option values are evaluated in the order: CLI, environment vars, and finally config file vals
* Property values can be set as a java -D arg to or as a proxy or agent jar -D arg.
* Property values can be set as a java -D arg to or as a proxy or agent jar -D arg.

### Admin Servlets

These admin servlets are available when the admin servlet is enabled:
* /ping

* /ping
* /threaddump
* /healthcheck
* /version

The admin servlets can be enabled with the `ADMIN_ENABLED` environment var, the `--admin` CLI option, or with the
The admin servlets can be enabled with the `ADMIN_ENABLED` environment var, the `--admin` CLI option, or with the
`proxy.admin.enabled` and `agent.admin.enabled` properties.

The debug servlet can be enabled with the `DEBUG_ENABLED` env var, `--debug` CLI option , or with the
`proxy.admin.debugEnabled` and `agent.admin.debugEnabled` properties. The debug servlet requires that the
admin servlets are enabled. The debug servlet is at: `/debug` on the admin port.
The debug servlet can be enabled with the `DEBUG_ENABLED` env var, `--debug` CLI option , or with the
`proxy.admin.debugEnabled` and `agent.admin.debugEnabled` properties. The debug servlet requires that the admin servlets
are enabled. The debug servlet is at: `/debug` on the admin port.

Descriptions of the servlets are [here](http://metrics.dropwizard.io/3.2.2/manual/servlets.html).
The path names can be changed in the configuration file. To disable an admin servlet, assign its property path to "".
Descriptions of the servlets are [here](http://metrics.dropwizard.io/3.2.2/manual/servlets.html). The path names can be
changed in the configuration file. To disable an admin servlet, assign its property path to "".

## Adding TLS to Agent-Proxy connections

Agents connect to a proxy using [gRPC](https://grpc.io). gRPC supports TLS with or without mutual authentication. The
necessary certificate and key file paths can be specified via CLI args, environment variables and configuration file settings.
necessary certificate and key file paths can be specified via CLI args, environment variables and configuration file
settings.

The gRPC docs describe [how to setup TLS](https://github.com/grpc/grpc-java/tree/master/examples/example-tls).
The [repo](https://github.com/pambrose/prometheus-proxy/tree/master/testing/certs) includes the
certificates and keys necessary to test TLS support.
The [repo](https://github.com/pambrose/prometheus-proxy/tree/master/testing/certs) includes the certificates and keys
necessary to test TLS support.

Running TLS without mutual authentication requires these settingss:

* certChainFilePath and privateKeyFilePath on the proxy
* trustCertCollectionFilePath on the agent

Running TLS with mutual authentication requires these settingss:

* certChainFilePath, privateKeyFilePath and trustCertCollectionFilePath on the proxy
* certChainFilePath, privateKeyFilePath and trustCertCollectionFilePath on the agent

### Running with TLS

Run a proxy and an agent with TLS (no mutual auth) using the included testing certs and keys with:

```bash
java -jar prometheus-proxy.jar --config examples/tls-no-mutual-auth.conf
java -jar prometheus-agent.jar --config examples/tls-no-mutual-auth.conf
```

Run a proxy and an agent docker container with TLS (no mutual auth) using the included testing certs and keys with:

```bash
docker run --rm -p 8082:8082 -p 8092:8092 -p 50440:50440 -p 8080:8080 \
--mount type=bind,source="$(pwd)"/testing/certs,target=/app/testing/certs \
--mount type=bind,source="$(pwd)"/examples/tls-no-mutual-auth.conf,target=/app/tls-no-mutual-auth.conf \
--env PROXY_CONFIG=tls-no-mutual-auth.conf \
--env ADMIN_ENABLED=true \
--env METRICS_ENABLED=true \
pambrose/prometheus-proxy:1.8.8
pambrose/prometheus-proxy:1.9.0

docker run --rm -p 8083:8083 -p 8093:8093 \
--mount type=bind,source="$(pwd)"/testing/certs,target=/app/testing/certs \
--mount type=bind,source="$(pwd)"/examples/tls-no-mutual-auth.conf,target=/app/tls-no-mutual-auth.conf \
--env AGENT_CONFIG=tls-no-mutual-auth.conf \
--env PROXY_HOSTNAME=mymachine.lan:50440 \
--name docker-agent \
pambrose/prometheus-agent:1.8.8
pambrose/prometheus-agent:1.9.0
```

**Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure
to use `/app` as the base directory in the target for `--mount` options.
**Note:** The `WORKDIR` of the proxy and agent images is `/app`, so make sure to use `/app` as the base directory in the
target for `--mount` options.

## Grafana
## Grafana

[Grafana](https://grafana.com) dashboards for the proxy and agent are [here](https://github.com/pambrose/prometheus-proxy/tree/master/grafana).
[Grafana](https://grafana.com) dashboards for the proxy and agent
are [here](https://github.com/pambrose/prometheus-proxy/tree/master/grafana).

## Related Links

Expand Down
2 changes: 1 addition & 1 deletion bin/docker-agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
docker run --rm -p 8083:8083 -p 8093:8093 \
--env AGENT_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \
--env PROXY_HOSTNAME=mymachine.lan \
pambrose/prometheus-agent:1.8.8
pambrose/prometheus-agent:1.9.0
2 changes: 1 addition & 1 deletion bin/docker-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

docker run --rm -p 8082:8082 -p 8092:8092 -p 50051:50051 -p 8080:8080 \
--env PROXY_CONFIG='https://raw.githubusercontent.com/pambrose/prometheus-proxy/master/examples/simple.conf' \
pambrose/prometheus-proxy:1.8.8
pambrose/prometheus-proxy:1.9.0
Loading

0 comments on commit 929d84a

Please sign in to comment.