@@ -42,54 +42,48 @@ module Unix_runtime = struct
42
42
]
43
43
end
44
44
45
- type config = {
46
- port : int option ;
47
- addr : string option ;
48
- }
45
+ type config = string option
49
46
50
47
module Server = Prometheus_app. Cohttp (Cohttp_lwt_unix. Server )
51
48
52
- let serve config = match config.port, config.addr with
53
- | None , _ -> []
54
- | Some port , None ->
55
- let mode = `TCP (`Port port) in
56
- let callback = Server. callback in
57
- let thread = Cohttp_lwt_unix.Server. create ~mode (Cohttp_lwt_unix.Server. make ~callback () ) in
58
- [thread]
59
- | Some port , Some addr ->
49
+ let bind addr port =
60
50
let open ! Unix in
61
51
let [@ ocaml.warning " -partial-match" ] addrinfo :: _ =
62
- getaddrinfo addr ( Int. to_string port) [AI_SOCKTYPE SOCK_STREAM ] in
52
+ getaddrinfo addr port [AI_SOCKTYPE SOCK_STREAM ] in
63
53
let socket = socket ~cloexec: true addrinfo.ai_family addrinfo.ai_socktype addrinfo.ai_protocol in
64
54
let () = setsockopt socket SO_REUSEADDR true in
65
55
let callback = Server. callback in
66
- let () = listen socket 20 in
67
56
let () = bind socket addrinfo.ai_addr in
57
+ let () = listen socket 20 in
68
58
let mode = `TCP (`Socket (Lwt_unix. of_unix_file_descr socket)) in
69
59
let thread = Cohttp_lwt_unix.Server. create ~mode (Cohttp_lwt_unix.Server. make ~callback () ) in
70
60
[thread]
71
61
72
- let listen_prometheus_addr =
73
- let open ! Cmdliner in
74
- let doc =
75
- Arg. info ~docs: " MONITORING OPTIONS" ~docv: " ADDR" ~doc:
76
- " Ip address on which to provide Prometheus metrics over HTTP."
77
- [" listen-prometheus-addr" ]
78
- in
79
- Arg. (value @@ opt (some string ) None doc)
62
+ let serve config =
63
+ let addr = " 0.0.0.0" in
64
+ let port = " 9090" in
65
+ match config with
66
+ | None -> []
67
+ | Some config_s ->
68
+ try
69
+ match (String. split_on_char ':' config_s) with
70
+ | [] -> bind addr port
71
+ | port :: [] -> bind addr port
72
+ | addr :: port :: [] -> bind addr port
73
+ with
74
+ | Match_failure _ -> Printf. printf " ERROR: Incorrect addr:port pair specified, prometheus listener not starting.\n " ; flush_all () ; []
75
+ [@@ ocaml.warning " -partial-match" ]
80
76
81
77
let listen_prometheus =
82
78
let open ! Cmdliner in
83
79
let doc =
84
- Arg. info ~docs: " MONITORING OPTIONS" ~docv: " PORT " ~doc:
85
- " Port on which to provide Prometheus metrics over HTTP."
80
+ Arg. info ~docs: " MONITORING OPTIONS" ~docv: " ADDR_PORT " ~doc:
81
+ " Address and port on which to provide Prometheus metrics over HTTP."
86
82
[" listen-prometheus" ]
87
83
in
88
- Arg. (value @@ opt (some int ) None doc)
84
+ Arg. (value @@ opt (some string ) None doc)
89
85
90
- let opts =
91
- let combine port addr = { port; addr } in
92
- Cmdliner.Term. (const combine $ listen_prometheus $ listen_prometheus_addr)
86
+ let opts = listen_prometheus
93
87
94
88
let () =
95
89
let add (info , collector ) =
0 commit comments