github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dds/v3/connection/ListSessions.go (about) 1 package connection 2 3 import ( 4 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" 6 ) 7 8 type ListSessionOpts struct { 9 // Specifies the node ID. The following nodes can be queried: mongos nodes in the cluster, and all nodes in the replica set and single node instances. 10 NodeId string `json:"-"` 11 // Specifies the index position. If offset is set to N, the resource query starts from the N+1 piece of data. The value is 0 by default, indicating that the query starts from the first piece of data. The value cannot be a negative number. 12 Offset int `q:"offset"` 13 // Specifies the number of records to be queried. The value range is [1, 20]. The default value is 10, indicating that 10 records are returned. 14 Limit int `q:"limit"` 15 // Specifies the execution plan description. If this parameter is left empty, sessions in which plan_summary is empty are queried. You can also specify an execution plan, for example, COLLSCAN IXSCAN FETCH SORT LIMIT SKIP COUNT COUNT_SCAN TEXT PROJECTION 16 PlanSummary string `q:"plan_summary"` 17 // Specifies the operation type. If this parameter is left empty, sessions in which type is empty are queried. You can also specify an operation type, for example, none update insert query command getmore remove killcursors. 18 Type string `q:"type"` 19 // Specifies the namespace. If this parameter is left blank, the sessions in which namespace is empty are queried. You can also specify the value based on the service requirements. 20 NameSpace string `q:"namespace"` 21 // Specifies the duration. The unit is us. If this parameter is left empty, the sessions in which cost_time is empty are queried. You can also set this parameter based on the service requirements, indicating that the sessions in which the value of cost_time exceeds the specified value are queried. 22 CostTime int `q:"cost_time"` 23 } 24 25 func ListSessions(client *golangsdk.ServiceClient, opts ListSessionOpts) (*ListSessionsResponse, error) { 26 url, err := golangsdk.NewURLBuilder().WithEndpoints("nodes", opts.NodeId, "sessions").WithQueryParams(&opts).Build() 27 if err != nil { 28 return nil, err 29 } 30 31 // GET https://{Endpoint}/v3/{project_id}/nodes/{node_id}/sessions 32 raw, err := client.Get(client.ServiceURL(url.String()), nil, nil) 33 if err != nil { 34 return nil, err 35 } 36 37 var res ListSessionsResponse 38 err = extract.Into(raw.Body, &res) 39 return &res, err 40 } 41 42 type ListSessionsResponse struct { 43 Sessions []SessionResponse `json:"sessions"` 44 TotalCount int `json:"total_count"` 45 } 46 47 type SessionResponse struct { 48 // Indicates the session ID. 49 Id string `json:"id"` 50 // Indicates that whether the current session is active. If the value is "true", the session is active. If the value is "false", the session is inactive. 51 Active bool `json:"active"` 52 // Indicates the operation. 53 Operation string `json:"operation"` 54 // Indicates the operation type. 55 Type string `json:"type"` 56 // Specifies the duration. The unit is us. 57 CostTime string `json:"cost_time"` 58 // Indicates the execution plan description. 59 PlanSummary string `json:"plan_summary"` 60 // Indicates the host. 61 Host string `json:"engine_versions"` 62 // Indicates the client address. 63 Client string `json:"client"` 64 // Indicates the connection description. 65 Description string `json:"description"` 66 // Indicates the namespace. 67 Namespace string `json:"namespace"` 68 }