Skip to content

Commit

Permalink
First cut
Browse files Browse the repository at this point in the history
  • Loading branch information
csibbitt committed Dec 7, 2022
0 parents commit 666e94a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM ubi9
ADD prom-target.py /
ENTRYPOINT ["/prom-target.py"]
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# prom-target

Simple script to generate fake prometheus metrics

## Usage

```
$ ./prom-target.py &
[1] 3475808
Listening on port 8000 to serve 10000 total metrics
$ curl http://localhost:8000
127.0.0.1 - - [07/Dec/2022 17:47:11] "GET / HTTP/1.1" 200 -
#Mock Prometheus metrics
mock_metric_0{labelA="0",labelB="0"} 1
mock_metric_0{labelA="1",labelB="0"} 2
[...]
$ kill %%
[1]+ Terminated ./prom-target.py -m 1000 -l 10
```

## Container

```
$ podman build -t prom-target .
[...]
$ podman run --name target1 -d -p 8000:8000 prom-target -m 100 -l 5
6bfe29b1fb6e720d0a72cf64a931101d65286825f8e2eceef2419b2f1646135c
$ curl localhost:8000
#Mock Prometheus metrics
mock_metric_0{labelA="0",labelB="0"} 1
mock_metric_0{labelA="1",labelB="0"} 2
[...]
$ podman rm -f target1
6bfe29b1fb6e720d0a72cf64a931101d65286825f8e2eceef2419b2f1646135c
```
30 changes: 30 additions & 0 deletions prom-target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
import argparse
from http.server import HTTPServer, BaseHTTPRequestHandler


class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):

def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b"#Mock Prometheus metrics\n")
a_range = int(args.metrics/2)
i = 0
for m in range(0, args.metrics):
for la in range(0, args.labels):
i = i+1
self.wfile.write(f"mock_metric_{m}{{labelA=\"{la}\",labelB=\"0\"}} {i}\n".encode())

parser = argparse.ArgumentParser(
prog='prom-target',
description='Serves a prometheus endpoint with a specified number of metrics and label cardinality')
parser.add_argument('-p', '--port', type=int, default=8000)
parser.add_argument('-m', '--metrics', type=int, default=1000)
parser.add_argument('-l', '--labels', type=int, default=10)
args = parser.parse_args()

print(f'Listening on port {args.port} to serve {args.metrics * args.labels} total metrics')

httpd = HTTPServer(('0.0.0.0', args.port), SimpleHTTPRequestHandler)
httpd.serve_forever()

0 comments on commit 666e94a

Please sign in to comment.