github.com/matrixorigin/matrixone@v1.2.0/pkg/util/metric/v2/dashboard/grafana_dashboard_rpc.go (about)

     1  // Copyright 2023 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package dashboard
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/K-Phoen/grabana/axis"
    21  	"github.com/K-Phoen/grabana/dashboard"
    22  )
    23  
    24  func (c *DashboardCreator) initRPCDashboard() error {
    25  	folder, err := c.createFolder(moFolderName)
    26  	if err != nil {
    27  		return err
    28  	}
    29  
    30  	build, err := dashboard.New(
    31  		"RPC Metrics",
    32  		c.withRowOptions(
    33  			c.initRPCOverviewRow(),
    34  			c.initRPCConnectionRow(),
    35  			c.initRPCConnectDurationRow(),
    36  			c.initRPCWriteDurationRow(),
    37  			c.initRPCRequestDoneDurationRow(),
    38  		)...)
    39  	if err != nil {
    40  		return err
    41  	}
    42  	_, err = c.cli.UpsertDashboard(context.Background(), folder, build)
    43  	return err
    44  }
    45  
    46  func (c *DashboardCreator) initRPCOverviewRow() dashboard.Option {
    47  	return dashboard.Row(
    48  		"RPC overview",
    49  		c.withGraph(
    50  			"RPC Network Input",
    51  			6,
    52  			`sum(irate(`+c.getMetricWithFilter("mo_rpc_network_bytes", `type="input"`)+`[$interval])) by (`+c.by+`)`,
    53  			"{{ "+c.by+" }}",
    54  			axis.Unit("bytes"),
    55  			axis.Min(0)),
    56  
    57  		c.withGraph(
    58  			"RPC Network Output",
    59  			6,
    60  			`sum(irate(`+c.getMetricWithFilter("mo_rpc_network_bytes", `type="output"`)+`[$interval])) by (`+c.by+`)`,
    61  			"{{ "+c.by+" }}",
    62  			axis.Unit("bytes"),
    63  			axis.Min(0)),
    64  
    65  		c.withGraph(
    66  			"RPC Client Create",
    67  			6,
    68  			`sum(rate(`+c.getMetricWithFilter("mo_rpc_client_create_total", "")+`[$interval])) by (name)`,
    69  			"{{ name }}"),
    70  
    71  		c.withGraph(
    72  			"Connection pool",
    73  			6,
    74  			`sum(`+c.getMetricWithFilter("mo_rpc_backend_pool_size", ``)+`) by (name)`,
    75  			"{{ name }}"),
    76  
    77  		c.withGraph(
    78  			"Sending queue",
    79  			4,
    80  			`sum(`+c.getMetricWithFilter("mo_rpc_sending_queue_size", ``)+`) by (name, side)`,
    81  			"{{ name }}({{ side }})"),
    82  
    83  		c.withGraph(
    84  			"Write Batch Size",
    85  			4,
    86  			`sum(`+c.getMetricWithFilter("mo_rpc_sending_batch_size", ``)+`) by (name)`,
    87  			"{{ name }}"),
    88  
    89  		c.withGraph(
    90  			"Server sessions",
    91  			4,
    92  			`sum(`+c.getMetricWithFilter("mo_rpc_server_session_size", ``)+`) by (name)`,
    93  			"{{ name }}"),
    94  	)
    95  }
    96  
    97  func (c *DashboardCreator) initRPCConnectionRow() dashboard.Option {
    98  	return dashboard.Row(
    99  		"Connection Status",
   100  		c.withGraph(
   101  			"Create",
   102  			3,
   103  			`sum(rate(`+c.getMetricWithFilter("mo_rpc_backend_create_total", "")+`[$interval])) by (name)`,
   104  			"{{ name }}"),
   105  
   106  		c.withGraph(
   107  			"Close",
   108  			3,
   109  			`sum(rate(`+c.getMetricWithFilter("mo_rpc_backend_close_total", "")+`[$interval])) by (name)`,
   110  			"{{ name }}"),
   111  
   112  		c.withGraph(
   113  			"Reconnect Total",
   114  			3,
   115  			`sum(rate(`+c.getMetricWithFilter("mo_rpc_backend_connect_total", `type="total"`)+`[$interval])) by (name)`,
   116  			"{{ name }}"),
   117  
   118  		c.withGraph(
   119  			"Reconnect Failed",
   120  			3,
   121  			`sum(rate(`+c.getMetricWithFilter("mo_rpc_backend_connect_total", `type="failed"`)+`[$interval])) by (name)`,
   122  			"{{ name }}"),
   123  	)
   124  }
   125  
   126  func (c *DashboardCreator) initRPCConnectDurationRow() dashboard.Option {
   127  	return dashboard.Row(
   128  		"RPC connection duration",
   129  		c.getHistogramWithExtraBy(
   130  			"Connect duration",
   131  			c.getMetricWithFilter(`mo_rpc_backend_connect_duration_seconds_bucket`, ``),
   132  			[]float64{0.50, 0.8, 0.90, 0.99},
   133  			12,
   134  			"name",
   135  			axis.Unit("s"),
   136  			axis.Min(0)),
   137  	)
   138  }
   139  
   140  func (c *DashboardCreator) initRPCWriteDurationRow() dashboard.Option {
   141  	return dashboard.Row(
   142  		"RPC write duration",
   143  		c.getHistogramWithExtraBy(
   144  			"Client-side Write To Network Duration",
   145  			c.getMetricWithFilter(`mo_rpc_write_duration_seconds_bucket`, `side="client"`),
   146  			[]float64{0.50, 0.8, 0.90, 0.99},
   147  			3,
   148  			"name",
   149  			axis.Unit("s"),
   150  			axis.Min(0)),
   151  
   152  		c.getHistogramWithExtraBy(
   153  			"Client-side Write Latency Duration",
   154  			c.getMetricWithFilter(`mo_rpc_write_latency_duration_seconds_bucket`, `side="client"`),
   155  			[]float64{0.50, 0.8, 0.90, 0.99},
   156  			3,
   157  			"name",
   158  			axis.Unit("s"),
   159  			axis.Min(0)),
   160  
   161  		c.getHistogramWithExtraBy(
   162  			"Server-side Write To Network Duration",
   163  			c.getMetricWithFilter(`mo_rpc_write_duration_seconds_bucket`, `side="server"`),
   164  			[]float64{0.50, 0.8, 0.90, 0.99},
   165  			3,
   166  			"name",
   167  			axis.Unit("s"),
   168  			axis.Min(0)),
   169  
   170  		c.getHistogramWithExtraBy(
   171  			"Server-side Write Latency Duration",
   172  			c.getMetricWithFilter(`mo_rpc_write_latency_duration_seconds_bucket`, `side="server"`),
   173  			[]float64{0.50, 0.8, 0.90, 0.99},
   174  			3,
   175  			"name",
   176  			axis.Unit("s"),
   177  			axis.Min(0)),
   178  	)
   179  }
   180  
   181  func (c *DashboardCreator) initRPCRequestDoneDurationRow() dashboard.Option {
   182  	return dashboard.Row(
   183  		"Request done Duration",
   184  		c.getHistogramWithExtraBy(
   185  			"Request done Duration",
   186  			c.getMetricWithFilter(`mo_rpc_backend_done_duration_seconds_bucket`, ``),
   187  			[]float64{0.50, 0.8, 0.90, 0.99},
   188  			12,
   189  			"name",
   190  			axis.Unit("s"),
   191  			axis.Min(0)),
   192  	)
   193  }