Skip to content

Commit 53a081c

Browse files
authored
rrd2csv: Accept a trailing comma in metrics names (#6214)
rrd2csv itself prints out a list of comma-separated metrics names, but could't accept this list as command line arguments: ``` $ rrd2csv .....memory_total_kib, memory_free_kib, .... $ rrd2csv memory_total_kib, memory_free_kib WARNING: Requested metric AVERAGE:host:05e817e2-3a65-484d-b0da-a7163f9ffc12:memory_total_kib, is disabled or non-existant timestamp, AVERAGE:host:05e817e2-3a65-484d-b0da-a7163f9ffc12:memory_free_kib 2025-01-07T14:06:45Z, 30042000 ``` Now this works just fine: ``` $ rrd2csv memory_total_kib, memory_free_kib timestamp, AVERAGE:host:92bc3b1e-e0a3-49ba-8994-fc305ff882b7:memory_total_kib, AVERAGE:host:92bc3b1e-e0a3-49ba-8994-fc305ff882b7:memory_free_kib 2025-01-07T15:04:50Z, 33350000, 30023000 ```
2 parents 264ca76 + 32b154e commit 53a081c

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

ocaml/rrd2csv/src/rrd2csv.ml

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,27 +149,33 @@ module Ds_selector = struct
149149

150150
let of_string str =
151151
let open Rrd in
152-
let splitted = Xstringext.String.split ':' str in
152+
let splitted = Xstringext.String.split ',' str in
153153
match splitted with
154-
| [cf; owner; uuid; metric] ->
155-
{
156-
cf= (try Some (cf_type_of_string cf) with _ -> None)
157-
; owner=
158-
( match owner with
159-
| "vm" ->
160-
Some (VM uuid)
161-
| "sr" ->
162-
Some (SR uuid)
163-
| "host" ->
164-
Some Host
165-
| _ ->
166-
None
167-
)
168-
; uuid
169-
; metric
170-
}
171-
| [metric] ->
172-
{empty with metric}
154+
| without_trailing_comma :: _ -> (
155+
let splitted = Xstringext.String.split ':' without_trailing_comma in
156+
match splitted with
157+
| [cf; owner; uuid; metric] ->
158+
{
159+
cf= (try Some (cf_type_of_string cf) with _ -> None)
160+
; owner=
161+
( match owner with
162+
| "vm" ->
163+
Some (VM uuid)
164+
| "sr" ->
165+
Some (SR uuid)
166+
| "host" ->
167+
Some Host
168+
| _ ->
169+
None
170+
)
171+
; uuid
172+
; metric
173+
}
174+
| [metric] ->
175+
{empty with metric}
176+
| _ ->
177+
failwith "ds_selector_of_string"
178+
)
173179
| _ ->
174180
failwith "ds_selector_of_string"
175181

0 commit comments

Comments
 (0)