{

<% if not prj %>
    <% set prj = "l7-balancer-term" %>
<% endif %>

<% if (prj == 'l7-balancer-term') or (prj == 'l7-balancer-exp-term') or (prj == 'l7-geo-only') %>
    <% set prj_is_kubr = 'true' %>
<% endif %>

<% if prj_is_kubr or (prj == 'l7-balancer-knoss-morda') or (prj == 'l7-balancer-knoss-search') or (prj == 'l7-proxy') %>
    <% if hide_domains %>
	    <% set use_service_total_rps = 0 %>
    <% else %>
        <% set use_service_total_rps = 1 %>
    <% endif %>
<% endif %>

<% if service_req %>
	<% if prj_is_kubr or (prj == 'l7-balancer-knoss-morda') or (prj == 'l7-balancer-knoss-search') or (prj == 'l7-balancer-yaru') or (prj == 'any') %>
       <% set use_service_req = 'true' %>
	<% endif %>
<% endif %>

<% if use_service_req %>
    <% set panels = "[exits, service_total, error1, error2, error3, outgoing_codes, processing_time, succ_requests_to_geo, fail_requests_to_geo, cpu_usage, cpu_throttled_and_memory, coroutines, ddos, pings, network]" %>
<% else %>
    <% set panels = "[exits, service_total, error1, error2, error3, outgoing_codes, processing_time, cpu_usage, cpu_throttled_and_memory, coroutines, ddos, pings, network]" %>
<% endif %>

<% if not geo %>
    <% set geo = list_geo(itype='balancer', prj=prj|string) %>
<% else %>
	<% set geo = ("[" + geo|string + "]")|from_json %>
<% endif %>

<% if not hosts %>
    <% set hosts = "ASEARCH" %>
<% endif %>

<% if not ctype%>
	<% set ctype = "prod,prestable" %>
<% endif %>

<% if not service %>
    <% set service = "service_total" %>
<% endif %>

<% if show_alerts %>
  <% set show_alerts = 1 %>
<% else %>
  <% set show_alerts = 0 %>
<% endif %>

<% set research_signals = "signals=*cpu_limiter*,*worker-conts*,*conts*,balancer_report-worker-dns*summ,balancer_report-pinger-dns*summ,%7B*exit*,messages-crashes_total_summ,instancectl-balancer.exit_error_mmmm,instancectl-balancer.exit_signal_mmmm%7D,%7Bbalancer_report-worker-tcp_conns_ammv,balancer_report-worker-tcp_max_conns_ammv%7D,*ban*,%7Bservice_total,balancer_report-report-service_total-reused_summ,balancer_report-report*service_total*requests_summ%7D,%7Bbalancer_report-report*service_total*succ_summ,balancer_report-report*service_total-*fail_summ%7D,%7Bportoinst-anon_usage_gb_tmmv,portoinst-memory_guarantee_gb_tmmv%7D,%7Bquant(fdstat-fd_used_hgram,99),quant(fdstat-fd_available_hgram,1)%7D,*desync*,quant(balancer_report-worker-cpu_usage_hgram,99),*conts_wait*,*conts_scheduled*,*conts_ready*,perc(portoinst-cpu_throttled_cores_tmmv,portoinst-cpu_guarantee_cores_tmmv),portoinst-net_retrans_segs_tmmv,netstat-tcp_retrans_segs_summ,%7Bquant(balancer_report-report-service_total-processing_time_hgram,max),quant(balancer_report-report-service_total-processing_time_hgram,99),quant(balancer_report-report-service_total-processing_time_hgram,95),quant(balancer_report-report-service_total-processing_time_hgram,50)%7D,%7Bdiv(or(balancer_report-report-service_total-outgoing_1xx_summ,balancer_report-report-service_total-1xx-externalunknown_summ),normal()),div(or(balancer_report-report-service_total-outgoing_2xx_summ,balancer_report-report-service_total-2xx-externalunknown_summ),normal()),div(or(balancer_report-report-service_total-outgoing_3xx_summ,balancer_report-report-service_total-3xx-externalunknown_summ),normal()),div(or(balancer_report-report-service_total-outgoing_404_summ,balancer_report-report-service_total-404-externalunknown_summ),normal()),div(or(balancer_report-report-service_total-outgoing_4xx_summ,balancer_report-report-service_total-4xx-externalunknown_summ),normal()),div(or(balancer_report-report-service_total-outgoing_5xx_summ,balancer_report-report-service_total-5xx-externalunknown_summ),normal())%7D,%7Bbalancer_report-report-service_total-backend_error_summ,balancer_report-report-service_total-client_fail_summ,balancer_report-report-service_total-limited_backend_attempt_summ%7D,%7Bquant(balancer_report-worker-dns_resolve_time_hgram,99),quant(balancer_report-worker-dns_async_resolve_time_hgram,99)%7D,%7Bquant(balancer_report-pinger-dns_resolve_time_hgram,99),quant(balancer_report-pinger-dns_async_resolve_time_hgram,99)%7D,portoinst-anon_usage_gb_tmmv,%7Bbalancer_report-http2-h2_conn_active_ammv,balancer_report-http2-h2_conn_inprog_ammv,balancer_report-http2-h1_conn_inprog_ammv,balancer_report-report-service_total-inprog_ammv%7D,balancer_report-active-entire_group_disabled_ammv,%7Bbalancer_report-http2-stream_success_summ,balancer_report-ssl_sni-tls1_3_requests_summ,balancer_report-ssl_sni-https_requests_summ,balancer_report-report-service_total-requests_summ%7D,%7Bbalancer_report-report-service_total-client_fail_summ,balancer_report-ssl_sni-*%7D,%7Bbalancer_report-report*service_total*requests_summ%7D,%7Bbalancer_report-report*service_total*succ_summ%7D,%7Bbalancer_report-report*service_total-*fail_summ%7D,balancer_report-worker-tcp_conns_open_summ,%7Bportoinst-net_tx_mb_summ,portoinst-net_rx_mb_summ%7D,%7Bportoinst-net_tx_mb_summ,portoinst-net_rx_mb_summ%7D,%7Bportoinst-ooms_summ,hsum(portoinst-ooms_slot_hgram)%7D,*limit*,*antirobot*,%7B*antirobot-o*,*antirobot-p*,*antirobot-r*,*antirobot-s*%7D/" %>

<% set panel_height = 1 %>
<% set upstreams_height = panel_height * 1.5 %>
<% set panel_width = 9 %>
<% if not signal_width %>
	<% set signal_width = 1 %>
<% endif %>

<% set colors_good = ["#169833", "#81e34a", "#5ab26d", "#50f410"] %>
<% set colors_neutral1 = ["#1070f4", "#1e10f4", "#469ce5", "#46dee5", "#5ba7da"] %>
<% set colors_neutral2 = ["#8846e5", "#ae85e7", "#a60df4", "#837689", "#020202"] %>
<% set colors_warning = ["#eea03a", "#e7da0d"] %>
<% set colors_error = ["#ff0b0b", "#f139cc", "#d01a5f", "#eb4b1e", "#ad0808"] %>

"abc": "appbalancer",
"title": "L7 balancer monitoring panel",
"description": "https://wiki.yandex-team.ru/balancer/Как-Мониторить-Балансер/",
"type": "panel",
"charts": [
<% set main_layout = create_main_layout("vertical", default_width=panel_width, default_height=panel_height) %>
<% set panels = panels|from_json %>

<% set error_signals1 = (
	("client_fail_summ", 0, colors_neutral1[0], colors_neutral1[0]),
	("client_error_summ", 0, colors_warning[0], colors_neutral1[1]),
	("client_timeout_summ", 0, colors_neutral2[0], colors_neutral1[2]),
	("other_fail_summ", 0, colors_error[0], colors_warning[0]),
) %>

<% set error_signals2 = (
    ("conn_fail_summ", 0, colors_neutral1[0], colors_error[0]),
	("conn_refused_summ", 0, colors_warning[0], colors_error[1]),
	("conn_timeout_summ", 0, colors_neutral2[0], colors_error[2]),
	("conn_other_error_summ", 0, colors_error[0], colors_error[3]),
) %>

<% set error_signals3 = (
	("backend_error_summ", 0, colors_neutral1[0], colors_neutral2[0]),
	("backend_fail_summ", 0, colors_neutral2[0], colors_neutral2[1]),
	("backend_timeout_summ", 0, colors_warning[0], colors_neutral2[2]),
) %>

<% if use_service_total_rps %>
	<% set upstreams_layout = main_layout.sub("vertical", default_width=panel_width * geo|length, default_height=panel_height) %>
	<% set rps_layout = upstreams_layout.sub("horizontal") %>
        {
            "title": "service total RPS",
			"type": "graphic",
			"normalize": "true",
			<<rps_layout.coords()>>,
            "signals": [
            <% for signal in list_signals(pattern='balancer_report-report-service_total_(?P<section>.+)-requests_summ', itype='balancer', prj=prj, limit=500) %>
            {
                "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>",
                "host": "<< hosts >>",
                "name": "<< signal >>",
                "title": "<< signal.sub('section') >>",
				"width": << signal_width >>,
            },
            <% endfor %>
            ],
        },
        <% set fails_layout = upstreams_layout.sub("horizontal") %>
        {
            "title": "service total fails",
			"type": "graphic",
			"normalize": "true",
			<<fails_layout.coords()>>,
            "signals": [
            <% for signal in list_signals(pattern='balancer_report-report-service_total_(?P<section>.+)-fail_summ', itype='balancer', prj=prj, limit=5000) %>
            {
                "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>",
                "host": "<< hosts >>",
                "name": "<< signal >>",
                "title": "<< signal.sub('section') >>",
                "width": << signal_width >>,
            },
            <% endfor %>
            ],
        },
<% endif %>

<% if show_upstreams %>
	<% set upstreams_layout = main_layout.sub("vertical", default_width=panel_width * geo|length, default_height=panel_height) %>
	<% set rps_layout = upstreams_layout.sub("horizontal") %>
        {
            "title": "RPS by upstreams",
			"type": "graphic",
			"normalize": "true",
			<<rps_layout.coords()>>,
            "signals": [
            <% for signal in list_signals(pattern='balancer_report-report-(?P<section>.+)-requests_summ', itype='balancer', prj=prj, limit=5000) %>
                <%- set s = signal.sub('section')|string %>
                <%- if 'default' not in s
                    and 'service_total' not in s
                    and 'requests_to' not in s
                    and 'noc_static_check' not in s
                    and 'antirobot' not in s
                    and 'expgetter' not in s
                    and not s.startswith('_') %>
                    {
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>",
                        "host": "<< hosts >>",
                        "name": "<< signal >>",
                        "title": "<< signal.sub('section') >>",
						"width": << signal_width >>,
                    },
                <% endif %>
            <% endfor %>
            ],
        },
        <% set fails_layout = upstreams_layout.sub("horizontal") %>
        {
            "title": "fails by upstreams",
			"type": "graphic",
			"normalize": "true",
			<<fails_layout.coords()>>,
            "signals": [
            <% for signal in list_signals(pattern='balancer_report-report-(?P<section>.+)-fail_summ', itype='balancer', prj=prj, limit=5000) %>
                <%- set s = signal.sub('section')|string %>
                <%- if 'default' not in s
                    and 'service_total' not in s
                    and 'requests_to' not in s
                    and 'noc_static_check' not in s
                    and 'antirobot' not in s
                    and 'expgetter' not in s
                    and not s.startswith('_') %>
                    {
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>",
                        "host": "<< hosts >>",
                        "name": "<< signal >>",
                        "title": "<< signal.sub('section') >>",
                        "width": << signal_width >>,
                    },
                <% endif %>
            <% endfor %>
            ],
        },
<% endif %>
<% set by_dc_layout = main_layout.sub("horizontal", default_width=panel_width, default_height=panel_height * 9 / 10) %>
<% for location in geo %>
	<% set dc_layout = by_dc_layout.sub("vertical") %>
	<% for panel in panels %>
			<% if "exits" == panel %>
			<% set exit_layout = dc_layout.sub("horizontal") %>
			{
				"title": "<< location >> signals quota %, frozen threads, exits",
				"links": [
				{
					"title": "research panel",
					"url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
				},
				],
				"yAxis": [{"minValue":0}],
				"type": "graphic",
				"normalize": "true",
				<<exit_layout.coords()>>,
				"signals": [
				<% for e in (("modules-unistat-limit_usage_perc_xxxx", 0, colors_neutral1[0], "signals quota %"),
							 ("balancer_report-threads-froze_ammv", 1, colors_warning[0], "threads frozen"),
							 ("sum(instancectl-balancer.exit_error_mmmm, instancectl-balancer.exit_signal_mmmm)", 1, colors_error[0], "exits"),
							 ("max(diff(messages-crashes_total_summ, messages-crashes_sig9_summ), sum(messages-crashes_sig6_summ, messages-crashes_sig11_summ))", 1, colors_error[1], "crashes, not SIGKILL"),
							 ("messages-crashes_sig9_summ", 1, colors_neutral2[0], "exits by SIGKILL")
				) %>
					{
						"color": "<< e[2] >>",
						"host": "<< hosts >>",
						"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
						"name": "<< e[0] >>",
						"title": "<< e[3] >>",
						"width": << signal_width >>,
						"yAxis": << e[1] >>,
					},
				<% endfor %>
				{
					"color": "<< colors_error[0] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "const(100)",
					"title": "100%",
				},
				],
			},
        <% elif "service_total" == panel %>
			<% if show_alerts %>
				<% set stub_layout = dc_layout.sub("horizontal") %>
				{
					"type": "text",
					"text": "<< location >>",
					<<stub_layout.coords(height=0.25)>>,
				},
				<% set alerts_layout = dc_layout.sub("flow", columns=panel_width) %>
				<% set alerts = list_alerts(name_pattern='L7_alerts\.self\.' + prj|string + '\.' + location|string + '\..+') %>
				<% for alert in alerts|sort(attribute='name') %>
				{
					"type": "alert",
					"name": "<<alert>>",
					"title": "<<alert.name.split(".")[3:]|join(' ')|replace('_', ' ')>>",
					<<alerts_layout.coords(width=1, height=0.3)>>,
					"showThresholds": false,
				},
				<% endfor %>
				<% set stub_layout = dc_layout.sub("horizontal") %>
				{
					"type": "text",
					"text": "<< prj >>",
					<<stub_layout.coords(height=0.25)>>,
				},
			<% endif %>
			<% set service_total_layout = dc_layout.sub("horizontal") %>
			<% set service_total_signals = (
				("requests_summ", 0, colors_neutral1[0]),
				("inprog_ammv", 0, colors_neutral1[1]),
				("backend_attempt_summ", 0, colors_neutral1[2]),
				("succ_summ", 0, colors_good[0]),
				("fail_summ", 1, colors_error[0]),
				("ka_summ", 0, colors_neutral2[0]),
				("nka_summ", 0, colors_neutral2[1]),
				("reused_summ", 0, colors_neutral2[2]),
				("nreused_summ", 0, colors_neutral2[3]),
			) %>
            {
                "title": "<< location >> << service >> total",
				"description": "Requests. Signals description is here https://wiki.yandex-team.ru/balancer/cookbook/stats/#tablicadostupnyxsignalov",
				"links": [
                {
                    "title": "signals description",
                    "url": "https://wiki.yandex-team.ru/balancer/cookbook/stats/#tablicadostupnyxsignalov"
                },
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
                "type": "graphic",
                "normalize": true,
				<<service_total_layout.coords()>>,
				"signals": [
					<% for code in service_total_signals %>
						{
							"color": "<< code[2] >>",
							"host": "<< hosts >>",
							"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
							"name": "balancer_report-report-<< service >>-<< code[0] >>",
							"title": << code[0] >>,
							"width": << signal_width >>,
							"yAxis": << code[1] >>,
						},
					<% endfor %>
				],
            },
        <% elif "error1" == panel %>
			<% set error_layout = dc_layout.sub("horizontal", default_height=panel_height * 6 / 10) %>
            {
				"title": "<< location >> << service >> client errors",
				"description": "Request errors. Signals description is here https://wiki.yandex-team.ru/balancer/cookbook/stats/#tablicadostupnyxsignalov",
				"links": [
                {
                    "title": "signals description",
                    "url": "https://wiki.yandex-team.ru/balancer/cookbook/stats/#tablicadostupnyxsignalov"
                },
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
				"normalize": "true",
				<<error_layout.coords()>>,
				"yAxis": [{"log":2}],
                "signals": [
				<% for error_signal in error_signals1 %>
				{
					"color": "<< error_signal[2] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "balancer_report-report-<< service >>-<< error_signal[0] >>",
					"title": "<< error_signal[0] >>",
					"width": << signal_width >>,
					"yAxis": << error_signal[1] >>,
				},
				<% endfor %>
                ],
            },
        <% elif "error2" == panel %>
			<% set error_layout = dc_layout.sub("horizontal", default_height=panel_height * 6 / 10) %>
            {
				"title": "<< location >> << service >> conn errors",
				"description": "Request errors. Signals description is here https://wiki.yandex-team.ru/balancer/cookbook/stats/#tablicadostupnyxsignalov",
				"links": [
                {
                    "title": "signals description",
                    "url": "https://wiki.yandex-team.ru/balancer/cookbook/stats/#tablicadostupnyxsignalov"
                },
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
				"normalize": "true",
				<<error_layout.coords()>>,
				"yAxis": [{"log":2}],
                "signals": [
				<% for error_signal in error_signals2 %>
				{
					"color": "<< error_signal[2] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "balancer_report-report-<< service >>-<< error_signal[0] >>",
					"title": "<< error_signal[0] >>",
					"width": << signal_width >>,
					"yAxis": << error_signal[1] >>,
				},
				<% endfor %>
                ],
            },
        <% elif "error3" == panel %>
			<% set error_layout = dc_layout.sub("horizontal", default_height=panel_height * 6 / 10) %>
            {
				"title": "<< location >> << service >> backend errors",
				"description": "Request errors. Signals description is here https://wiki.yandex-team.ru/balancer/cookbook/stats/#tablicadostupnyxsignalov",
				"links": [
                {
                    "title": "signals description",
                    "url": "https://wiki.yandex-team.ru/balancer/cookbook/stats/#tablicadostupnyxsignalov"
                },
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
				"normalize": "true",
				<<error_layout.coords()>>,
				"yAxis": [{"log":2}],
                "signals": [
				<% for error_signal in error_signals3 %>
				{
					"color": "<< error_signal[2] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "balancer_report-report-<< service >>-<< error_signal[0] >>",
					"title": "<< error_signal[0] >>",
					"width": << signal_width >>,
					"yAxis": << error_signal[1] >>,
				},
				<% endfor %>
                ],
            },
		<% elif "outgoing_codes" == panel %>
			<% set outgoing_layout = dc_layout.sub("horizontal") %>
			<% set response_codes = (
				('101', 0, colors_neutral1[0]),
				('1xx', 0, colors_neutral1[1]),
				('2xx', 0, colors_good[0]),
				('3xx', 0, colors_neutral2[0]),
				('4xx', 0, colors_error[0]),
				('404', 0, colors_warning[0]),
				('5xx', 0, colors_error[1]),
			) %>
			{
				"title": "<< location >> << service >> outgoing codes",
				"description": "Outgoing codes from balancer to client",
				"links": [
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
                "type": "graphic",
				"yAxis": [{"log":2}],
                "normalize": true,
				<<outgoing_layout.coords()>>,
				"signals": [
				<% for code in response_codes %>
				{
					"color": "<< code[2] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "balancer_report-report-<< service >>-outgoing_<< code[0] >>_summ",
					"title": "<< service >> << code[0] >>",
					"width": << signal_width >>,
					"yAxis": << code[1] >>
				},
				<% endfor %>
				],
			},
        <% elif "processing_time" == panel %>
			<% set time_layout = dc_layout.sub("horizontal") %>
			{
				"title": "<< location >> << service >> processing time distribution",
				"description": "quantile",
				"links": [
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
				"type": "graphic",
				"normalize": true,
				<<time_layout.coords()>>,
				"signals": [
				<% for t in ((90, colors_neutral1[0]),
							 (95, colors_neutral1[1]),
							 (98, colors_neutral1[2]),
							 (99, colors_neutral2[0]),
							 (999, colors_neutral2[1]),
							) %>
				{
					"color": "<< t[1] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "quant(balancer_report-report-<< service >>-processing_time_hgram, << t[0] >>)",
					"title": "<< service >> << t[0] >>%",
					"width": << signal_width >>,
				},
				<% endfor %>
				],
			},
        <% elif "succ_requests_to_geo" == panel %>
            <% if prj_is_kubr %>
                <% set dest_dc = ("knoss_localdc", "knoss_fallback") %>
            <% else %>
                <% set dest_dc = geo %>
            <% endif %>

			<% set w = dest_dc|length %>
			<% set local_dc_layout = dc_layout.sub("horizontal", default_width=panel_width/w, default_height=panel_height/2) %>
            <% for loc in dest_dc %>
				<% set local_dc_dest_layout = local_dc_layout.sub("horizontal", default_width=panel_width/w, default_height=panel_height/2) %>
                {
                    "title": "<< location >> << loc >> << service_req >> succ requests",
                    "description": "for upstream (service_req param)",
                    "type": "graphic",
                    "normalize": true,
					<<local_dc_dest_layout.coords()>>,
                    "signals": [
                        {
                            "color": "<< colors_good[0] >>",
                            "host": "<< hosts >>",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-requests_summ",
                            "title": "<< service_req >> success requests to << loc >>",
                        },
                    ],
                },
            <% endfor %>
        <% elif "fail_requests_to_geo" == panel %>
            <% if prj_is_kubr %>
                <% set dest_dc = ("knoss_localdc", "knoss_fallback") %>
            <% else %>
                <% set dest_dc = geo %>
            <% endif %>

			<% set w = dest_dc|length %>
			<% set local_dc_layout = dc_layout.sub("horizontal", default_width=panel_width/w, default_height=panel_height/2) %>
            <% for loc in dest_dc %>
				<% set local_dc_dest_layout = local_dc_layout.sub("horizontal", default_width=panel_width/w, default_height=panel_height/2) %>                {
                    "title": "<< location >> << loc >> << service_req >> fail requests",
                    "description": "for upstream (service_req param)",
                    "type": "graphic",
                    "normalize": true,
					<<local_dc_dest_layout.coords()>>,
					"signals": [
					<% for error_signal in (error_signals1 + error_signals2 + error_signals3) %>
                        {
                            "color": "<< error_signal[3] >>",
                            "host": "<< hosts >>",
                            "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                            "name": "balancer_report-report-<< service_req >>_requests_to_<< loc >>-<< error_signal[0] >>",
                            "title": "<< service_req >> << location >> to << loc >> << error_signal[0] >>",
							"yAxis": << error_signal[1] >>,
                        },
					<% endfor %>
					],
                },
            <% endfor %>
		<% elif "cpu_usage" == panel %>
			<% set cpu_usage_layout = dc_layout.sub("horizontal") %>
            {
                "title": "<< location >> CPU",
				"description": "CPU usage quantiles, usage % from guarantee, CPU limiter",
				"links": [
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
                "type": "graphic",
                "normalize": true,
				<<cpu_usage_layout.coords()>>,
                "signals": [
				<% for p in ((50, colors_warning[0]),
							 (70, colors_neutral1[0]),
							 (99, colors_neutral1[0]),
							) %>
                    {
                        "color": "<< p[1] >>",
                        "host": "<< hosts >>",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "quant(balancer_report-worker-cpu_usage_hgram, << p[0] >>)",
                        "title": "p<< p[0] >>",
						"width": << signal_width >>,
                    },
				<% endfor %>
                    {
                        "color": "<< colors_neutral2[0] >>",
                        "host": "<< hosts >>",
						"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "perc(portoinst-cpu_usage_cores_tmmv, portoinst-cpu_guarantee_cores_tmmv)",
                        "title": "usage",
						"width": << signal_width >>,
                    },
				<% for l in (("conn_hold_summ", colors_error[0]),
							 ("conn_rejected_summ", colors_error[1]),
							 ("http2_closed_summ", colors_error[2]),
							 ("http2_disabled_summ", colors_error[3]),
							 ("keepalive_closed_summ", colors_error[4]),
							) %>
                    {
                        "color": "<< l[1] >>",
                        "host": "<< hosts >>",
                        "tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "balancer_report-worker-cpu_limiter_<< l[0] >>",
                        "title": "CPU limiter << l[0] >>",
						"width": << signal_width >>,
                    },
				<% endfor %>
                ],
            },
        <% elif "cpu_throttled_and_memory" == panel %>
			<% set throttled_and_memory_layout = dc_layout.sub("horizontal") %>
            {
                "title": "<< location >> cpu wait/throttled cores and memory usage",
				"links": [
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
                "type": "graphic",
                "normalize": true,
				<<throttled_and_memory_layout.coords()>>,
                "signals": [
                    {
                        "color": "<< colors_neutral1[0] >>",
                        "host": "<< hosts >>",
						"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "perc(portoinst-cpu_wait_cores_tmmv, portoinst-cpu_guarantee_cores_tmmv)",
                        "title": "cpu wait",
						"width": << signal_width >>,
						"yAxis": 0,
                    },
                    {
                        "color": "<< colors_neutral1[1] >>",
                        "host": "<< hosts >>",
						"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "perc(portoinst-cpu_throttled_cores_tmmv, portoinst-cpu_guarantee_cores_tmmv)",
                        "title": "cpu throttled cores",
						"width": << signal_width >>,
						"yAxis": 0,
                    },
                    {
                        "color": "<< colors_neutral2[0] >>",
                        "host": "<< hosts >>",
						"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "portoinst-anon_usage_gb_tmmv",
                        "title": "RSS anon memory usage",
						"width": << signal_width >>,
						"yAxis": 1,
                    },
                    {
                        "color": "<< colors_error[0] >>",
                        "host": "<< hosts >>",
						"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
                        "name": "portoinst-ooms_summ",
                        "title": "OOMs summ",
						"width": << signal_width >>,
						"yAxis": 2,
                    },
                ],
            },
		<% elif "coroutines" == panel %>
			<% set coroutines_layout = dc_layout.sub("horizontal") %>
			{
				"title": "<< location >> worker coroutines and desync",
				"links": [
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
				"yAxis": [{"log":2}],
				"type": "graphic",
				"normalize": true,
				<<coroutines_layout.coords()>>,
				"signals": [
				<% for coro in (("ready_ammv", 0, colors_good[0]),
								("scheduled_ammv", 0, colors_neutral1[0]),
								("waiting_ammv", 0, colors_neutral2[0]),
								) %>
				{
					"color": "<< coro[2] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "balancer_report-worker-conts_<< coro[0] >>",
					"title": "<< coro[0] >>",
					"width": << signal_width >>,
					"yAxis": << coro[1] >>
				},
				<% endfor %>
				{
					"color": "<< colors_warning[0] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "balancer_report-report-service_total-inprog_ammv",
					"title": "coro inprog",
					"width": << signal_width >>,
					"yAxis": << 0 >>
				},
				{
					"color": "<< colors_error[0] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "balancer_report-worker-cpu_usage_time_desync_summ",
					"title": "coro desync",
					"width": << signal_width >>,
					"yAxis": 1
				},
				],
			},
        <% elif "ddos" == panel %>
			<% set ddos_layout = dc_layout.sub("horizontal") %>
			{
				"title": "<< location >> DDOS and antirobot",
				"links": [
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
				"yAxis": [{"log":2}],
				"type": "graphic",
				"normalize": true,
				<<ddos_layout.coords()>>,
				"signals": [
				<% for a in (("requests_summ", 0, colors_neutral1[0], "requests to antirobot"),
							 ("outgoing_1xx_summ", 0, colors_neutral1[1], "outgoing 1xx"),
							 ("outgoing_101_summ", 0, colors_neutral1[2], "outgoing 101"),
							 ("outgoing_2xx_summ", 0, colors_good[0], "outgoing 2xx"),
							 ("outgoing_3xx_summ", 0, colors_good[1], "outgoing 3xx"),
							 ("outgoing_4xx_summ", 0, colors_error[1], "outgoing 4xx"),
							 ("outgoing_404_summ", 0, colors_error[2], "outgoing 404"),
							 ("outgoing_5xx_summ", 0, colors_error[3], "outgoing 5xx"),
							) %>
				{
					"color": "<< a[2] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "balancer_report-report-antirobot-<< a[0] >>",
					"title": "<< a[3] >>",
					"width": << signal_width >>,
					"yAxis": << a[1] >>,
				},
				<% endfor %>
				<% for b in (("ban-addresses_ammv", 1, colors_neutral2[0], "banned addresses"),
							 ("ban-conns_summ", 1, colors_neutral2[1], "banned connections"),
							 ("http-banned_requests_summ", 1, colors_neutral2[2], "banned http requests"),
							) %>
				{
					"color": "<< b[2] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "balancer_report-<< b[0] >>",
					"title": "<< b[3] >>",
					"width": << signal_width >>,
					"yAxis": << b[1] >>,
				},
				<% endfor %>
				],
			},
        <% elif "pings" == panel %>
			<% set pings_layout = dc_layout.sub("horizontal") %>
            {
                "title": "<< location >> conns and FDs usage",
				"description": "Percentage from maximum available",
				"links": [
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
				"yAxis": [{"minValue":0}],
                "type": "graphic",
                "normalize": true,
				<<pings_layout.coords()>>,
                "signals": [
				<% for n in (("perc(balancer_report-worker-tcp_conns_ammv, balancer_report-worker-tcp_max_conns_ammv)", "tcp conns %", 0, colors_good[0]),
							 ("perc(havg(fdstat-fd_used_hgram), havg(fdstat-fd_available_hgram))", "FD usage %", 1, colors_neutral1[0]),
							) %>
				{
					"color": "<< n[3] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "<< n[0] >>",
					"title": "<< n[1] >>",
					"width": << signal_width >>,
					"yAxis": 0
				},
				<% endfor %>
                ],
            },
		<% elif "network" == panel %>
			<% set network_layout = dc_layout.sub("horizontal") %>
			{
				"title": "<< location >> network stats",
				"links": [
                {
                    "title": "research panel",
                    "url": "https://yasm.yandex-team.ru/chart/hosts=<< hosts >>;itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>;<< research_signals >>"
           		},
                ],
				"type": "graphic",
				"normalize": true,
				<<network_layout.coords()>>,
				"signals": [
				<% for n in (("div(portoinst-net_packets_summ, 100)", "packets summ / 100", 0, colors_good[0]),
							 ("balancer_report-report-noc_static_check-succ_summ", "pings", 0, colors_neutral1[0]),
							 ("portoinst-net_retrans_segs_tmmv", "porto retransmits", 0, colors_neutral2[0]),
							 ("netstat-tcp_retrans_segs_summ", "netstat retransmits", 1, colors_neutral2[1]),
							 ("portoinst-net_drops_summ", "drops summ", 2, colors_error[0]),
							) %>
				{
					"color": "<< n[3] >>",
					"host": "<< hosts >>",
					"tag": "itype=balancer;ctype=<< ctype >>;prj=<< prj >>;geo=<< location >>",
					"name": "<< n[0] >>",
					"title": "<< n[1] >>",
					"width": << signal_width >>,
					"yAxis": << n[2] >>,
				},
				<% endfor %>
				],
			},
		<% endif %>
	<% endfor %>
<% endfor %>
    ],
    "type": "panel"
}