simplequery.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. "strings"
  17. "yunion.io/x/jsonutils"
  18. )
  19. type SimpleQueryOptions struct {
  20. Id string `json:"id"`
  21. Database string `json:"database"`
  22. MetricName string `json:"metric_name"`
  23. StartTime string `json:"start_time" help:"e.g.: 2023-12-06T21:54:42.123Z"`
  24. EndTime string `json:"end_time" help:"e.g.: 2023-12-18T21:54:42.123Z"`
  25. Tags []string `json:"tags"`
  26. }
  27. func (o *SimpleQueryOptions) GetId() string {
  28. return "simple-query"
  29. }
  30. func (o *SimpleQueryOptions) Params() (jsonutils.JSONObject, error) {
  31. ret := jsonutils.Marshal(o).(*jsonutils.JSONDict)
  32. ret.Remove("tags")
  33. tags := map[string]string{}
  34. for _, tag := range o.Tags {
  35. if strings.Contains(tag, "=") {
  36. info := strings.Split(tag, "=")
  37. if len(info) == 2 {
  38. tags[info[0]] = info[1]
  39. }
  40. }
  41. }
  42. if len(tags) > 0 {
  43. ret.Set("tag_pairs", jsonutils.Marshal(tags))
  44. }
  45. return ret, nil
  46. }
  47. type CdfQueryOptions struct {
  48. Database string `json:"database"`
  49. MetricName string `json:"metric_name"`
  50. StartTime string `json:"start_time" help:"e.g.: 2023-12-06T21:54:42.123Z"`
  51. EndTime string `json:"end_time" help:"e.g.: 2023-12-18T21:54:42.123Z"`
  52. Tags []string `json:"tags"`
  53. }
  54. func (o *CdfQueryOptions) GetId() string {
  55. return "cdf-query"
  56. }
  57. func (o *CdfQueryOptions) Params() (jsonutils.JSONObject, error) {
  58. ret := jsonutils.Marshal(o).(*jsonutils.JSONDict)
  59. ret.Remove("tags")
  60. tags := map[string]string{}
  61. for _, tag := range o.Tags {
  62. if strings.Contains(tag, "=") {
  63. info := strings.Split(tag, "=")
  64. if len(info) == 2 {
  65. tags[info[0]] = info[1]
  66. }
  67. }
  68. }
  69. if len(tags) > 0 {
  70. ret.Set("tag_pairs", jsonutils.Marshal(tags))
  71. }
  72. return ret, nil
  73. }