|
1 | 1 | # inventor |
| 2 | + |
2 | 3 | Prometheus HTTP SD implementation |
3 | 4 |
|
4 | | -## helm chart |
| 5 | +## Description |
| 6 | + |
| 7 | +The Inventor is a Prometheus HTTP SD Server allows users to dynamcially add or remove prometheus targets and labels and expose it to a [Prometheus HTTP SD](https://prometheus.io/docs/prometheus/latest/http_sd/) job. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +Running the server: |
| 12 | +``` |
| 13 | +cd src |
| 14 | +go run main.go |
| 15 | +``` |
| 16 | + |
| 17 | +Installing with Helm |
5 | 18 | ```bash |
6 | 19 | helm repo add inventor https://code-tool.github.io/inventor/ |
7 | 20 | ``` |
| 21 | + |
| 22 | +Registering new target: |
| 23 | +```bash |
| 24 | +curl -X PUT -H "x-api-token: secret" http://127.0.0.1:9101/target \ |
| 25 | +-d '{"static_config": {"targets": ["10.0.10.2:9100",], "labels": {"__meta_datacenter": "dc-01", "__meta_prometheus_job": "node"}, "target_group": "mygroup"}}' |
| 26 | +``` |
| 27 | + |
| 28 | +More examples: `./test/end-to-end` |
| 29 | + |
| 30 | +Prometheus SD config example |
| 31 | +```yaml |
| 32 | +scrape_configs: |
| 33 | + - job_name: http_sd |
| 34 | + http_sd_configs: |
| 35 | + - url: http://127.0.0.1:9101/discover |
| 36 | + # if SD_TOKEN env variable is set |
| 37 | + headers: |
| 38 | + - "x-sd-token: REDACTED" |
| 39 | + |
| 40 | +``` |
| 41 | + |
| 42 | +Prometheus SD config with groups example |
| 43 | +```yaml |
| 44 | +scrape_configs: |
| 45 | + - job_name: http_sd_mygroup |
| 46 | + http_sd_configs: |
| 47 | + - url: http://127.0.0.1:9101/group?name=mygroup |
| 48 | + # if SD_TOKEN env variable is set |
| 49 | + headers: |
| 50 | + - "x-sd-token: REDACTED" |
| 51 | + |
| 52 | +``` |
| 53 | + |
| 54 | + |
| 55 | +## Configuration Environmet Valiables |
| 56 | + |
| 57 | + * `REDIS_ADDR`: redis server addres to store metrics and targets |
| 58 | + * `REDIS_PORT`: redis server port |
| 59 | + * `REDIS_DBNO`: redis server keyspace |
| 60 | + * `TTL_SECONDS`: ttl for storing target, default is 6h (21600 seconds) |
| 61 | + * `API_TOKEN`: API token for manipulating targets |
| 62 | + * `SD_TOKEN`: Options token for Prometheus HTTP SD, is empty by default and not validating (header `x-sd-token`) |
| 63 | + |
| 64 | +## API Methods |
| 65 | + |
| 66 | +* **GET /discover** |
| 67 | + * Returning the list of targets in Prometheus HTTP SD format |
| 68 | +* **GET /group** |
| 69 | + * Returning targets by group name `/group?name=mygroup` |
| 70 | +* **PUT /target** |
| 71 | + * Adds the new target |
| 72 | +* **GET /target** |
| 73 | + * Returning target by ID |
| 74 | +* **DELETE /target** |
| 75 | + * Removing target by ID |
| 76 | +* **GET /metrics** |
| 77 | + * Metrics in prometheus format |
| 78 | +* **GET /healthcheck** |
| 79 | + * Health Check for kubernetes deployments |
| 80 | + |
| 81 | + |
| 82 | +## Build Docker image |
| 83 | +```bash |
| 84 | +docker build -t ghcr.io/code-tool/inventor/inventor:$(cat VERSION.txt) --build-arg BUILD_VERSION=$(cat VERSION.txt) -f docker/Dockerfile . |
| 85 | +``` |
| 86 | +pulling image: |
| 87 | +```bash |
| 88 | +ghcr.io/code-tool/inventor/inventor:0.0.3 |
| 89 | +``` |
| 90 | + |
| 91 | +## License |
| 92 | + |
| 93 | +Covered under the [MIT license](LICENSE.md). |
0 commit comments