diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eaf0da7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM ubi9 +ADD prom-target.py / +ENTRYPOINT ["/prom-target.py"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..926664d --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/prom-target.py b/prom-target.py new file mode 100755 index 0000000..58e1565 --- /dev/null +++ b/prom-target.py @@ -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()