Add flags of instance, endpoint and normal for metrics command (#76)
* Fix outdated doc
Co-authored-by: kezhenxu94 <kezhenxu94@163.com>
diff --git a/README.md b/README.md
index 57a4a3a..1b51908 100644
--- a/README.md
+++ b/README.md
@@ -160,12 +160,15 @@
<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) |
@@ -175,13 +178,16 @@
<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) |
@@ -191,12 +197,15 @@
<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) |
@@ -206,7 +215,7 @@
<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 |
| :--- | :--- | :--- |
@@ -214,6 +223,7 @@
| `--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) |
@@ -389,7 +399,7 @@
<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 "5ca1e1be91064db6880abac4648667ff@192.168.252.13"
```
![](http://skywalking.apache.org/screenshots/cli/metrics-linear.png)
@@ -407,19 +417,34 @@
<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>
diff --git a/commands/flags/metrics.go b/commands/flags/metrics.go
index b1bcfb2..151c4ae 100644
--- a/commands/flags/metrics.go
+++ b/commands/flags/metrics.go
@@ -34,4 +34,21 @@
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,
+ },
}
diff --git a/commands/interceptor/scope.go b/commands/interceptor/scope.go
index d7c84e8..6ecd7bc 100644
--- a/commands/interceptor/scope.go
+++ b/commands/interceptor/scope.go
@@ -33,7 +33,7 @@
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
diff --git a/commands/metrics/aggregation/topn.go b/commands/metrics/aggregation/topn.go
index 183ec05..0745691 100644
--- a/commands/metrics/aggregation/topn.go
+++ b/commands/metrics/aggregation/topn.go
@@ -61,7 +61,7 @@
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
diff --git a/commands/metrics/linear/linear-metrics.go b/commands/metrics/linear/linear-metrics.go
index a684781..36711c3 100644
--- a/commands/metrics/linear/linear-metrics.go
+++ b/commands/metrics/linear/linear-metrics.go
@@ -50,7 +50,9 @@
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 == "" {
@@ -72,7 +74,8 @@
Scope: scope,
ServiceName: &serviceName,
Normal: &normal,
- ServiceInstanceName: &serviceName,
+ ServiceInstanceName: &instanceName,
+ EndpointName: &endpointName,
},
}, duration)
diff --git a/commands/metrics/linear/multiple-linear-metrics.go b/commands/metrics/linear/multiple-linear-metrics.go
index 9c8bd3b..e9ded0d 100644
--- a/commands/metrics/linear/multiple-linear-metrics.go
+++ b/commands/metrics/linear/multiple-linear-metrics.go
@@ -19,6 +19,7 @@
import (
"fmt"
+ "strings"
"github.com/apache/skywalking-cli/commands/flags"
"github.com/apache/skywalking-cli/commands/interceptor"
@@ -39,11 +40,11 @@
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",
},
},
),
@@ -58,23 +59,16 @@
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,
@@ -84,11 +78,13 @@
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})
diff --git a/commands/metrics/list/list-metrics.go b/commands/metrics/list/list-metrics.go
index f163fb7..8b22349 100644
--- a/commands/metrics/list/list-metrics.go
+++ b/commands/metrics/list/list-metrics.go
@@ -26,8 +26,9 @@
)
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",
diff --git a/commands/metrics/single/single-metrics.go b/commands/metrics/single/single-metrics.go
index 2d92cca..d407fa4 100644
--- a/commands/metrics/single/single-metrics.go
+++ b/commands/metrics/single/single-metrics.go
@@ -49,7 +49,9 @@
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 == "" {
@@ -68,9 +70,11 @@
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)
diff --git a/docs/How-to-release.md b/docs/How-to-release.md
index 6980e71..db56647 100644
--- a/docs/How-to-release.md
+++ b/docs/How-to-release.md
@@ -215,11 +215,9 @@
Website: http://skywalking.apache.org/
SkyWalking CLI Resources:
-- Issue: https://github.com/apache/skywalking/issues
+ - Issue: https://github.com/apache/skywalking/issues
- Mailing list: dev@skywalking.apache.org
- Documents: https://github.com/apache/skywalking-cli/blob/$VERSION/README.md
The Apache SkyWalking Team
-```
-
-
+ ```