commonalertmetric.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package monitor
  15. import (
  16. "yunion.io/x/jsonutils"
  17. monitorapi "yunion.io/x/onecloud/pkg/apis/monitor"
  18. "yunion.io/x/onecloud/pkg/mcclient/options"
  19. )
  20. type MonitorMetricListOptions struct {
  21. options.BaseListOptions
  22. MeasurementName []string `help:"name of Measurement"`
  23. ResType string `help:"Resource properties of measurement e.g. guest/host/redis/oss/rds"`
  24. MeasurementDisplayName string `help:"The name of the measurement customization"`
  25. FieldName []string `help:"Name of Field"`
  26. Unit string `help:"Unit of Field " choices:"%|bps|Mbps|Bps|cps|count|ms|byte"`
  27. FieldDisplayName string `help:"The name of the field customization"`
  28. }
  29. func (o *MonitorMetricListOptions) Params() (jsonutils.JSONObject, error) {
  30. param, err := options.ListStructToParams(&(o.BaseListOptions))
  31. if err != nil {
  32. return nil, err
  33. }
  34. metricInput := new(monitorapi.MetricListInput)
  35. metricInput.Measurement.Names = o.MeasurementName
  36. metricInput.Measurement.ResType = o.ResType
  37. metricInput.Measurement.DisplayName = o.MeasurementDisplayName
  38. metricInput.MetricFields.Names = o.FieldName
  39. metricInput.MetricFields.Unit = o.Unit
  40. metricInput.MetricFields.DisplayName = o.FieldDisplayName
  41. listParam := metricInput.JSON(metricInput)
  42. param.Update(listParam)
  43. return param, nil
  44. }
  45. type MetricUpdateOptions struct {
  46. ID string `help:"ID of Metric " required:"true" positional:"true"`
  47. ResType string `help:"Resource properties of measurement e.g. guest/host/redis/oss/rds" required:"true"`
  48. MeasurementDisplayName string `help:"The name of the measurement customization" required:"true"`
  49. FieldName string `help:"Name of Field" required:"true"`
  50. FieldDisplayName string `help:"The name of the field customization" required:"true"`
  51. Unit string `help:"Unit of Field" choices:"%|bps|Mbps|Bps|cps|count|ms|byte" required:"true"`
  52. }
  53. func (o *MetricUpdateOptions) GetId() string {
  54. return o.ID
  55. }
  56. func (o *MetricUpdateOptions) Params() (jsonutils.JSONObject, error) {
  57. updateInput := new(monitorapi.MetricUpdateInput)
  58. updateInput.Measurement.DisplayName = o.MeasurementDisplayName
  59. updateInput.Measurement.ResType = o.ResType
  60. updateField := new(monitorapi.MetricFieldUpdateInput)
  61. updateField.Name = o.FieldName
  62. updateField.DisplayName = o.FieldDisplayName
  63. updateField.Unit = o.Unit
  64. updateInput.MetricFields = []monitorapi.MetricFieldUpdateInput{*updateField}
  65. updateInput.Scope = "system"
  66. return updateInput.JSON(updateInput), nil
  67. }
  68. type MetricShowOptions struct {
  69. ID string `help:"ID of Metric " json:"-"`
  70. }
  71. func (o *MetricShowOptions) Params() (jsonutils.JSONObject, error) {
  72. return options.StructToParams(o)
  73. }
  74. func (o *MetricShowOptions) GetId() string {
  75. return o.ID
  76. }
  77. type MetricDeleteOptions struct {
  78. ID string `help:"ID of Metric " json:"-"`
  79. }
  80. func (o *MetricDeleteOptions) GetId() string {
  81. return o.ID
  82. }
  83. func (o *MetricDeleteOptions) Params() (jsonutils.JSONObject, error) {
  84. return options.StructToParams(o)
  85. }