Skip to content

Commit

Permalink
Add flags of instance, endpoint and normal for metrics command (#76)
Browse files Browse the repository at this point in the history
* Fix outdated doc

Co-authored-by: kezhenxu94 <[email protected]>
  • Loading branch information
fgksgf and kezhenxu94 authored Nov 25, 2020
1 parent 88b1874 commit ffee47d
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 44 deletions.
47 changes: 36 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,15 @@ Ascii Graph, like coloring in terminal, so please use `json` or `yaml` instead.

<details>

<summary>metrics linear [--start=start-time] [--end=end-time] --name=metrics-name --service=service-name</summary>
<summary>metrics linear [--start=start-time] [--end=end-time] --name=metrics-name --service=service-name [--instance=instance-name] [--endpoint=endpoint-name] [--isNormal=true/false]</summary>

| option | description | default |
| :--- | :--- | :--- |
| `--name` | Metrics name, defined in [OAL](https://github.com/apache/skywalking/blob/master/oap-server/server-bootstrap/src/main/resources/oal/core.oal). |
| `--service` | The name of the service. | "" |
| `--instance` | The name of the service instance. | "" |
| `--endpoint` | The name of the endpoint. | "" |
| `--isNormal` | Set the service to normal or unnormal. | `true` |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |

Expand All @@ -175,13 +178,16 @@ Ascii Graph, like coloring in terminal, so please use `json` or `yaml` instead.

<details>

<summary>metrics multiple-linear [--start=start-time] [--end=end-time] --name=metrics-name [--service=service-name] [--num=number-of-linear-metrics]</summary>
<summary>metrics multiple-linear [--start=start-time] [--end=end-time] --name=metrics-name [--service=service-name] [--num=number-of-linear-metrics] [--instance=instance-name] [--endpoint=endpoint-name] [--isNormal=true/false]</summary>

| option | description | default |
| :--- | :--- | :--- |
| `--name` | Metrics name that ends with `_percentile`, defined in [OAL](https://github.com/apache/skywalking/blob/master/oap-server/server-bootstrap/src/main/resources/oal/core.oal), such as `all_percentile`, etc. |
| `--service` | The name of the service, when scope is `All`, no name is required. | "" |
| `--num` | Number of the linear metrics to fetch | `5` |
| `--labels` | The labels you need to query | `0,1,2,3,4` |
| `--instance` | The name of the service instance. | "" |
| `--endpoint` | The name of the endpoint. | "" |
| `--isNormal` | Set the service to normal or unnormal. | `true` |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |

Expand All @@ -191,12 +197,15 @@ Ascii Graph, like coloring in terminal, so please use `json` or `yaml` instead.

<details>

<summary>metrics single [--start=start-time] [--end=end-time] --name=metrics-name --service=service-name</summary>
<summary>metrics single [--start=start-time] [--end=end-time] --name=metrics-name --service=service-name [--instance=instance-name] [--endpoint=endpoint-name] [--isNormal=true/false]</summary>

| option | description | default |
| :--- | :--- | :--- |
| `--name` | Metrics name, defined in [OAL](https://github.com/apache/skywalking/blob/master/oap-server/server-bootstrap/src/main/resources/oal/core.oal), such as `service_sla`, etc. |
| `--service` | The name of the service. | "" |
| `--instance` | The name of the service instance. | "" |
| `--endpoint` | The name of the endpoint. | "" |
| `--isNormal` | Set the service to normal or unnormal. | `true` |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |

Expand All @@ -206,14 +215,15 @@ Ascii Graph, like coloring in terminal, so please use `json` or `yaml` instead.

<details>

<summary>metrics top 5 [--start=start-time] [--end=end-time] --name=metrics-name [--service=parent-service] [--order=DES]</summary>
<summary>metrics top 5 [--start=start-time] [--end=end-time] --name=metrics-name [--service=parent-service] [--order=DES] [--isNormal=true/false]</summary>

| option | description | default |
| :--- | :--- | :--- |
| arguments | The first argument is the number of top entities | `5` |
| `--name` | Metrics name, defined in [OAL](https://github.com/apache/skywalking/blob/master/oap-server/server-bootstrap/src/main/resources/oal/core.oal), such as `service_sla`, etc. |
| `--service` | The name of the parent service, could be null if query the global top N. | "" |
| `--order` | The order of metrics, `DES` or `ASC`. |`DES`|
| `--isNormal` | Set the service to normal or unnormal. | `true` |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |

Expand Down Expand Up @@ -389,7 +399,7 @@ otherwise,
<summary>Query a linear metrics graph for an instance</summary>

```shell
$ ./bin/swctl --display=graph metrics linear --name=service_instance_resp_time --service "load balancer1.system"
$ ./bin/swctl --display=graph metrics linear --name=service_instance_resp_time --service "projectC.business-zone" --instance "[email protected]"
```

![](http://skywalking.apache.org/screenshots/cli/metrics-linear.png)
Expand All @@ -407,19 +417,34 @@ $ ./bin/swctl instance ls --service-name=projectC | jq '.[] | select(.name == "p
<summary>Query a single metrics value for a specific endpoint</summary>

```shell
$ ./bin/swctl service ls projectC | jq '.[0].id' | xargs ./bin/swctl endpoint ls --service-id | jq '.[] | [.id] | join(",")' | xargs ./bin/swctl metrics single --name endpoint_cpm --ids
[{"id":"22","value":116}]
export SERVICE_NAME=projectC.business-zone
export ENDPOINT=/projectC/{value}
export METRICS_NAME=endpoint_cpm
./bin/swctl metrics single --name ${METRICS_NAME} --service ${SERVICE_NAME} --endpoint ${ENDPOINT}
```

Result:

```
23
```

</details>

<details>

<summary>Query metrics single values for all endpoints of service of id 3</summary>
<summary>Query metrics single values for all endpoints of service `projectC.business-zone`</summary>

```shell
$ ./bin/swctl service ls projectC | jq '.[0].id' | xargs ./bin/swctl endpoint ls --service-id | jq '.[] | [.id] | join(",")' | xargs ./bin/swctl metrics single --name endpoint_cpm --end='2019-12-02 2137' --ids
[{"id":"3","value":116}]
export SERVICE_NAME=projectC.business-zone
export METRICS_NAME=endpoint_cpm
./bin/swctl endpoint ls --service-id=$(./bin/swctl service ls "$SERVICE_NAME" | jq -r '.[0].id') | jq -r '.[].name' | xargs ./bin/swctl metrics single --name "${METRICS_NAME}" --service "${SERVICE_NAME}" --endpoint
```

Result:

```
23
```

</details>
Expand Down
17 changes: 17 additions & 0 deletions commands/flags/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,21 @@ var MetricsFlags = []cli.Flag{
Value: "",
Required: false,
},
cli.StringFlag{
Name: "instance",
Usage: "the name of service instance",
Value: "",
Required: false,
},
cli.StringFlag{
Name: "endpoint",
Usage: "the name of endpoint",
Value: "",
Required: false,
},
cli.BoolTFlag{
Name: "isNormal",
Usage: "set the service to normal or unnormal",
Required: false,
},
}
2 changes: 1 addition & 1 deletion commands/interceptor/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ParseScope(name string) schema.Scope {
ret = schema.ScopeServiceInstanceRelation
} else if strings.HasPrefix(name, "service_instance") {
ret = schema.ScopeServiceInstance
} else if strings.HasPrefix(name, "service_") {
} else if strings.HasPrefix(name, "service_") || strings.HasPrefix(name, "database_") {
ret = schema.ScopeService
} else if strings.HasPrefix(name, "endpoint_relation") {
ret = schema.ScopeEndpointRelation
Expand Down
2 changes: 1 addition & 1 deletion commands/metrics/aggregation/topn.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var TopN = cli.Command{
step := ctx.Generic("step").(*model.StepEnumValue).Selected

metricsName := ctx.String("name")
normal := true
normal := ctx.BoolT("isNormal")
scope := interceptor.ParseScope(metricsName)
order := ctx.Generic("order").(*model.OrderEnumValue).Selected
topN := 5
Expand Down
7 changes: 5 additions & 2 deletions commands/metrics/linear/linear-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ var Single = cli.Command{

metricsName := ctx.String("name")
serviceName := ctx.String("service")
normal := true
normal := ctx.BoolT("isNormal")
instanceName := ctx.String("instance")
endpointName := ctx.String("endpoint")
scope := interceptor.ParseScope(metricsName)

if serviceName == "" {
Expand All @@ -72,7 +74,8 @@ var Single = cli.Command{
Scope: scope,
ServiceName: &serviceName,
Normal: &normal,
ServiceInstanceName: &serviceName,
ServiceInstanceName: &instanceName,
EndpointName: &endpointName,
},
}, duration)

Expand Down
34 changes: 15 additions & 19 deletions commands/metrics/linear/multiple-linear-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package linear

import (
"fmt"
"strings"

"github.com/apache/skywalking-cli/commands/flags"
"github.com/apache/skywalking-cli/commands/interceptor"
Expand All @@ -39,11 +40,11 @@ var Multiple = cli.Command{
flags.DurationFlags,
flags.MetricsFlags,
[]cli.Flag{
cli.IntFlag{
Name: "num",
Usage: "`num`, the number of linear metrics to query, (default: 5)",
cli.StringFlag{
Name: "labels",
Usage: "the labels you need to query",
Required: false,
Value: 5,
Value: "0,1,2,3,4",
},
},
),
Expand All @@ -58,23 +59,16 @@ var Multiple = cli.Command{

metricsName := ctx.String("name")
serviceName := ctx.String("service")
normal := true
numOfLinear := ctx.Int("num")
normal := ctx.BoolT("isNormal")
instanceName := ctx.String("instance")
endpointName := ctx.String("endpoint")
labels := ctx.String("labels")
scope := interceptor.ParseScope(metricsName)

if serviceName == "" && scope != schema.ScopeAll {
return fmt.Errorf("the name of service should be specified when metrics' scope is not `All`")
}

if numOfLinear > 5 || numOfLinear < 1 {
numOfLinear = 5
}

var labels []string
for i := 0; i < numOfLinear; i++ {
labels = append(labels, fmt.Sprintf("%d", i))
}

duration := schema.Duration{
Start: start,
End: end,
Expand All @@ -84,11 +78,13 @@ var Multiple = cli.Command{
metricsValuesArray := metrics.MultipleLinearIntValues(ctx, schema.MetricsCondition{
Name: metricsName,
Entity: &schema.Entity{
Scope: scope,
ServiceName: &serviceName,
Normal: &normal,
Scope: scope,
ServiceName: &serviceName,
Normal: &normal,
ServiceInstanceName: &instanceName,
EndpointName: &endpointName,
},
}, labels, duration)
}, strings.Split(labels, ","), duration)

reshaped := utils.MetricsValuesArrayToMap(duration, metricsValuesArray)
return display.Display(ctx, &displayable.Displayable{Data: reshaped})
Expand Down
5 changes: 3 additions & 2 deletions commands/metrics/list/list-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (
)

var Command = cli.Command{
Name: "list",
Usage: "List metrics that could be queried",
Name: "list",
ShortName: "ls",
Usage: "List metrics that could be queried",
Flags: []cli.Flag{
cli.StringFlag{
Name: "regex",
Expand Down
12 changes: 8 additions & 4 deletions commands/metrics/single/single-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ var Command = cli.Command{

metricsName := ctx.String("name")
serviceName := ctx.String("service")
normal := true
normal := ctx.BoolT("isNormal")
instanceName := ctx.String("instance")
endpointName := ctx.String("endpoint")
scope := interceptor.ParseScope(metricsName)

if serviceName == "" {
Expand All @@ -68,9 +70,11 @@ var Command = cli.Command{
metricsValue := metrics.IntValues(ctx, schema.MetricsCondition{
Name: metricsName,
Entity: &schema.Entity{
Scope: scope,
ServiceName: &serviceName,
Normal: &normal,
Scope: scope,
ServiceName: &serviceName,
Normal: &normal,
ServiceInstanceName: &instanceName,
EndpointName: &endpointName,
},
}, duration)

Expand Down
6 changes: 2 additions & 4 deletions docs/How-to-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,9 @@ Vote result should follow these:
Website: http://skywalking.apache.org/

SkyWalking CLI Resources:
- Issue: https://github.com/apache/skywalking/issues
- Issue: https://github.com/apache/skywalking/issues
- Mailing list: [email protected]
- Documents: https://github.com/apache/skywalking-cli/blob/$VERSION/README.md

The Apache SkyWalking Team
```


```

0 comments on commit ffee47d

Please sign in to comment.