Skip to content

Commit dd5bdae

Browse files
committed
Merge pull request #57 from sharady/CP-13995-ring3
CP-13995: Adding functions into xcp-rrdd for archiving of sr-level rrds
2 parents 272edd0 + e86832d commit dd5bdae

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

rrdd/rrdd_server.ml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,38 @@ open Rrdd_shared
2525
module D = Debug.Make(struct let name="rrdd_server" end)
2626
open D
2727

28+
let sr_rrds_path _ ~(sr_uuid : string) : string =
29+
Filename.concat sr_rrds_location (sr_uuid ^ ".gz")
30+
31+
let archive_sr_rrd _ ~(sr_uuid : string) : unit =
32+
if Mutex.try_lock mutex then begin
33+
let srrds =
34+
try
35+
Hashtbl.fold (fun k v acc -> (k,v.rrd)::acc) sr_rrds []
36+
with exn ->
37+
Mutex.unlock mutex;
38+
raise exn
39+
in
40+
Mutex.unlock mutex;
41+
try
42+
let rrd = List.assoc sr_uuid srrds in
43+
archive_rrd ~uuid:sr_uuid ~rrd ()
44+
with Not_found -> ()
45+
end
46+
47+
let get_sr_rrd ~sr_uuid =
48+
let path = Filename.concat sr_rrds_location sr_uuid in
49+
rrd_of_gzip path
50+
51+
let push_sr_rrd _ ~(sr_uuid : string) : unit =
52+
try
53+
let rrd = get_sr_rrd ~sr_uuid in
54+
debug "Pushing RRD for SR uuid=%s locally" sr_uuid;
55+
Mutex.execute mutex (fun _ ->
56+
Hashtbl.replace sr_rrds sr_uuid {rrd; dss=[]; domid=0}
57+
)
58+
with _ -> ()
59+
2860
let has_vm_rrd _ ~(vm_uuid : string) =
2961
Mutex.execute mutex (fun _ -> Hashtbl.mem vm_rrds vm_uuid)
3062

@@ -49,6 +81,20 @@ let backup_rrds _ ?(save_stats_locally = true) () : unit =
4981
let rrd = Mutex.execute mutex (fun () -> Rrd.copy_rrd rrd) in
5082
archive_rrd ~save_stats_locally ~uuid ~rrd ()
5183
) vrrds;
84+
let srrds =
85+
try
86+
Hashtbl.fold (fun k v acc -> (k,v.rrd)::acc) sr_rrds []
87+
with exn ->
88+
Mutex.unlock mutex;
89+
raise exn
90+
in
91+
Mutex.unlock mutex;
92+
List.iter
93+
(fun (uuid, rrd) ->
94+
debug "Backup: saving RRD for SR uuid=%s to local disk" uuid;
95+
let rrd = Mutex.execute mutex (fun () -> Rrd.copy_rrd rrd) in
96+
archive_rrd ~uuid ~rrd ()
97+
) srrds;
5298
match !host_rrd with
5399
| Some rrdi ->
54100
debug "Backup: saving RRD for host to local disk";

rrdd/rrdd_shared.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ let cache_sr_lock = Mutex.create ()
3434
let default_ssl_port = 443
3535
let https_port = ref default_ssl_port
3636

37+
let sr_rrds_location = Constants.rrd_location
38+
3739
(** Pool secret. *)
3840
let get_pool_secret () =
3941
try

0 commit comments

Comments
 (0)