未验证 提交 c38c595a 编写于 作者: K kezhenxu94 提交者: GitHub

[Feature] Support top N entities and thermodynamic metrics (#33)

### Motivation

Support top N entities and thermodynamic metrics commands

### Result

- Commands `metrics top n` and `thermodynamic` are added

- Closes https://github.com/apache/skywalking/issues/3898

- Closes https://github.com/apache/skywalking/issues/3897
上级 53d1395a
......@@ -24,7 +24,7 @@ linters-settings:
maligned:
suggest-new: true
dupl:
threshold: 100
threshold: 200
goconst:
min-len: 2
min-occurrences: 2
......@@ -93,4 +93,4 @@ linters:
service:
golangci-lint-version: 1.20.x
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"
\ No newline at end of file
- echo "here I can run custom commands, but no preparation needed for this repo"
......@@ -83,7 +83,10 @@ This section covers all the available commands in SkyWalking CLI and their usage
| `--config` | from where the default options values will be loaded | `~/.skywalking.yml` |
| `--debug` | enable debug mode, will print more detailed information at runtime | `false` |
| `--base-url` | base url of GraphQL backend | `http://127.0.0.1:12800/graphql` |
| `--display` | display style when printing the query result, supported styles are: `json`, `yaml`, `table` | `json` |
| `--display` | display style when printing the query result, supported styles are: `json`, `yaml`, `table`, `graph` | `json` |
Note that not all display styles (except for `json` and `yaml`) are supported in all commands due to data formats incompatibilities and the limits of
Ascii Graph, like coloring in terminal, so please use `json` or `yaml` instead.
### `service`
......@@ -197,6 +200,36 @@ This section covers all the available commands in SkyWalking CLI and their usage
</details>
#### `metrics top <n>`
<details>
<summary>metrics top 3 [--start=start-time] [--end=end-time] --name endpoint_sla [--service-id 3]</summary>
| option | description | default |
| :--- | :--- | :--- |
| `--name` | Metrics name, defined in [OAL](https://github.com/apache/skywalking/blob/master/oap-server/server-bootstrap/src/main/resources/official_analysis.oal), such as `service_sla`, etc. |
| `--service-id` | service ID that are required by the metric type, such as service IDs for `service_sla` |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |
| arguments | the first argument is the number of top entities | `3` |
</details>
#### `metrics thermodynamic`
<details>
<summary>metrics thermodynamic --name=thermodynamic name</summary>
| option | description | default |
| :--- | :--- | :--- |
| `--name` | Metrics name, defined in [OAL](https://github.com/apache/skywalking/blob/master/oap-server/server-bootstrap/src/main/resources/official_analysis.oal), such as `service_sla`, etc. |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |
</details>
# Use Cases
<details>
......@@ -244,7 +277,7 @@ $ ./bin/swctl endpoint ls --service-id=3
otherwise,
```shell
./bin/swctl service ls projectC | jq '.[].id' | xargs ./bin/swctl-latest-darwin-amd64 endpoint ls --service-id
./bin/swctl service ls projectC | jq '.[].id' | xargs ./bin/swctl endpoint ls --service-id
[{"id":"22","name":"/projectC/{value}"}]
```
......@@ -331,7 +364,7 @@ $ ./bin/swctl service ls projectC | jq '.[0].id' | xargs ./bin/swctl endpoint ls
<summary>Query multiple metrics values for all percentiles</summary>
```shell
$ ./bin/swctl-latest-darwin-amd64 --display=graph --debug metrics multiple-linear --name all_percentile
$ ./bin/swctl --display=graph --debug metrics multiple-linear --name all_percentile
┌PRESS Q TO QUIT───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│┌───────────────────────────────#0───────────────────────────────┐┌───────────────────────────────#1───────────────────────────────┐┌─────────────────────────────────#2─────────────────────────────────┐│
......@@ -395,6 +428,50 @@ $ ./bin/swctl-latest-darwin-amd64 --display=graph --debug metrics multiple-linea
<details>
<summary>Query the top 5 services whose sla is largest</summary>
```shell
$ ./bin/swctl metrics top 5 --name service_sla
[{"name":"projectB","id":"2","value":10000},{"name":"projectC","id":"3","value":10000},{"name":"projectA","id":"4","value":10000},{"name":"projectD","id":"5","value":10000}]
```
</details>
<details>
<summary>Query the top 5 instances whose sla is largest, of service (id = 3)</summary>
```shell
$ ./bin/swctl metrics top 5 --name service_instance_sla --service-id 3
[{"name":"projectC-pid:30335@skywalking-server-0002","id":"13","value":10000},{"name":"projectC-pid:22037@skywalking-server-0001","id":"2","value":10000}]
```
</details>
<details>
<summary>Query the top 5 endpoints whose sla is largest, of service (id = 3)</summary>
```shell
$ ./bin/swctl metrics top 5 --name endpoint_sla --service-id 3
[{"name":"/projectC/{value}","id":"4","value":10000}]
```
</details>
<details>
<summary>Query the overall heatmap</summary>
```shell
$ ./bin/swctl metrics thermodynamic --name all_heatmap
{"nodes":[[0,0,238],[0,1,1],[0,2,39],[0,3,31],[0,4,12],[0,5,13],[0,6,4],[0,7,3],[0,8,3],[0,9,0],[0,10,48],[0,11,3],[0,12,49],[0,13,54],[0,14,11],[0,15,9],[0,16,2],[0,17,4],[0,18,0],[0,19,1],[0,20,186],[1,0,264],[1,1,3],[1,2,51],[1,3,38],[1,4,16],[1,5,14],[1,6,3],[1,7,2],[1,8,1],[1,9,2],[1,10,51],[1,11,1],[1,12,41],[1,13,56],[1,14,16],[1,15,15],[1,16,7],[1,17,7],[1,18,3],[1,19,1],[1,20,174],[2,0,231],[2,1,3],[2,2,42],[2,3,41],[2,4,18],[2,5,4],[2,6,2],[2,7,1],[2,8,2],[2,9,0],[2,10,54],[2,11,4],[2,12,55],[2,13,48],[2,14,14],[2,15,4],[2,16,3],[2,17,2],[2,18,4],[2,19,4],[2,20,187],[3,0,231],[3,1,3],[3,2,55],[3,3,38],[3,4,18],[3,5,9],[3,6,1],[3,7,1],[3,8,1],[3,9,1],[3,10,56],[3,11,6],[3,12,38],[3,13,50],[3,14,16],[3,15,12],[3,16,4],[3,17,4],[3,18,2],[3,19,2],[3,20,183],[4,0,238],[4,1,2],[4,2,47],[4,3,49],[4,4,11],[4,5,7],[4,6,0],[4,7,0],[4,8,2],[4,9,2],[4,10,55],[4,11,3],[4,12,41],[4,13,47],[4,14,12],[4,15,7],[4,16,3],[4,17,2],[4,18,10],[4,19,0],[4,20,190],[5,0,238],[5,1,3],[5,2,42],[5,3,28],[5,4,18],[5,5,4],[5,6,2],[5,7,4],[5,8,4],[5,9,1],[5,10,54],[5,11,2],[5,12,65],[5,13,56],[5,14,17],[5,15,9],[5,16,2],[5,17,3],[5,18,0],[5,19,2],[5,20,179],[6,0,218],[6,1,1],[6,2,34],[6,3,37],[6,4,10],[6,5,5],[6,6,1],[6,7,1],[6,8,0],[6,9,3],[6,10,49],[6,11,7],[6,12,47],[6,13,43],[6,14,19],[6,15,15],[6,16,1],[6,17,4],[6,18,2],[6,19,3],[6,20,183],[7,0,242],[7,1,0],[7,2,41],[7,3,34],[7,4,21],[7,5,4],[7,6,3],[7,7,4],[7,8,1],[7,9,0],[7,10,71],[7,11,4],[7,12,47],[7,13,50],[7,14,19],[7,15,8],[7,16,6],[7,17,3],[7,18,2],[7,19,4],[7,20,174],[8,0,220],[8,1,3],[8,2,40],[8,3,36],[8,4,6],[8,5,8],[8,6,1],[8,7,5],[8,8,0],[8,9,1],[8,10,61],[8,11,2],[8,12,43],[8,13,50],[8,14,17],[8,15,11],[8,16,4],[8,17,5],[8,18,1],[8,19,1],[8,20,183],[9,0,239],[9,1,1],[9,2,48],[9,3,37],[9,4,8],[9,5,12],[9,6,2],[9,7,0],[9,8,0],[9,9,0],[9,10,74],[9,11,1],[9,12,58],[9,13,53],[9,14,17],[9,15,13],[9,16,5],[9,17,2],[9,18,2],[9,19,0],[9,20,178],[10,0,249],[10,1,2],[10,2,40],[10,3,49],[10,4,12],[10,5,8],[10,6,0],[10,7,1],[10,8,0],[10,9,0],[10,10,58],[10,11,1],[10,12,54],[10,13,47],[10,14,21],[10,15,12],[10,16,6],[10,17,4],[10,18,3],[10,19,2],[10,20,165],[11,0,240],[11,1,1],[11,2,50],[11,3,47],[11,4,10],[11,5,2],[11,6,1],[11,7,1],[11,8,2],[11,9,1],[11,10,52],[11,11,4],[11,12,41],[11,13,51],[11,14,17],[11,15,6],[11,16,1],[11,17,6],[11,18,1],[11,19,0],[11,20,199],[12,0,240],[12,1,3],[12,2,40],[12,3,41],[12,4,17],[12,5,10],[12,6,5],[12,7,2],[12,8,2],[12,9,0],[12,10,86],[12,11,1],[12,12,56],[12,13,49],[12,14,16],[12,15,7],[12,16,4],[12,17,8],[12,18,4],[12,19,3],[12,20,157],[13,0,234],[13,1,1],[13,2,53],[13,3,38],[13,4,12],[13,5,4],[13,6,0],[13,7,2],[13,8,0],[13,9,0],[13,10,59],[13,11,2],[13,12,53],[13,13,48],[13,14,18],[13,15,8],[13,16,3],[13,17,8],[13,18,1],[13,19,1],[13,20,187],[14,0,269],[14,1,0],[14,2,66],[14,3,47],[14,4,17],[14,5,4],[14,6,1],[14,7,0],[14,8,0],[14,9,0],[14,10,55],[14,11,1],[14,12,53],[14,13,48],[14,14,18],[14,15,8],[14,16,3],[14,17,3],[14,18,4],[14,19,0],[14,20,179],[15,0,254],[15,1,0],[15,2,57],[15,3,45],[15,4,8],[15,5,9],[15,6,9],[15,7,4],[15,8,3],[15,9,0],[15,10,68],[15,11,1],[15,12,52],[15,13,51],[15,14,19],[15,15,7],[15,16,4],[15,17,0],[15,18,0],[15,19,1],[15,20,177],[16,0,257],[16,1,1],[16,2,65],[16,3,50],[16,4,16],[16,5,3],[16,6,1],[16,7,0],[16,8,0],[16,9,0],[16,10,61],[16,11,3],[16,12,63],[16,13,59],[16,14,14],[16,15,9],[16,16,5],[16,17,2],[16,18,0],[16,19,0],[16,20,174],[17,0,243],[17,1,1],[17,2,63],[17,3,44],[17,4,5],[17,5,3],[17,6,0],[17,7,3],[17,8,0],[17,9,0],[17,10,66],[17,11,4],[17,12,56],[17,13,38],[17,14,11],[17,15,10],[17,16,4],[17,17,2],[17,18,3],[17,19,0],[17,20,181],[18,0,236],[18,1,3],[18,2,38],[18,3,49],[18,4,16],[18,5,5],[18,6,3],[18,7,3],[18,8,1],[18,9,0],[18,10,41],[18,11,4],[18,12,59],[18,13,49],[18,14,13],[18,15,9],[18,16,4],[18,17,1],[18,18,2],[18,19,0],[18,20,192],[19,0,238],[19,1,2],[19,2,49],[19,3,37],[19,4,15],[19,5,2],[19,6,1],[19,7,1],[19,8,3],[19,9,0],[19,10,60],[19,11,3],[19,12,58],[19,13,53],[19,14,17],[19,15,4],[19,16,2],[19,17,2],[19,18,2],[19,19,0],[19,20,185],[20,0,242],[20,1,0],[20,2,55],[20,3,36],[20,4,10],[20,5,6],[20,6,1],[20,7,1],[20,8,1],[20,9,0],[20,10,57],[20,11,4],[20,12,46],[20,13,58],[20,14,15],[20,15,11],[20,16,3],[20,17,2],[20,18,7],[20,19,0],[20,20,188],[21,0,231],[21,1,3],[21,2,50],[21,3,43],[21,4,13],[21,5,1],[21,6,0],[21,7,1],[21,8,0],[21,9,0],[21,10,57],[21,11,3],[21,12,51],[21,13,36],[21,14,15],[21,15,8],[21,16,7],[21,17,2],[21,18,3],[21,19,1],[21,20,188],[22,0,241],[22,1,2],[22,2,60],[22,3,42],[22,4,11],[22,5,8],[22,6,0],[22,7,0],[22,8,0],[22,9,0],[22,10,56],[22,11,4],[22,12,57],[22,13,46],[22,14,20],[22,15,8],[22,16,6],[22,17,1],[22,18,1],[22,19,0],[22,20,191],[23,0,240],[23,1,0],[23,2,46],[23,3,44],[23,4,20],[23,5,3],[23,6,3],[23,7,4],[23,8,1],[23,9,1],[23,10,62],[23,11,4],[23,12,64],[23,13,44],[23,14,15],[23,15,3],[23,16,4],[23,17,2],[23,18,3],[23,19,1],[23,20,181],[24,0,255],[24,1,0],[24,2,61],[24,3,41],[24,4,17],[24,5,7],[24,6,0],[24,7,1],[24,8,0],[24,9,0],[24,10,60],[24,11,3],[24,12,62],[24,13,49],[24,14,17],[24,15,10],[24,16,3],[24,17,2],[24,18,3],[24,19,2],[24,20,177],[25,0,244],[25,1,1],[25,2,56],[25,3,35],[25,4,12],[25,5,12],[25,6,2],[25,7,1],[25,8,0],[25,9,0],[25,10,66],[25,11,3],[25,12,53],[25,13,55],[25,14,20],[25,15,13],[25,16,3],[25,17,1],[25,18,3],[25,19,2],[25,20,173],[26,0,234],[26,1,1],[26,2,45],[26,3,34],[26,4,9],[26,5,6],[26,6,0],[26,7,3],[26,8,0],[26,9,1],[26,10,54],[26,11,6],[26,12,59],[26,13,48],[26,14,20],[26,15,10],[26,16,1],[26,17,2],[26,18,2],[26,19,0],[26,20,182],[27,0,228],[27,1,1],[27,2,46],[27,3,35],[27,4,5],[27,5,7],[27,6,2],[27,7,3],[27,8,2],[27,9,3],[27,10,61],[27,11,2],[27,12,61],[27,13,43],[27,14,15],[27,15,7],[27,16,3],[27,17,1],[27,18,3],[27,19,1],[27,20,187],[28,0,248],[28,1,4],[28,2,60],[28,3,45],[28,4,11],[28,5,9],[28,6,5],[28,7,1],[28,8,1],[28,9,1],[28,10,58],[28,11,2],[28,12,53],[28,13,38],[28,14,20],[28,15,10],[28,16,4],[28,17,6],[28,18,1],[28,19,2],[28,20,178],[29,0,241],[29,1,2],[29,2,46],[29,3,28],[29,4,16],[29,5,8],[29,6,4],[29,7,2],[29,8,1],[29,9,0],[29,10,66],[29,11,3],[29,12,51],[29,13,51],[29,14,28],[29,15,9],[29,16,3],[29,17,4],[29,18,3],[29,19,4],[29,20,153],[30,0,151],[30,1,1],[30,2,26],[30,3,26],[30,4,8],[30,5,4],[30,6,2],[30,7,2],[30,8,3],[30,9,1],[30,10,32],[30,11,3],[30,12,33],[30,13,25],[30,14,10],[30,15,3],[30,16,1],[30,17,3],[30,18,2],[30,19,0],[30,20,82]],"axisYStep":0}
```
</details>
<details>
<summary>Automatically convert to server side timezone</summary>
if your backend nodes are deployed in docker and the timezone is UTC, you may not want to convert your timezone to UTC every time you type a command, `--timezone` comes to your rescue.
......
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package aggregation
import (
"fmt"
"strconv"
"strings"
"github.com/apache/skywalking-cli/commands/interceptor"
"github.com/urfave/cli"
"github.com/apache/skywalking-cli/commands/flags"
"github.com/apache/skywalking-cli/commands/model"
"github.com/apache/skywalking-cli/display"
"github.com/apache/skywalking-cli/graphql/aggregation"
"github.com/apache/skywalking-cli/graphql/schema"
)
var TopN = cli.Command{
Name: "top",
Usage: "query top `n` entities",
ArgsUsage: "<n>",
Flags: flags.Flags(
flags.DurationFlags,
[]cli.Flag{
cli.StringFlag{
Name: "name",
Usage: "`metrics name`, which should be defined in OAL script",
Required: true,
},
cli.GenericFlag{
Name: "order",
Usage: "the `order` by which the top entities are sorted",
Value: &model.OrderEnumValue{
Enum: schema.AllOrder,
Default: schema.OrderDes,
Selected: schema.OrderDes,
},
},
cli.StringFlag{
Name: "service-id",
Usage: "the `service id` whose instances/endpoints are to be fetch, if applicable",
Required: false,
},
},
),
Before: interceptor.BeforeChain([]cli.BeforeFunc{
interceptor.TimezoneInterceptor,
interceptor.DurationInterceptor,
}),
Action: func(ctx *cli.Context) error {
name := ctx.String("name")
start := ctx.String("start")
end := ctx.String("end")
step := ctx.Generic("step").(*model.StepEnumValue).Selected
order := ctx.Generic("order").(*model.OrderEnumValue).Selected
serviceID := ctx.String("service-id")
topN := 5
if ctx.NArg() > 0 {
nn, err := strconv.Atoi(ctx.Args().First())
if err != nil {
return fmt.Errorf("the 1st argument must be a number")
}
topN = nn
}
duration := schema.Duration{
Start: start,
End: end,
Step: step,
}
var metricsValues []schema.TopNEntity
if strings.HasPrefix(name, "service_instance") {
if serviceID == "" {
metricsValues = aggregation.AllServiceInstanceTopN(ctx, name, topN, duration, order)
} else {
metricsValues = aggregation.ServiceInstanceTopN(ctx, serviceID, name, topN, duration, order)
}
} else if strings.HasPrefix(name, "endpoint_") {
if serviceID == "" {
metricsValues = aggregation.AllEndpointTopN(ctx, name, topN, duration, order)
} else {
metricsValues = aggregation.EndpointTopN(ctx, serviceID, name, topN, duration, order)
}
} else if strings.HasPrefix(name, "service_") {
metricsValues = aggregation.ServiceTopN(ctx, name, topN, duration, order)
}
return display.Display(ctx, metricsValues)
},
}
......@@ -20,6 +20,10 @@ package metrics
import (
"github.com/urfave/cli"
"github.com/apache/skywalking-cli/commands/metrics/aggregation"
"github.com/apache/skywalking-cli/commands/metrics/thermodynamic"
"github.com/apache/skywalking-cli/commands/metrics/linear"
"github.com/apache/skywalking-cli/commands/metrics/single"
)
......@@ -31,5 +35,7 @@ var Command = cli.Command{
single.Command,
linear.Single,
linear.Multiple,
thermodynamic.Command,
aggregation.TopN,
},
}
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package thermodynamic
import (
"github.com/urfave/cli"
"github.com/apache/skywalking-cli/commands/flags"
"github.com/apache/skywalking-cli/commands/interceptor"
"github.com/apache/skywalking-cli/commands/model"
"github.com/apache/skywalking-cli/display"
"github.com/apache/skywalking-cli/graphql/metrics"
"github.com/apache/skywalking-cli/graphql/schema"
)
var Command = cli.Command{
Name: "thermodynamic",
ShortName: "td",
Usage: "Query thermodynamic metrics defined in backend OAL",
Flags: flags.Flags(
flags.DurationFlags,
[]cli.Flag{
cli.StringFlag{
Name: "name",
Usage: "metrics `NAME`, which should be defined in OAL script",
Required: true,
},
},
),
Before: interceptor.BeforeChain([]cli.BeforeFunc{
interceptor.TimezoneInterceptor,
interceptor.DurationInterceptor,
}),
Action: func(ctx *cli.Context) error {
end := ctx.String("end")
start := ctx.String("start")
step := ctx.Generic("step")
metricsName := ctx.String("name")
duration := schema.Duration{
Start: start,
End: end,
Step: step.(*model.StepEnumValue).Selected,
}
metricsValues := metrics.Thermodynamic(ctx, schema.MetricCondition{
Name: metricsName,
}, duration)
return display.Display(ctx, metricsValues)
},
}
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package model
import (
"fmt"
"strings"
"github.com/apache/skywalking-cli/graphql/schema"
)
// OrderEnumValue defines the values domain of --order option
type OrderEnumValue struct {
Enum []schema.Order
Default schema.Order
Selected schema.Order
}
// Set the --order value, from raw string to OrderEnumValue
func (s *OrderEnumValue) Set(value string) error {
for _, enum := range s.Enum {
if strings.EqualFold(enum.String(), value) {
s.Selected = enum
return nil
}
}
orders := make([]string, len(schema.AllOrder))
for i, order := range schema.AllOrder {
orders[i] = order.String()
}
return fmt.Errorf("allowed orders are %s", strings.Join(orders, ", "))
}
// String representation of the order
func (s OrderEnumValue) String() string {
return s.Selected.String()
}
......@@ -34,7 +34,7 @@ type StepEnumValue struct {
// Set the --step value, from raw string to StepEnumValue
func (s *StepEnumValue) Set(value string) error {
for _, enum := range s.Enum {
if enum.String() == value {
if strings.EqualFold(enum.String(), value) {
s.Selected = enum
return nil
}
......
// Licensed to Apache Software Foundation (ASF) under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Apache Software Foundation (ASF) licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package aggregation
import (
"github.com/machinebox/graphql"
"github.com/urfave/cli"
"github.com/apache/skywalking-cli/graphql/client"
"github.com/apache/skywalking-cli/graphql/schema"
)
func ServiceTopN(ctx *cli.Context, name string, topN int, duration schema.Duration, order schema.Order) []schema.TopNEntity {
var response map[string][]schema.TopNEntity
request := graphql.NewRequest(`
query ($name: String!, $topN: Int!, $duration: Duration!, $order: Order!) {
result: getServiceTopN(
duration: $duration,
name: $name,
topN: $topN,
order: $order
) {
id name value
}
}
`)
request.Var("name", name)
request.Var("topN", topN)
request.Var("duration", duration)
request.Var("order", order)
client.ExecuteQueryOrFail(ctx, request, &response)
return response["result"]
}
func AllServiceInstanceTopN(ctx *cli.Context, name string, topN int, duration schema.Duration, order schema.Order) []schema.TopNEntity {
var response map[string][]schema.TopNEntity
request := graphql.NewRequest(`
query ($name: String!, $topN: Int!, $duration: Duration!, $order: Order!) {
result: getAllServiceInstanceTopN(
duration: $duration,
name: $name,
topN: $topN,
order: $order
) {
id name value
}
}
`)
request.Var("name", name)
request.Var("topN", topN)
request.Var("duration", duration)
request.Var("order", order)
client.ExecuteQueryOrFail(ctx, request, &response)
return response["result"]
}
func ServiceInstanceTopN(ctx *cli.Context, serviceID, name string, topN int, duration schema.Duration, order schema.Order) []schema.TopNEntity {
var response map[string][]schema.TopNEntity
request := graphql.NewRequest(`
query ($serviceId: ID!, $name: String!, $topN: Int!, $duration: Duration!, $order: Order!) {
result: getServiceInstanceTopN(
serviceId: $serviceId,
duration: $duration,
name: $name,
topN: $topN,
order: $order
) {
id name value
}
}
`)
request.Var("serviceId", serviceID)
request.Var("name", name)
request.Var("topN", topN)
request.Var("duration", duration)
request.Var("order", order)
client.ExecuteQueryOrFail(ctx, request, &response)
return response["result"]
}
func AllEndpointTopN(ctx *cli.Context, name string, topN int, duration schema.Duration, order schema.Order) []schema.TopNEntity {
var response map[string][]schema.TopNEntity
request := graphql.NewRequest(`
query ($name: String!, $topN: Int!, $duration: Duration!, $order: Order!) {
result: getAllEndpointTopN(
duration: $duration,
name: $name,
topN: $topN,
order: $order
) {
id name value
}
}
`)
request.Var("name", name)
request.Var("topN", topN)
request.Var("duration", duration)
request.Var("order", order)
client.ExecuteQueryOrFail(ctx, request, &response)
return response["result"]
}
func EndpointTopN(ctx *cli.Context, serviceID, name string, topN int, duration schema.Duration, order schema.Order) []schema.TopNEntity {
var response map[string][]schema.TopNEntity
request := graphql.NewRequest(`
query ($serviceId: ID!, $name: String!, $topN: Int!, $duration: Duration!, $order: Order!) {
result: getEndpointTopN(
serviceId: $serviceId,
duration: $duration,
name: $name,
topN: $topN,
order: $order
) {
id name value
}
}
`)
request.Var("serviceId", serviceID)
request.Var("name", name)
request.Var("topN", topN)
request.Var("duration", duration)
request.Var("order", order)
client.ExecuteQueryOrFail(ctx, request, &response)
return response["result"]
}
......@@ -80,3 +80,21 @@ func MultipleLinearIntValues(ctx *cli.Context, condition schema.MetricCondition,
return response["metrics"]
}
func Thermodynamic(ctx *cli.Context, condition schema.MetricCondition, duration schema.Duration) schema.Thermodynamic {
request := graphql.NewRequest(`
query ($metric: MetricCondition!, $duration: Duration!) {
metrics: getThermodynamic(metric: $metric, duration: $duration) {
nodes responseTimeStep: axisYStep
}
}
`)
request.Var("metric", condition)
request.Var("duration", duration)
var response map[string]schema.Thermodynamic
client.ExecuteQueryOrFail(ctx, request, &response)
return response["metrics"]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册