@@ -25,6 +25,38 @@ open Rrdd_shared
2525module D = Debug. Make (struct let name= " rrdd_server" end )
2626open 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+
2860let 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" ;
0 commit comments