vm_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 victoriametrics
  15. /*import (
  16. "context"
  17. "testing"
  18. "yunion.io/x/jsonutils"
  19. "yunion.io/x/log"
  20. "yunion.io/x/onecloud/pkg/apis/monitor"
  21. "yunion.io/x/onecloud/pkg/monitor/tsdb"
  22. )
  23. func Test_queryByRaw(t *testing.T) {
  24. ds := &tsdb.DataSource{
  25. Id: "vm",
  26. Name: "vm",
  27. Type: "victoricmetrics",
  28. Url: "http://192.168.222.171:34795/",
  29. }
  30. q := &tsdb.TsdbQuery{
  31. TimeRange: tsdb.NewTimeRange("48h", "now"),
  32. Queries: []*tsdb.Query{
  33. {
  34. RefId: "A",
  35. MetricQuery: monitor.MetricQuery{
  36. Database: "telegraf",
  37. Measurement: "cpu",
  38. Selects: []monitor.MetricQuerySelect{
  39. {
  40. {
  41. Type: "field",
  42. Params: []string{"usage_active"},
  43. },
  44. {
  45. Type: "mean",
  46. },
  47. },
  48. },
  49. Tags: []monitor.MetricQueryTag{
  50. {
  51. Key: "res_type",
  52. Operator: "=",
  53. Value: "host",
  54. },
  55. },
  56. GroupBy: []monitor.MetricQueryPart{
  57. //{
  58. // Type: "tag",
  59. // Params: []string{"host_id"},
  60. //},
  61. {
  62. Type: "tag",
  63. Params: []string{"*"},
  64. },
  65. },
  66. },
  67. },
  68. },
  69. Debug: false,
  70. }
  71. ep, _ := NewVMAdapter(ds)
  72. resp, err := ep.Query(context.Background(), ds, q)
  73. if err != nil {
  74. t.Fatalf("queryByRaw error: %v", err)
  75. }
  76. log.Infof("resp: %s", jsonutils.Marshal(resp).PrettyString())
  77. }
  78. */