-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 666e94a
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM ubi9 | ||
ADD prom-target.py / | ||
ENTRYPOINT ["/prom-target.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |