github.com/matrixorigin/matrixone@v1.2.0/pkg/util/metric/v2/dashboard/grafana_dashboard_proxy.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) initProxyDashboard() error {
    25  	folder, err := c.createFolder(moFolderName)
    26  	if err != nil {
    27  		return err
    28  	}
    29  
    30  	build, err := dashboard.New(
    31  		"Proxy Metrics",
    32  		c.withRowOptions(
    33  			c.initProxyConnectionRow(),
    34  			c.initProxyTransferDurationRow(),
    35  			c.initProxyTransferCounterRow(),
    36  			c.initProxyOthersRow(),
    37  		)...,
    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) initProxyConnectionRow() dashboard.Option {
    47  	return dashboard.Row(
    48  		"Proxy Connection",
    49  		c.withMultiGraph(
    50  			"Connect Counter",
    51  			6,
    52  			[]string{
    53  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connect_counter", `type="accepted"`) + `[$interval]))`,
    54  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connect_counter", `type="current"`) + `[$interval]))`,
    55  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connect_counter", `type="success"`) + `[$interval]))`,
    56  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connect_counter", `type="route-fail"`) + `[$interval]))`,
    57  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connect_counter", `type="common-fail"`) + `[$interval]))`,
    58  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connect_counter", `type="retry"`) + `[$interval]))`,
    59  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connect_counter", `type="select"`) + `[$interval]))`,
    60  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connect_counter", `type="reject"`) + `[$interval]))`,
    61  			},
    62  			[]string{
    63  				"accepted",
    64  				"current",
    65  				"success",
    66  				"route-fail",
    67  				"common-fail",
    68  				"retry",
    69  				"select",
    70  				"reject",
    71  			},
    72  		),
    73  		c.withMultiGraph(
    74  			"Disconnect Counter",
    75  			6,
    76  			[]string{
    77  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_disconnect_counter", `type="server"`) + `[$interval]))`,
    78  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_disconnect_counter", `type="client"`) + `[$interval]))`,
    79  			},
    80  			[]string{
    81  				"server",
    82  				"client",
    83  			},
    84  		),
    85  	)
    86  }
    87  
    88  func (c *DashboardCreator) initProxyTransferDurationRow() dashboard.Option {
    89  	return dashboard.Row(
    90  		"Connection transfer duration",
    91  		c.getHistogram(
    92  			"connection transfer duration",
    93  			c.getMetricWithFilter(`mo_proxy_connection_transfer_duration_seconds_bucket`, ``),
    94  			[]float64{0.50, 0.8, 0.90, 0.99},
    95  			12,
    96  			axis.Unit("s"),
    97  			axis.Min(0)),
    98  	)
    99  }
   100  
   101  func (c *DashboardCreator) initProxyTransferCounterRow() dashboard.Option {
   102  	return dashboard.Row(
   103  		"Proxy Transfer",
   104  		c.withMultiGraph(
   105  			"Connection Transfer Counter",
   106  			6,
   107  			[]string{
   108  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connection_transfer_counter", `type="success"`) + `[$interval]))`,
   109  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connection_transfer_counter", `type="fail"`) + `[$interval]))`,
   110  				`sum(rate(` + c.getMetricWithFilter("mo_proxy_connection_transfer_counter", `type="abort"`) + `[$interval]))`,
   111  			},
   112  			[]string{
   113  				"success",
   114  				"fail",
   115  				"abort",
   116  			},
   117  		),
   118  		c.withGraph(
   119  			"Backend Server Drain Counter",
   120  			6,
   121  			`sum(rate(`+c.getMetricWithFilter("mo_proxy_drain_counter", ``)+`[$interval]))`,
   122  			""),
   123  	)
   124  }
   125  
   126  func (c *DashboardCreator) initProxyOthersRow() dashboard.Option {
   127  	return dashboard.Row(
   128  		"Proxy Others State",
   129  		c.withGraph(
   130  			"Available Backend Server Num",
   131  			3,
   132  			`sum(rate(`+c.getMetricWithFilter("mo_proxy_available_backend_server_num", "")+`[$interval]))`,
   133  			""),
   134  		c.withGraph(
   135  			"Transfer Queue Size",
   136  			3,
   137  			`sum(rate(`+c.getMetricWithFilter("mo_proxy_transfer_queue_size", "")+`[$interval]))`,
   138  			""),
   139  		c.withGraph(
   140  			"Connections Need To Transfer",
   141  			3,
   142  			`sum(rate(`+c.getMetricWithFilter("mo_proxy_connections_need_to_transfer", "")+`[$interval]))`,
   143  			""),
   144  		c.withGraph(
   145  			"Connections In Transfer Intent State",
   146  			3,
   147  			`sum(rate(`+c.getMetricWithFilter("mo_proxy_connections_transfer_intent", "")+`[$interval]))`,
   148  			""),
   149  	)
   150  }