Skip to content

Commit ffee47d

Browse files
fgksgfkezhenxu94
andauthored
Add flags of instance, endpoint and normal for metrics command (#76)
* Fix outdated doc Co-authored-by: kezhenxu94 <kezhenxu94@163.com>
1 parent 88b1874 commit ffee47d

File tree

9 files changed

+88
-44
lines changed

9 files changed

+88
-44
lines changed

README.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,15 @@ Ascii Graph, like coloring in terminal, so please use `json` or `yaml` instead.
160160

161161
<details>
162162

163-
<summary>metrics linear [--start=start-time] [--end=end-time] --name=metrics-name --service=service-name</summary>
163+
<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>
164164

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

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

176179
<details>
177180

178-
<summary>metrics multiple-linear [--start=start-time] [--end=end-time] --name=metrics-name [--service=service-name] [--num=number-of-linear-metrics]</summary>
181+
<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>
179182

180183
| option | description | default |
181184
| :--- | :--- | :--- |
182185
| `--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. |
183186
| `--service` | The name of the service, when scope is `All`, no name is required. | "" |
184-
| `--num` | Number of the linear metrics to fetch | `5` |
187+
| `--labels` | The labels you need to query | `0,1,2,3,4` |
188+
| `--instance` | The name of the service instance. | "" |
189+
| `--endpoint` | The name of the endpoint. | "" |
190+
| `--isNormal` | Set the service to normal or unnormal. | `true` |
185191
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
186192
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |
187193

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

192198
<details>
193199

194-
<summary>metrics single [--start=start-time] [--end=end-time] --name=metrics-name --service=service-name</summary>
200+
<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>
195201

196202
| option | description | default |
197203
| :--- | :--- | :--- |
198204
| `--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. |
199205
| `--service` | The name of the service. | "" |
206+
| `--instance` | The name of the service instance. | "" |
207+
| `--endpoint` | The name of the endpoint. | "" |
208+
| `--isNormal` | Set the service to normal or unnormal. | `true` |
200209
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
201210
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |
202211

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

207216
<details>
208217

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

211220
| option | description | default |
212221
| :--- | :--- | :--- |
213222
| arguments | The first argument is the number of top entities | `5` |
214223
| `--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. |
215224
| `--service` | The name of the parent service, could be null if query the global top N. | "" |
216225
| `--order` | The order of metrics, `DES` or `ASC`. |`DES`|
226+
| `--isNormal` | Set the service to normal or unnormal. | `true` |
217227
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
218228
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |
219229

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

391401
```shell
392-
$ ./bin/swctl --display=graph metrics linear --name=service_instance_resp_time --service "load balancer1.system"
402+
$ ./bin/swctl --display=graph metrics linear --name=service_instance_resp_time --service "projectC.business-zone" --instance "5ca1e1be91064db6880abac4648667ff@192.168.252.13"
393403
```
394404

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

409419
```shell
410-
$ ./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
411-
[{"id":"22","value":116}]
420+
export SERVICE_NAME=projectC.business-zone
421+
export ENDPOINT=/projectC/{value}
422+
export METRICS_NAME=endpoint_cpm
423+
./bin/swctl metrics single --name ${METRICS_NAME} --service ${SERVICE_NAME} --endpoint ${ENDPOINT}
424+
```
425+
426+
Result:
427+
428+
```
429+
23
412430
```
413431

414432
</details>
415433

416434
<details>
417435

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

420438
```shell
421-
$ ./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
422-
[{"id":"3","value":116}]
439+
export SERVICE_NAME=projectC.business-zone
440+
export METRICS_NAME=endpoint_cpm
441+
./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
442+
```
443+
444+
Result:
445+
446+
```
447+
23
423448
```
424449

425450
</details>

commands/flags/metrics.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,21 @@ var MetricsFlags = []cli.Flag{
3434
Value: "",
3535
Required: false,
3636
},
37+
cli.StringFlag{
38+
Name: "instance",
39+
Usage: "the name of service instance",
40+
Value: "",
41+
Required: false,
42+
},
43+
cli.StringFlag{
44+
Name: "endpoint",
45+
Usage: "the name of endpoint",
46+
Value: "",
47+
Required: false,
48+
},
49+
cli.BoolTFlag{
50+
Name: "isNormal",
51+
Usage: "set the service to normal or unnormal",
52+
Required: false,
53+
},
3754
}

commands/interceptor/scope.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func ParseScope(name string) schema.Scope {
3333
ret = schema.ScopeServiceInstanceRelation
3434
} else if strings.HasPrefix(name, "service_instance") {
3535
ret = schema.ScopeServiceInstance
36-
} else if strings.HasPrefix(name, "service_") {
36+
} else if strings.HasPrefix(name, "service_") || strings.HasPrefix(name, "database_") {
3737
ret = schema.ScopeService
3838
} else if strings.HasPrefix(name, "endpoint_relation") {
3939
ret = schema.ScopeEndpointRelation

commands/metrics/aggregation/topn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var TopN = cli.Command{
6161
step := ctx.Generic("step").(*model.StepEnumValue).Selected
6262

6363
metricsName := ctx.String("name")
64-
normal := true
64+
normal := ctx.BoolT("isNormal")
6565
scope := interceptor.ParseScope(metricsName)
6666
order := ctx.Generic("order").(*model.OrderEnumValue).Selected
6767
topN := 5

commands/metrics/linear/linear-metrics.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ var Single = cli.Command{
5050

5151
metricsName := ctx.String("name")
5252
serviceName := ctx.String("service")
53-
normal := true
53+
normal := ctx.BoolT("isNormal")
54+
instanceName := ctx.String("instance")
55+
endpointName := ctx.String("endpoint")
5456
scope := interceptor.ParseScope(metricsName)
5557

5658
if serviceName == "" {
@@ -72,7 +74,8 @@ var Single = cli.Command{
7274
Scope: scope,
7375
ServiceName: &serviceName,
7476
Normal: &normal,
75-
ServiceInstanceName: &serviceName,
77+
ServiceInstanceName: &instanceName,
78+
EndpointName: &endpointName,
7679
},
7780
}, duration)
7881

commands/metrics/linear/multiple-linear-metrics.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package linear
1919

2020
import (
2121
"fmt"
22+
"strings"
2223

2324
"github.com/apache/skywalking-cli/commands/flags"
2425
"github.com/apache/skywalking-cli/commands/interceptor"
@@ -39,11 +40,11 @@ var Multiple = cli.Command{
3940
flags.DurationFlags,
4041
flags.MetricsFlags,
4142
[]cli.Flag{
42-
cli.IntFlag{
43-
Name: "num",
44-
Usage: "`num`, the number of linear metrics to query, (default: 5)",
43+
cli.StringFlag{
44+
Name: "labels",
45+
Usage: "the labels you need to query",
4546
Required: false,
46-
Value: 5,
47+
Value: "0,1,2,3,4",
4748
},
4849
},
4950
),
@@ -58,23 +59,16 @@ var Multiple = cli.Command{
5859

5960
metricsName := ctx.String("name")
6061
serviceName := ctx.String("service")
61-
normal := true
62-
numOfLinear := ctx.Int("num")
62+
normal := ctx.BoolT("isNormal")
63+
instanceName := ctx.String("instance")
64+
endpointName := ctx.String("endpoint")
65+
labels := ctx.String("labels")
6366
scope := interceptor.ParseScope(metricsName)
6467

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

69-
if numOfLinear > 5 || numOfLinear < 1 {
70-
numOfLinear = 5
71-
}
72-
73-
var labels []string
74-
for i := 0; i < numOfLinear; i++ {
75-
labels = append(labels, fmt.Sprintf("%d", i))
76-
}
77-
7872
duration := schema.Duration{
7973
Start: start,
8074
End: end,
@@ -84,11 +78,13 @@ var Multiple = cli.Command{
8478
metricsValuesArray := metrics.MultipleLinearIntValues(ctx, schema.MetricsCondition{
8579
Name: metricsName,
8680
Entity: &schema.Entity{
87-
Scope: scope,
88-
ServiceName: &serviceName,
89-
Normal: &normal,
81+
Scope: scope,
82+
ServiceName: &serviceName,
83+
Normal: &normal,
84+
ServiceInstanceName: &instanceName,
85+
EndpointName: &endpointName,
9086
},
91-
}, labels, duration)
87+
}, strings.Split(labels, ","), duration)
9288

9389
reshaped := utils.MetricsValuesArrayToMap(duration, metricsValuesArray)
9490
return display.Display(ctx, &displayable.Displayable{Data: reshaped})

commands/metrics/list/list-metrics.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import (
2626
)
2727

2828
var Command = cli.Command{
29-
Name: "list",
30-
Usage: "List metrics that could be queried",
29+
Name: "list",
30+
ShortName: "ls",
31+
Usage: "List metrics that could be queried",
3132
Flags: []cli.Flag{
3233
cli.StringFlag{
3334
Name: "regex",

commands/metrics/single/single-metrics.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ var Command = cli.Command{
4949

5050
metricsName := ctx.String("name")
5151
serviceName := ctx.String("service")
52-
normal := true
52+
normal := ctx.BoolT("isNormal")
53+
instanceName := ctx.String("instance")
54+
endpointName := ctx.String("endpoint")
5355
scope := interceptor.ParseScope(metricsName)
5456

5557
if serviceName == "" {
@@ -68,9 +70,11 @@ var Command = cli.Command{
6870
metricsValue := metrics.IntValues(ctx, schema.MetricsCondition{
6971
Name: metricsName,
7072
Entity: &schema.Entity{
71-
Scope: scope,
72-
ServiceName: &serviceName,
73-
Normal: &normal,
73+
Scope: scope,
74+
ServiceName: &serviceName,
75+
Normal: &normal,
76+
ServiceInstanceName: &instanceName,
77+
EndpointName: &endpointName,
7478
},
7579
}, duration)
7680

docs/How-to-release.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,9 @@ Vote result should follow these:
215215
Website: http://skywalking.apache.org/
216216

217217
SkyWalking CLI Resources:
218-
- Issue: https://github.com/apache/skywalking/issues
218+
- Issue: https://github.com/apache/skywalking/issues
219219
- Mailing list: dev@skywalking.apache.org
220220
- Documents: https://github.com/apache/skywalking-cli/blob/$VERSION/README.md
221221

222222
The Apache SkyWalking Team
223-
```
224-
225-
223+
```

0 commit comments

Comments
 (0)