Skip to content

Commit 137731c

Browse files
committed
CP-13995: Periodic Archiving of SR-level RRDs
1) backup_rrds need to backup sr rrds on a host. 2) Xapi_periodic_scheduler performs backup of SR-level RRDs too. 3) Asks xcp-rrdd to archive RRDs and copy them to filesystem. 4) Xapi copies these archived RRDs from filesystem to sr-stats vdi Signed-off-by: Sharad Yadav <[email protected]>
1 parent b4a1c4d commit 137731c

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

ocaml/xapi/xapi_host.ml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,10 +950,19 @@ let has_extension ~__context ~name =
950950
let sync_data ~__context ~host =
951951
Xapi_sync.sync_host __context host (* Nb, no attempt to wrap exceptions yet *)
952952

953+
let copy_srs_rrds ~__context () =
954+
let srs = Xapi_sr.srs_with_rrds ~__context in
955+
if !srs <> [] then begin
956+
List.iter (fun sr ->
957+
let vdi = Xapi_vdi_helpers.create_rrd_vdi ~__context ~sr:sr in
958+
Xapi_vdi_helpers.copy_sr_rdds ~__context ~sr:sr ~vdi:vdi ~archive:false) !srs
959+
end
960+
953961
let backup_rrds ~__context ~host ~delay =
954962
Xapi_periodic_scheduler.add_to_queue "RRD backup" Xapi_periodic_scheduler.OneShot
955963
delay (fun _ ->
956-
log_and_ignore_exn (Rrdd.backup_rrds ~save_stats_locally:(Pool_role.is_master ()))
964+
log_and_ignore_exn (Rrdd.backup_rrds ~save_stats_locally:(Pool_role.is_master ()));
965+
log_and_ignore_exn (copy_srs_rrds ~__context)
957966
)
958967

959968
let get_servertime ~__context ~host =

ocaml/xapi/xapi_host.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ val call_plugin :
164164
host:[ `host ] Ref.t ->
165165
plugin:string -> fn:string -> args:(string * string) list -> string
166166
val sync_data : __context:Context.t -> host:API.ref_host -> unit
167-
val backup_rrds : __context:'a -> host:'b -> delay:float -> unit
167+
val backup_rrds : __context:Context.t -> host:'b -> delay:float -> unit
168168
val get_servertime : __context:'a -> host:'b -> Date.iso8601
169169
val get_server_localtime : __context:'a -> host:'b -> Date.iso8601
170170
val enable_binary_storage :

ocaml/xapi/xapi_periodic_scheduler_init.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ let register () =
3939
(* Periodic backup of RRDs *)
4040
let rrdbackup_timer =
4141
if Xapi_fist.reduce_rrd_backup_interval then 60.0 *. 5.0 else !Xapi_globs.rrd_backup_interval in
42-
let rrdbackup_func () =
43-
Server_helpers.exec_with_new_task "rrdbackup_func"
44-
(fun __context ->
45-
let hosts = Db.Host.get_all ~__context in
46-
Helpers.call_api_functions ~__context
47-
(fun rpc session_id ->
48-
ignore(List.fold_left (fun delay host -> Client.Client.Host.backup_rrds rpc session_id host delay; (delay +. 60.0)) 0.0 hosts)))
49-
in
42+
let rrdbackup_func () =
43+
Server_helpers.exec_with_new_task "rrdbackup_func"
44+
(fun __context ->
45+
let hosts = Db.Host.get_all ~__context in
46+
Helpers.call_api_functions ~__context
47+
(fun rpc session_id ->
48+
ignore(List.fold_left (fun delay host -> Client.Client.Host.backup_rrds rpc session_id host delay; (delay +. 60.0)) 0.0 hosts))
49+
)
50+
in
5051
let rrdbackup_delay =
5152
if Xapi_fist.reduce_rrd_backup_interval then 60.0 *. 6.0 else 3600.0 in
5253

ocaml/xapi/xapi_sr.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,27 @@ let scanning_thread () = Debug.with_thread_named "scanning_thread" (fun () ->
126126

127127
let sr_cache = ref []
128128

129-
let update_physical_utilisation ~__context =
129+
let srs_with_rrds ~__context =
130130
let srs = Helpers.get_all_plugged_srs ~__context in
131131
(* Remove SRs from sr_cache if they are no more available *)
132132
sr_cache := List.filter (fun sr -> (List.mem sr srs)) !sr_cache;
133133
(* Checks whether SR is sr_master and has SR_STATS capability *)
134134
let is_stats_sr ~__context sr =
135135
let sr_record = Db.SR.get_record_internal ~__context ~self:sr in
136136
if (Smint.(has_capability Sr_stats (Xapi_sr_operations.features_of_sr ~__context sr_record)) &&
137-
(Helpers.i_am_srmaster ~__context ~sr))
138-
then true else false
137+
(Helpers.i_am_srmaster ~__context ~sr)) then true else false
139138
in
140139
let srs_to_be_added = List.filter (fun sr -> (List.mem sr !sr_cache = false) && (is_stats_sr ~__context sr)) srs in
141140
sr_cache := !sr_cache @ srs_to_be_added;
141+
sr_cache
142+
143+
let update_physical_utilisation ~__context =
144+
let srs = srs_with_rrds ~__context in
142145
(* Update the physical utilisation db field of cached SRs *)
143146
List.iter (fun sr ->
144147
let new_value = Rrdd.query_sr_ds ~sr_uuid:(Db.SR.get_uuid ~__context ~self:sr) ~ds_name:"physical_utilisation" in
145-
Db.SR.set_physical_utilisation ~__context ~self:sr ~value:(Int64.of_float new_value)) !sr_cache
148+
Db.SR.set_physical_utilisation ~__context ~self:sr ~value:(Int64.of_float new_value)
149+
) !srs
146150

147151
let physical_utilisation_thread ~__context () =
148152
while true do

0 commit comments

Comments
 (0)