-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (49 loc) · 2.41 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import logging
import asyncio
from aioprometheus.service import Service
from ts_metric_exporter.collector.worker_resource import get_ts_worker_resource
async def main(exporter_address: str,
exporter_port: int,
ts_address: str,
ts_management_port: int,
refresh_duration_seconds: int,
ts_k8s_namespace: str) -> None:
"""
Launches Prometheus exporter service.
This runs:
- exportation of TorchServe model worker resources as Prometheus metrics.
@param exporter_address: An address to accept on exposed exporter service.
@param exporter_port: An port to accept on exposed exporter service.
@param ts_address:
@param ts_management_port:
@param refresh_duration_seconds:
@param ts_k8s_namespace:
"""
service = Service()
await service.start(addr=exporter_address, port=exporter_port)
logging.info(f'Serving TorchServe resource exporter on "{service.metrics_url}"')
await get_ts_worker_resource(ts_server_address=ts_address,
ts_management_port=ts_management_port,
ts_k8s_namespace=ts_k8s_namespace,
retrieve_duration_seconds=refresh_duration_seconds)
await service.stop()
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--exporter-address', type=str, default='0.0.0.0', required=False)
parser.add_argument('--exporter-port', type=int, default=8082, required=False)
parser.add_argument('--ts-address', type=str, default='127.0.0.1', required=True)
parser.add_argument('--ts-management-port', type=int, default=8081, required=False)
parser.add_argument('--refresh-duration-seconds', type=int, default=10, required=False)
parser.add_argument('--ts-k8s-namespace', type=str, default='torchserve', required=False)
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)
try:
asyncio.run(main(exporter_address=args.exporter_address,
exporter_port=args.exporter_port,
ts_address=args.ts_address,
ts_management_port=args.ts_management_port,
refresh_duration_seconds=args.refresh_duration_seconds,
ts_k8s_namespace=args.ts_k8s_namespace))
except KeyboardInterrupt:
pass