绘制多个系列的图表,这些系列都位于同一列中?

绘制多个系列的图表,这些系列都位于同一列中?

我正在尝试找到一种快速方法来获取 Cloudwatch 指标并将其绘制在 Excel 中,因为 Cloudwatch 无法在一次 API 调用中呈现数据。我只需要一个指标,但我需要从 526 个 EC2 实例中获得它,并且我需要它几个月。

到目前为止我已经获取了所有数据

mkdir /tmp/i
jq -r '.Reservations[].Instances[]|select([.Tags[].Value == "'"$tag"'"]|any).InstanceId' /tmp/instances \
  | xargs -n1 -P6 sh -c 'aws cloudwatch get-metric-statistics  \
--namespace the_namespace --metric-name the_metric_name \
--dimensions Name=InstanceId,Value=$0 \
--statistics Average \
--start-time $start  \
--end-time $end \
--period 86400 \
--region us-west-2  | tee /tmp/i/$0'

并且可以以CSV格式转储数据:

(cd /tmp/i; find . -type f -print0 | xargs --null -n1 sh -c "jq -c '.Datapoints[]|[\"'\$0'\",.Timestamp,.Average]|@csv' /tmp/i/\$0" | sort)

现在有两个挑战:

  1. 数据稀疏。如果实例在某个时间段内停止,则不会有零数据点,也不会有数据点。我认为如果我为时间序列设置 X 轴值,Excel 可以处理这个问题

  2. 该系列全部放在一个大栏目中。例如:

....
"./i-oneoneoneoneoneone","2021-02-04T00:00:00Z",0
"./i-oneoneoneoneoneone","2021-02-05T00:00:00Z",0.0002314814814814815
"./i-oneoneoneoneoneone","2021-02-06T00:00:00Z",0
"./i-oneoneoneoneoneone","2021-02-07T00:00:00Z",0
"./i-oneoneoneoneoneone","2021-02-08T00:00:00Z",0
"./i-oneoneoneoneoneone","2021-02-09T00:00:00Z",0
"./i-oneoneoneoneoneone","2021-02-10T00:00:00Z",0
"./i-twotwotwotwotwotwo","2020-11-15T00:00:00Z",0
"./i-twotwotwotwotwotwo","2020-11-16T00:00:00Z",0
"./i-twotwotwotwotwotwo","2020-11-17T00:00:00Z",0
"./i-twotwotwotwotwotwo","2020-11-18T00:00:00Z",0
"./i-twotwotwotwotwotwo","2020-11-19T00:00:00Z",0
"./i-twotwotwotwotwotwo","2020-11-20T00:00:00Z",0
...

我想 Excel 希望它们更像这样:

"","i-oneoneoneoneoneone","","i-twotwotwotwotwotwo", ...
"2021-02-04T00:00:00Z",0,"2020-11-15T00:00:00Z",0
"2021-02-05T00:00:00Z",0.0002314814814814815,"2020-11-16T00:00:00Z",0
"2021-02-06T00:00:00Z",0,"2020-11-16T00:00:00Z",0
"2021-02-07T00:00:00Z",0,"2020-11-17T00:00:00Z",0
"2021-02-08T00:00:00Z",0,"2020-11-18T00:00:00Z",0
"2021-02-09T00:00:00Z",0,"2020-11-19T00:00:00Z",0
"2021-02-10T00:00:00Z",0,"2020-11-20T00:00:00Z",0
...

其中系列位于相邻的 (x,y) 列对中。鉴于我有数百个这样的系列,我真的不想剪切和粘贴它们。

相关内容