albatross_log: a read-only mode to read a log file
This commit is contained in:
parent
47fef438e0
commit
537c113a8a
|
@ -161,14 +161,20 @@ let handle mvar ring s addr =
|
|||
|
||||
let m = Vmm_core.conn_metrics "unix"
|
||||
|
||||
let jump _ file influx =
|
||||
let jump _ file read_only influx =
|
||||
Sys.(set_signal sigpipe Signal_ignore) ;
|
||||
Lwt_main.run
|
||||
(Albatross_cli.init_influx "albatross_log" influx;
|
||||
(read_from_file file >>= fun entries ->
|
||||
Logs.app (fun m -> m "read %d entries from disk" (List.length entries)) ;
|
||||
if read_only then begin
|
||||
List.iteri (fun i e ->
|
||||
Logs.app (fun m -> m "entry %d: %a" i Vmm_core.Log.pp e))
|
||||
entries;
|
||||
Lwt.return_unit
|
||||
end else begin
|
||||
Albatross_cli.init_influx "albatross_log" influx;
|
||||
Vmm_lwt.server_socket `Log >>= fun s ->
|
||||
let ring = Vmm_ring.create `Startup () in
|
||||
read_from_file file >>= fun entries ->
|
||||
Logs.app (fun m -> m "read %d entries from disk" (List.length entries)) ;
|
||||
List.iter (Vmm_ring.write ring) entries ;
|
||||
let mvar = Lwt_mvar.create_empty () in
|
||||
Sys.(set_signal sighup (Signal_handle (fun _ ->
|
||||
|
@ -183,7 +189,8 @@ let jump _ file influx =
|
|||
Lwt.async (fun () -> handle mvar ring cs addr >|= fun () -> m `Close) ;
|
||||
loop ()
|
||||
in
|
||||
loop ())
|
||||
loop ()
|
||||
end)
|
||||
|
||||
open Cmdliner
|
||||
open Albatross_cli
|
||||
|
@ -192,8 +199,12 @@ let file =
|
|||
let doc = "File to write the log to" in
|
||||
Arg.(value & opt string "/var/log/albatross" & info [ "logfile" ] ~doc)
|
||||
|
||||
let read_only =
|
||||
let doc = "Only read log file and present entries" in
|
||||
Arg.(value & flag & info [ "read-only" ] ~doc)
|
||||
|
||||
let cmd =
|
||||
Term.(term_result (const jump $ setup_log $ file $ influx)),
|
||||
Term.(const jump $ setup_log $ file $ read_only $ influx),
|
||||
Term.info "albatross_log" ~version:"%%VERSION_NUM%%"
|
||||
|
||||
let () = match Term.eval cmd with `Ok () -> exit 0 | _ -> exit 1
|
||||
|
|
Loading…
Reference in a new issue