@@ -34,7 +34,7 @@ let archive_sr_rrd _ ~(sr_uuid : string) : string =
3434 raise (Archive_failed (msg))
3535 ) in
3636 try
37- archive_rrd ~uuid: sr_uuid ~rrd: sr_rrd.rrd () ;
37+ archive_rrd_internal ~uuid: sr_uuid ~rrd: sr_rrd.rrd () ;
3838 let archive_path =
3939 Filename. concat Constants. rrd_location (sr_uuid ^ " .gz" ) in
4040 if not (Unixext. file_exists archive_path) then begin
@@ -62,8 +62,18 @@ let push_sr_rrd _ ~(sr_uuid : string) ~(path : string) : unit =
6262let has_vm_rrd _ ~(vm_uuid : string ) =
6363 Mutex. execute mutex (fun _ -> Hashtbl. mem vm_rrds vm_uuid)
6464
65- let backup_rrds _ ?(save_stats_locally = true ) () : unit =
66- debug " backup safe_stats_locally=%b" save_stats_locally;
65+ let archive_rrd _ ~vm_uuid ~remote_address : unit =
66+ Mutex. execute mutex (fun () ->
67+ try
68+ let rrd = (Hashtbl. find vm_rrds vm_uuid).rrd in
69+ archive_rrd_internal ~remote_address ~uuid: vm_uuid ~rrd () ;
70+ Hashtbl. remove vm_rrds vm_uuid
71+ with Not_found -> () )
72+
73+ let backup_rrds _ ?(remote_address = None ) () : unit =
74+ debug " backing up rrds %s" (match remote_address with
75+ | None -> " locally"
76+ | Some x -> Printf. sprintf " remotely at %s" x);
6777 let total_cycles = 5 in
6878 let cycles_tried = ref 0 in
6979 while ! cycles_tried < total_cycles do
@@ -81,7 +91,7 @@ let backup_rrds _ ?(save_stats_locally = true) () : unit =
8191 (fun (uuid , rrd ) ->
8292 debug " Backup: saving RRD for VM uuid=%s to local disk" uuid;
8393 let rrd = Mutex. execute mutex (fun () -> Rrd. copy_rrd rrd) in
84- archive_rrd ~save_stats_locally ~uuid ~rrd ()
94+ archive_rrd_internal ~remote_address ~uuid ~rrd ()
8595 ) vrrds;
8696 let srrds =
8797 try
@@ -95,13 +105,13 @@ let backup_rrds _ ?(save_stats_locally = true) () : unit =
95105 (fun (uuid , rrd ) ->
96106 debug " Backup: saving RRD for SR uuid=%s to local disk" uuid;
97107 let rrd = Mutex. execute mutex (fun () -> Rrd. copy_rrd rrd) in
98- archive_rrd ~uuid ~rrd ()
108+ archive_rrd_internal ~uuid ~rrd ()
99109 ) srrds;
100110 match ! host_rrd with
101111 | Some rrdi ->
102112 debug " Backup: saving RRD for host to local disk" ;
103113 let rrd = Mutex. execute mutex (fun () -> Rrd. copy_rrd rrdi.rrd) in
104- archive_rrd ~save_stats_locally ~uuid: (Inventory. lookup Inventory. _installation_uuid) ~rrd ()
114+ archive_rrd_internal ~remote_address ~uuid: (Inventory. lookup Inventory. _installation_uuid) ~rrd ()
105115 | None -> ()
106116 end else begin
107117 cycles_tried := 1 + ! cycles_tried;
@@ -120,17 +130,16 @@ let load_rrd_from_local_filesystem uuid =
120130module Deprecated = struct
121131 (* DEPRECATED *)
122132 (* Fetch an RRD from the master *)
123- let pull_rrd_from_master ~uuid ~is_host =
133+ let pull_rrd_from_master ~uuid ~master_address =
124134 let pool_secret = get_pool_secret () in
125- let uri = if is_host then Constants. get_host_rrd_uri else Constants. get_vm_rrd_uri in
135+ let uri = Constants. get_host_rrd_uri in
126136 (* Add in "dbsync = true" to the query to make sure the master
127137 * doesn't try to redirect here! *)
128138 let uri = uri ^ " ?uuid=" ^ uuid ^ " &dbsync=true" in
129139 let request =
130140 Http.Request. make ~user_agent: Constants. rrdd_user_agent
131141 ~cookie: [" pool_secret" , pool_secret] Http. Get uri in
132142 let open Xmlrpc_client in
133- let master_address = Pool_role_shared. get_master_address () in
134143 let transport = SSL (SSL. make () , master_address, ! Rrdd_shared. https_port) in
135144 with_transport transport (
136145 with_http request (fun (response , s ) ->
@@ -149,60 +158,56 @@ module Deprecated = struct
149158 * 1. For the local host after a xapi restart or host restart.
150159 * 2. For running VMs after a xapi restart.
151160 * It is now only used to load the host's RRD after xapi restart. *)
152- let load_rrd _ ~(uuid : string ) ~(domid : int ) ~(is_host : bool )
153- ~(timescale : int ) () : unit =
161+ let load_rrd _ ~(uuid : string ) ~(timescale : int ) ~(master_address : string option ) : unit =
154162 try
155163 let rrd =
156164 try
157165 let rrd = load_rrd_from_local_filesystem uuid in
158166 debug " RRD loaded from local filesystem for object uuid=%s" uuid;
159167 rrd
160168 with e ->
161- if Pool_role_shared. is_master () then begin
169+ match master_address with
170+ | None -> begin
162171 info " Failed to load RRD from local filesystem: metrics not available for uuid=%s" uuid;
163172 raise e
164- end else begin
173+ end
174+ | Some x -> begin
165175 debug " Failed to load RRD from local filesystem for object uuid=%s; asking master" uuid;
166176 try
167- let rrd = pull_rrd_from_master ~uuid ~is_host in
177+ let rrd = pull_rrd_from_master ~uuid ~master_address: x in
168178 debug " RRD pulled from master for object uuid=%s" uuid;
169179 rrd
170180 with e ->
171181 info " Failed to fetch RRD from master: metrics not available for uuid=%s" uuid;
172182 raise e
173183 end
174184 in
175- Mutex. execute mutex (fun () ->
176- if is_host
177- then begin
178- host_rrd := Some {rrd; dss = [] ; domid}
179- end else
180- Hashtbl. replace vm_rrds uuid {rrd; dss = [] ; domid}
181- )
185+ Mutex. execute mutex (fun () -> host_rrd := Some {rrd; dss = [] ; domid = 0 } )
182186 with _ -> ()
183187end
184188
185- (* Push function to push the archived RRD to the appropriate host
186- * (which might be us, in which case, pop it into the hashtbl. *)
187- let push_rrd _ ~(vm_uuid : string ) ~(domid : int ) ~(is_on_localhost : bool ) ()
188- : unit =
189+ let get_rrd ~vm_uuid =
190+ let path = Filename. concat Constants. rrd_location vm_uuid in
191+ rrd_of_gzip path
192+
193+ let push_rrd_local _ ~vm_uuid ~domid : unit =
189194 try
190- let path = Constants. rrd_location ^ " / " ^ vm_uuid in
191- let rrd = rrd_of_gzip path in
192- debug " Pushing RRD for VM uuid=%s " vm_uuid;
193- if is_on_localhost then
194- Mutex. execute mutex ( fun _ ->
195- Hashtbl. replace vm_rrds vm_uuid {rrd; dss = [] ; domid}
196- )
197- else
198- (* Host might be OpaqueRef:null, in which case we'll fail silently *)
199- let address = Pool_role_shared. get_master_address () in
200- send_rrd ~address ~to_archive: false ~ uuid: vm_uuid
201- ~rrd: (Rrd. copy_rrd rrd) ()
195+ let rrd = get_rrd ~ vm_uuid in
196+ debug " Pushing RRD for VM uuid=%s locally " vm_uuid;
197+ Mutex. execute mutex ( fun _ ->
198+ Hashtbl. replace vm_rrds vm_uuid {rrd; dss = [] ; domid}
199+ )
200+ with _ -> ()
201+
202+ let push_rrd_remote _ ~ vm_uuid ~ remote_address : unit =
203+ try
204+ let rrd = get_rrd ~vm_uuid in
205+ debug " Pushing RRD for VM uuid=%s remotely " vm_uuid;
206+ send_rrd ~address: remote_address ~to_archive: false ~uuid: vm_uuid ~rrd: (Rrd. copy_rrd rrd) ()
202207 with _ -> ()
203208
204209(* * Remove an RRD from the local filesystem, if it exists. *)
205- let remove_rrd _ ~(uuid : string ) () : unit =
210+ let remove_rrd _ ~(uuid : string ) : unit =
206211 let path = Constants. rrd_location ^ " /" ^ uuid in
207212 let gz_path = path ^ " .gz" in
208213 (try Unix. unlink path with _ -> () );
@@ -215,7 +220,7 @@ let remove_rrd _ ~(uuid : string) () : unit =
215220 * Remote address is assumed to be valid, since it is set by monitor_master.
216221 *)
217222let migrate_rrd _ ?(session_id : string option ) ~(remote_address : string )
218- ~(vm_uuid : string ) ~(host_uuid : string ) () : unit =
223+ ~(vm_uuid : string ) ~(host_uuid : string ) : unit =
219224 try
220225 let rrdi = Mutex. execute mutex (fun () ->
221226 let rrdi = Hashtbl. find vm_rrds vm_uuid in
@@ -237,12 +242,12 @@ let migrate_rrd _ ?(session_id : string option) ~(remote_address : string)
237242
238243(* Called on host shutdown/reboot to send the Host RRD to the master for
239244 * backup. Note all VMs will have been shutdown by now. *)
240- let send_host_rrd_to_master _ () =
245+ let send_host_rrd_to_master _ ~ master_address =
241246 match ! host_rrd with
242247 | Some rrdi ->
243248 debug " sending host RRD to master" ;
244249 let rrd = Mutex. execute mutex (fun () -> Rrd. copy_rrd rrdi.rrd) in
245- archive_rrd ~save_stats_locally: false ~uuid: (Inventory. lookup Inventory. _installation_uuid) ~rrd ()
250+ send_rrd ~address: master_address ~to_archive: true ~uuid: (Inventory. lookup Inventory. _installation_uuid) ~rrd ()
246251 | None -> ()
247252
248253let add_ds ~rrdi ~ds_name =
@@ -346,7 +351,7 @@ let query_sr_ds _ ~(sr_uuid : string) ~(ds_name : string) : float =
346351 Rrd. query_named_ds rrdi.rrd now ds_name Rrd. CF_Average
347352 )
348353
349- let update_use_min_max _ ~(value : bool ) () : unit =
354+ let update_use_min_max _ ~(value : bool ) : unit =
350355 debug " Updating use_min_max: New value=%b" value;
351356 use_min_max := value
352357
@@ -357,7 +362,7 @@ let update_vm_memory_target _ ~(domid : int) ~(target : int64) : unit =
357362 Mutex. execute memory_targets_m
358363 (fun _ -> Hashtbl. replace memory_targets domid target)
359364
360- let set_cache_sr _ ~(sr_uuid : string ) () : unit =
365+ let set_cache_sr _ ~(sr_uuid : string ) : unit =
361366 Mutex. execute cache_sr_lock (fun () -> cache_sr_uuid := Some sr_uuid)
362367
363368let unset_cache_sr _ () =
529534
530535module HA = struct
531536 let enable_and_update _ ~(statefile_latencies : Rrd.Statefile_latency.t list )
532- ~(heartbeat_latency : float ) ~(xapi_latency : float ) () =
537+ ~(heartbeat_latency : float ) ~(xapi_latency : float ) =
533538 Mutex. execute Rrdd_ha_stats. m (fun _ ->
534539 Rrdd_ha_stats. enabled := true ;
535540 Rrdd_ha_stats.Statefile_latency. all := statefile_latencies;
0 commit comments