2
* Copyright (C) 2006-2009 Citrix Systems Inc.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation; version 2.1 only. with the special
7
* exception on linking described in file LICENSE.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU Lesser General Public License for more details.
15
* @group Performance Monitoring
23
(uuid,vif) -> (*(i2,(s,i64_1, i64_2))) ->*)
26
XMLRPC.To.string uuid;
27
XMLRPC.To.string (string_of_int vif.vif_n);
28
XMLRPC.To.string vif.vif_name;
29
XMLRPC.To.string (string_of_float vif.vif_tx);
30
XMLRPC.To.string (string_of_float vif.vif_rx)
32
XMLRPC.To.array (List.map f l)
34
let unmarshall_vifs xml =
36
match XMLRPC.From.array (fun x->x) xml with
37
[uuid;i2;s;i64_1;i64_2] ->
38
(XMLRPC.From.string uuid,
39
{vif_n=int_of_string (XMLRPC.From.string i2);
40
vif_name=(XMLRPC.From.string s);
41
vif_tx=float_of_string (XMLRPC.From.string i64_1);
42
vif_rx=float_of_string (XMLRPC.From.string i64_2);
47
| _ -> failwith (Printf.sprintf "unmarshall_vifs unexpected XML: %s" (Xml.to_string xml))
49
List.map f (XMLRPC.From.array (fun x->x) xml)
57
XMLRPC.To.string uuid;
58
XMLRPC.To.string (string_of_int vbd.vbd_device_id);
59
XMLRPC.To.string (string_of_float vbd.vbd_io_read);
60
XMLRPC.To.string (string_of_float vbd.vbd_io_write);
62
XMLRPC.To.array (List.map f l)
64
let unmarshall_vbds xml =
66
match XMLRPC.From.array (fun x->x) xml with
67
[uuid;i2;i64_1;i64_2] ->
68
(XMLRPC.From.string uuid,
69
{vbd_device_id=int_of_string (XMLRPC.From.string i2);
70
vbd_io_read=float_of_string (XMLRPC.From.string i64_1);
71
vbd_io_write=float_of_string (XMLRPC.From.string i64_2);
73
vbd_raw_io_write=0L;})
74
| _ -> failwith (Printf.sprintf "unmarshall_vbds unexpected XML: %s" (Xml.to_string xml))
76
List.map f (XMLRPC.From.array (fun x->x) xml)
78
let marshall_float_array (a : float array) =
79
let l = Array.to_list a in
80
XMLRPC.To.array (List.map (fun x -> XMLRPC.To.string (string_of_float x)) l)
82
let unmarshall_float_array xml : float array =
83
Array.of_list (XMLRPC.From.array (fun x -> float_of_string (XMLRPC.From.string x)) xml)
85
let marshall_pcpus pcpus =
86
XMLRPC.To.array [ marshall_float_array pcpus.pcpus_usage ]
88
let unmarshall_pcpus xml =
89
match XMLRPC.From.array (fun x->x) xml with
90
[ia] -> {pcpus_usage=unmarshall_float_array ia}
91
| _ -> failwith (Printf.sprintf "unmarshall_pcpus unexpected XML: %s" (Xml.to_string xml))
94
let marshall_vcpus l =
100
XMLRPC.To.string uuid;
101
XMLRPC.To.string (string_of_float vcpus.vcpu_sumcpus);
102
marshall_float_array (vcpus.vcpu_vcpus)
104
XMLRPC.To.array (List.map f l)
106
let unmarshall_vcpus xml =
108
match XMLRPC.From.array (fun x->x) xml with
110
(XMLRPC.From.string uuid,
111
{vcpu_sumcpus=float_of_string (XMLRPC.From.string i);
112
vcpu_vcpus=unmarshall_float_array ia;
116
| _ -> failwith (Printf.sprintf "unmarshall_vcpus unexpected XML: %s" (Xml.to_string xml))
118
List.map f (XMLRPC.From.array (fun x->x) xml)
120
let marshall_memory l =
126
XMLRPC.To.string uuid;
127
XMLRPC.To.string (Int64.to_string mem.memory_mem)
129
XMLRPC.To.array (List.map f l)
131
let unmarshall_memory xml =
133
match XMLRPC.From.array (fun x->x) xml with
135
(XMLRPC.From.string uuid,
136
{memory_mem=Int64.of_string (XMLRPC.From.string i64)})
137
| _ -> failwith (Printf.sprintf "unmarshall_memory unexpected XML: %s" (Xml.to_string xml))
139
List.map f (XMLRPC.From.array (fun x->x) xml)
141
let marshall_pifs pifs =
142
let f x = match x with
145
XMLRPC.To.string pif.pif_name;
146
XMLRPC.To.string (string_of_float pif.pif_tx);
147
XMLRPC.To.string (string_of_float pif.pif_rx);
148
XMLRPC.To.string (string_of_bool pif.pif_carrier);
149
XMLRPC.To.string (string_of_int (Netdev.Link.int_of_speed pif.pif_speed));
150
XMLRPC.To.string (Netdev.Link.string_of_duplex pif.pif_duplex);
151
XMLRPC.To.string pif.pif_pci_bus_path;
152
XMLRPC.To.string pif.pif_vendor_id;
153
XMLRPC.To.string pif.pif_device_id;
155
XMLRPC.To.array (List.map f pifs)
157
let unmarshall_pifs xml =
158
let f xml = match XMLRPC.From.array (fun x -> x) xml with
159
| [ name; i64_1; i64_2; carrier; speed; duplex; pcibuspath; vendor; device ] ->
160
{pif_name=XMLRPC.From.string name;
161
pif_tx=float_of_string (XMLRPC.From.string i64_1);
162
pif_rx=float_of_string (XMLRPC.From.string i64_2);
164
pif_raw_rx=0L; (* Ignore these, for RRD only *)
165
pif_carrier=bool_of_string (XMLRPC.From.string carrier);
166
pif_speed=Netdev.Link.speed_of_int (int_of_string (XMLRPC.From.string speed));
167
pif_duplex=Netdev.Link.duplex_of_string (XMLRPC.From.string duplex);
168
pif_pci_bus_path=XMLRPC.From.string pcibuspath;
169
pif_vendor_id=XMLRPC.From.string vendor;
170
pif_device_id=XMLRPC.From.string device}
171
| _ -> failwith (Printf.sprintf "unmarshall_pifs unexpected XML: %s" (Xml.to_string xml))
173
List.map f (XMLRPC.From.array (fun x -> x) xml)
175
let marshall_uuids uuids =
176
XMLRPC.To.array (List.map XMLRPC.To.string uuids)
178
let unmarshall_uuids xml =
179
XMLRPC.From.array XMLRPC.From.string xml
181
let marshall_host_stats hs =
184
XMLRPC.To.string (Ref.string_of hs.host_ref);
185
XMLRPC.To.string (Int64.to_string hs.total_kib);
186
XMLRPC.To.string (Int64.to_string hs.free_kib);
187
marshall_vifs hs.vifs;
188
marshall_pifs hs.pifs;
189
marshall_vbds hs.vbds;
190
marshall_pcpus hs.pcpus;
191
marshall_vcpus hs.vcpus;
192
marshall_memory hs.mem;
193
marshall_uuids hs.registered
196
let unmarshall_host_stats xml =
197
match (XMLRPC.From.array (fun x->x) xml) with
198
[href; i64_1; i64_2; vifs; pifs; vbds; pcpus; vcpus; mem; uuids] ->
200
host_ref=Ref.of_string (XMLRPC.From.string href);
201
total_kib=Int64.of_string (XMLRPC.From.string i64_1);
202
free_kib=Int64.of_string (XMLRPC.From.string i64_2);
203
vifs=unmarshall_vifs vifs;
204
pifs=unmarshall_pifs pifs;
205
vbds=unmarshall_vbds vbds;
206
pcpus=unmarshall_pcpus pcpus;
207
vcpus=unmarshall_vcpus vcpus;
208
mem=unmarshall_memory mem;
209
registered=unmarshall_uuids uuids}
210
| [vifs; pifs; vbds; pcpus; vcpus; mem; hostmetrics; uuids] ->
211
(* CA-18377: This case supports unmarshalling of data from a Miami host. *)
213
match (XMLRPC.From.array (fun x->x) hostmetrics) with
214
[href; i64_1; i64_2] ->
216
host_ref=Ref.of_string (XMLRPC.From.string href);
217
total_kib=Int64.of_string (XMLRPC.From.string i64_1);
218
free_kib=Int64.of_string (XMLRPC.From.string i64_2);
219
vifs=unmarshall_vifs vifs;
220
pifs=unmarshall_pifs pifs;
221
vbds=unmarshall_vbds vbds;
222
pcpus=unmarshall_pcpus pcpus;
223
vcpus=unmarshall_vcpus vcpus;
224
mem=unmarshall_memory mem;
225
registered=unmarshall_uuids uuids}
226
| _ -> failwith (Printf.sprintf "unmarshall_host_stats unexpected XML: %s" (Xml.to_string xml))
228
| _ -> failwith (Printf.sprintf "unmarshall_host_stats unexpected XML: %s" (Xml.to_string xml))
231
marshall_host_stats hs
234
unmarshall_host_stats xml