Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
314 changes: 8 additions & 306 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Apache SkyWalking CLI
![](https://github.com/apache/skywalking-cli/workflows/Build/badge.svg?branch=master)
![](https://codecov.io/gh/apache/skywalking-cli/branch/master/graph/badge.svg)

<img src="http://skywalking.apache.org/assets/logo.svg" alt="Sky Walking logo" height="90px" align="right" />
<img src="https://skywalking.apache.org/assets/logo.svg" alt="Sky Walking logo" height="90px" align="right" />

The CLI (Command Line Interface) for [Apache SkyWalking](https://github.com/apache/skywalking).

Expand Down Expand Up @@ -103,314 +103,16 @@ command to create `$profile` file:
New-Item -Type file -Force $profile
```

After reloading your shell, swctl auto-completion should be working.

### `metrics`

#### `metrics linear`

<details>

<summary>metrics linear [--start=start-time] [--end=end-time] --name=metrics-name [--service=service-name] [--instance=instance-name] [--endpoint=endpoint-name] [--destService=dest-service-name] [--destInstance=dest-instance-name] [--destEndpoint=dest-endpoint-name] [--isDestNormal=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. | "" |
| `--destService` | The name of the destination service. | "" |
| `--destInstance` | The name of the destination instance. | "" |
| `--destEndpoint` | The name of the destination endpoint. | "" |
| `--isDestNormal` | Set the destination 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) |

</details>

#### `metrics multiple-linear`

<details>

<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] [--destService=dest-service-name] [--destInstance=dest-instance-name] [--destEndpoint=dest-endpoint-name] [--isDestNormal=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. | "" |
| `--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` |
| `--destService` | The name of the destination service. | "" |
| `--destInstance` | The name of the destination instance. | "" |
| `--destEndpoint` | The name of the destination endpoint. | "" |
| `--isDestNormal` | Set the destination 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) |

</details>

#### `metrics single`

<details>

<summary>metrics single [--start=start-time] [--end=end-time] --name=metrics-name --service=service-name [--instance=instance-name] [--endpoint=endpoint-name] [--isNormal=true/false] [--destService=dest-service-name] [--destInstance=dest-instance-name] [--destEndpoint=dest-endpoint-name] [--isDestNormal=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` |
| `--destService` | The name of the destination service. | "" |
| `--destInstance` | The name of the destination instance. | "" |
| `--destEndpoint` | The name of the destination endpoint. | "" |
| `--isDestNormal` | Set the destination 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) |

</details>

### `dashboard`

#### `dashboard global-metrics`

<details>

<summary>dashboard global-metrics [--template=template]</summary>

`dashboard global-metrics` displays global metrics in the form of a dashboard.

| argument | description | default |
| :--- | :--- | :--- |
| `--template` | The template file to customize how to display information | `templates/Dashboard.Global.json` |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |

You can imitate the content of [the default template file](examples/global.yml) to customize the dashboard.

</details>

#### `dashboard global`

<details>

<summary>dashboard global [--template=template]</summary>

`dashboard global` displays global metrics, global response latency and global heat map in the form of a dashboard.

| argument | description | default |
| :--- | :--- | :--- |
| `--template` | The template file to customize how to display information | `templates/dashboard/global.yml` |
| `--refresh` | The interval of auto-refresh (s). When `start` and `end` are both present, auto-refresh is disabled. | `6` |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |

You can imitate the content of [the default template file](examples/global.yml) to customize the dashboard.

</details>

### `install`

#### `manifest`

<details>

<summary>install manifest oap|ui [--name=string] [--namespace=string] [-f=filepath/-]</summary>

| argument | description | default |
| :--- | :--- | :--- |
| `--name` | The name of prefix of generated resources | `skywalking` |
| `--namespace` | The namespace where resource will be deployed | `skywalking-system` |
| `-f` | The custom resource file describing custom resources defined by swck | |

</details>

### `event`

#### `report`

<details>

<summary>event report [--uuid=uuid] [--service=service] [--name=name] [--message=message] [--startTime=startTime] [--endTime=endTime] [--instance=instance] [--endpoint=endpoint] [--type=type] [parameters...]</summary>

`event report` reports an event to OAP server via gRPC.

| argument | description | default |
| :--- | :--- | :--- |
| `uuid` | The unique ID of the event. | |
| `service` | The service of the event occurred on. | |
| `instance` | The service instance of the event occurred on. | |
| `endpoint` | The endpoint of the event occurred on. | |
| `name` | The name of the event. For example, 'Reboot' and 'Upgrade' etc. | |
| `type` | The type of the event, could be `Normal` or `Error`. | `Normal` |
| `message` | The detail of the event. This should be a one-line message that briefly describes why the event is reported. | |
| `startTime` | The start time (in milliseconds) of the event, measured between the current time and midnight, January 1, 1970 UTC. | |
| `endTime` | The end time (in milliseconds) of the event, measured between the current time and midnight, January 1, 1970 UTC. | |

</details>

#### `list`

<details>

<summary>event list [--service=service] [--instance=instance] [--endpoint=endpoint] [--name=name] [--type=type] [--start=start-time] [--end=end-time] </summary>

| argument | description | default |
| :--- | :--- | :--- |
| `service` | The service name whose events are to displayed. | |
| `instance` | The service instance name whose events are to displayed. | |
| `endpoint` | The endpoint name whose logs are to displayed. | |
| `name` | The name of the event. | |
| `type` | The type of the event, could be `Normal` or `Error`. | `Normal` |

</details>

### `logs`

#### `list`
After reloading your shell, `swctl` auto-completion should be working.

<details>

<summary>logs list [--service-id=service-id] [--instance-id=instance-id] [--endpoint-id=endpoint-id] [--trace-id=trace-id] [--tags=tags] [--start=start-time] [--end=end-time] </summary>

| argument | description | default |
| :--- | :--- | :--- |
| `service-id` | The service id whose logs are to displayed. | |
| `instance-id` | The service instance id whose logs are to displayed. | |
| `endpoint-id` | The service endpoint id whose logs are to displayed. | |
| `trace-id` | The trace id whose logs are to displayed. | |
| `tags` | Only tags defined in the core/default/searchableLogsTags are searchable. Check more details on the Configuration Vocabulary page | See [Configuration Vocabulary page](https://github.com/apache/skywalking/blob/master/docs/en/setup/backend/configuration-vocabulary.md) |

</details>

### `profile`

#### `create`

<details>

<summary>profile create [--service-id=service-id] [--service-name=service-name] [--endpoint=endpoint] [--start-time=start-time] [--duration=duration] [--min-duration-threshold=min-duration-threshold] [--dump-period=dump-period] [--max-sampling-count=max-sampling-count] </summary>

| argument | description | default |
| :--- | :--- | :--- |
| `service-id` | <service-id> whose endpoints are to be profile. | |
| `service-name` | <service-name> whose endpoints are to be profile. | |
| `endpoint` | which endpoint should profile. | |
| `start-time` | profile task start time(millisecond). | |
| `duration` | profile task continuous time(minute). | |
| `min-duration-threshold` | profiled endpoint must greater duration(millisecond). | |
| `dump-period` | profiled endpoint dump period(millisecond). | |
| `max-sampling-count` | profile task max sampling count. | |

</details>

#### `list`

<details>

<summary>profile list [--service-id=service-id] [--service-name=service-name] [--endpoint=endpoint] </summary>
## Help / Manual

| argument | description | default |
| :--- | :--- | :--- |
| `service-id` | `<service id>` whose profile task are to be searched. | |
| `service-name` | `<service name>` whose profile task are to be searched. | |
| `endpoint` | `<endpoint>` whose profile task are to be searched | |

</details>

#### `segment-list`

<details>

<summary>profile segment-list [--task-id=task-id] </summary>

| argument | description | default |
| :--- | :--- | :--- |
| `task-id` | `<task id>` whose profiled segment are to be searched. | |

</details>

#### `profiled-segment`

<details>

<summary>profile profiled-segment [--segment-id=segment-id] </summary>

| argument | description | default |
| :--- | :--- | :--- |
| `segment-id` | profiled segment id. | |

</details>

#### `profiled-analyze`

<details>

<summary>profile profiled-analyze [--segment-id=segment-id] [--time-ranges=time-ranges] </summary>

| argument | description | default |
| :--- | :--- | :--- |
| `segment-id` | profiled segment id. | |
| `time-ranges` | need to analyze time ranges in the segment: start-end,start-end. | |

</details>

### `dependency`

#### `service`

<details>

<summary>dependency service [service-id] [--start=start-time] [--end=end-time]</summary>

`dependency service` shows all the dependencies of given `[service-id]` in the time range of `[start, end]`.

| argument | description | default |
| :--- | :--- | :--- |
| `service-id` | The service id whose dependencies are to displayed. |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |

</details>

#### `endpoint`

<details>

<summary>dependency endpoint [endpoint-id] [--start=start-time] [--end=end-time]</summary>

`dependency endpoint` shows all the dependencies of given `[endpoint-id]` in the time range of `[start, end]`.

| argument | description | default |
| :--- | :--- | :--- |
| `endpoint-id` | The service endpoint id whose dependencies are to displayed. | |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |

</details>

#### `instance`

<details>

<summary>dependency instance [clientService-id] [serverService-id] [--start=start-time] [--end=end-time]</summary>

`dependency instance` shows the instance topology of given `[clientService-id]` and `[serverService-id]` in the time
range of `[start, end]`.

| argument | description | default |
| :--- | :--- | :--- |
| `clientService-id` | The service id of the client. | |
| `serverService-id` | The service id of the server. | |
| `--start` | See [Common options](#common-options) | See [Common options](#common-options) |
| `--end` | See [Common options](#common-options) | See [Common options](#common-options) |

</details>
`swctl` builds the help manual inside the command itself with some useful example commands, please type `swctl help`
after installation. If you want to look up detail manual for a specific sub-command, insert `help` before the last
sub-command, for example, `swctl service help list` shows the manual for command `swctl service list`,
and `swctl install manifest help oap` shows the manual for `swctl install manifest oap`.

# Use Cases
# More Use Cases

<details>
<summary>Report events in CD workflows - GitHub Actions</summary>
Expand Down
14 changes: 7 additions & 7 deletions internal/commands/interceptor/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ParseEndpoint(required bool) func(*cli.Context) error {
// See flags.EndpointRelationFlags.
func ParseEndpointRelation(required bool) func(*cli.Context) error {
return func(ctx *cli.Context) error {
if err := ParseService(required)(ctx); err != nil {
if err := ParseServiceRelation(required)(ctx); err != nil {
return err
}
if err := ParseEndpoint(required)(ctx); err != nil {
Expand All @@ -72,12 +72,7 @@ func parseEndpoint(required bool, idFlagName, nameFlagName, serviceIDFlagName st
return nil
}

if name != "" {
if serviceID == "" {
return fmt.Errorf(`"--%s" is specified but its related service name or id is not given`, nameFlagName)
}
id = serviceID + "_" + b64enc(name)
} else if id != "" {
if id != "" {
parts := strings.Split(id, "_")
if len(parts) != 2 {
return fmt.Errorf("invalid endpoint id, cannot be splitted into 2 parts. %v", id)
Expand All @@ -87,6 +82,11 @@ func parseEndpoint(required bool, idFlagName, nameFlagName, serviceIDFlagName st
return err
}
name = string(s)
} else if name != "" {
if serviceID == "" {
return fmt.Errorf(`"--%s" is specified but its related service name or id is not given`, nameFlagName)
}
id = serviceID + "_" + b64enc(name)
}

if err := ctx.Set(idFlagName, id); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions internal/commands/interceptor/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ package interceptor

import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"

"github.com/apache/skywalking-cli/internal/logger"
"github.com/apache/skywalking-cli/pkg/graphql/utils"

api "skywalking.apache.org/repo/goapi/query"
Expand Down Expand Up @@ -60,6 +63,11 @@ func ParseEntity(ctx *cli.Context) (*api.Entity, error) {
}
entity.Scope = utils.ParseScope(entity)

if logger.Log.GetLevel() <= logrus.DebugLevel {
s, _ := json.Marshal(&entity)
logger.Log.Debugf("entity: %+v", string(s))
}

return entity, nil
}

Expand Down
Loading