<% if not type %>
    <% set type = "term" %>
<% endif %>

<% if type == "term" %>
    <% set requests_const = [0, 130000, 150000, 160000] %>
    <% if not prj %>
        <% set prj = "l7-balancer-term" %>
    <% endif %>
    <% if not host %>
        <% set host = "sas2-0054.search.yandex.net" %>
    <% endif %>
<% elif type == "yastatic" %>
    <% set requests_const = [0, 40000, 55000] %>
    <% if not prj %>
        <% set prj = "l7-balancer-yastatic" %>
    <% endif %>
    <% if not host %>
        <% set host = "sas1-4699.search.yandex.net" %>
    <% endif %>
<% elif type == "exp" %>
    <% set requests_const = [0, 130000, 150000, 160000] %>
    <% if not prj %>
        <% set prj = "l7-balancer-exp-term" %>
    <% endif %>
    <% if not host %>
         <% set host = "vla1-2505.search.yandex.net" %>
    <% endif %>
<% elif type == "search" %>
    <% set requests_const = [0, 8000, 30000] %>
    <% if not prj %>
        <% set prj = "l7-balancer-knoss-search" %>
    <% endif %>
    <% if not host %>
         <% set host = "sas1-0369.search.yandex.net" %>
    <% endif %>
<% elif type == "morda" %>
    <% set requests_const = [0, 8000, 30000] %>
    <% if not prj %>
        <% set prj = "l7-balancer-knoss-morda" %>
    <% endif %>
    <% if not host %>
         <% set host = "sas1-0020.search.yandex.net" %>
    <% endif %>
<% else %>
    <% set requests_const = [0] %>
    <% if not prj %>
        <% set prj = "l7-balancer-term" %>
    <% endif %>
    <% if not host %>
        <% set host = "sas2-0054.search.yandex.net" %>
    <% endif %>
<% endif %>

<% if type == "search" or type == "morda" %>
    <% set pings = "service_health_check" %>
<% elif type == "yastatic" %>
    <% set pings = "requests_to_upstream_ok" %>
<% else %>
    <% set pings = "noc_static_check" %>
<% endif %>

<% if max_requests %>
    <% set requests_const = [0, max_requests|int] %>
<% endif %>

<% set tags = "itype=balancer;ctype=prod,prestable;prj=" + prj|string %>

<% set colors = ["#37bff2", "#169833", "#f6ab31", "#c95edd", "#e85b4e", "#409fd4", "#7bbf00", "#ff2727", "#80f320", "#169833"] %>
<% set old_colors = ["#c95edd", "#a2a6a7"] %>
<% set const_colors = ["#37bff2", "#169833", "#f6ab31", "#a2a6a7", "#c95edd", "#e85b4e", "#409fd4", "#7bbf00", "#ff2727", "#80f320", "#169833"] %>


{
    "abc": "appbalancer",
    "title": "yandex.ru << type >> signals" ,
    "description": "L7 balancer load signals",
    "type": "panel",
    "charts": [
        # 1st-2nd rows
        {
            "type": "graphic",
            "width": 2,
            "height": 2,
            "row": 1,
            "col": 1,
            "title": "yandex service_total requests",
            "stacked": false,
            "normalize": false,
            "signals": [
                <% for const in requests_const %>
                {
                    "title": "const << const >>",
                    "color": "<< const_colors[loop.index] >>",
                    "tag": "<< tags >>",
                    "host": "<<host>>",
                    "name": "const(<< const >>)"
                },
                <% endfor %>
                {
                    "title": "total",
                    "color": "<< colors[0] >>",
                    "tag": "<< tags >>",
                    "host": "<<host>>",
                    "name": "balancer_report-report-service_total-requests_summ"
                },
                <% if host_old %>
                {
                    "title": "total old",
                    "color": "<< old_colors[0] >>",
                    "tag": "<< tags >>",
                    "host": "<<host_old>>",
                    "name": "balancer_report-report-service_total-requests_summ"
                },
                <% endif %>
            ],
            "consts": []
        },
        {
            "type": "graphic",
            "width": 1,
            "height": 1,
            "row": 1,
            "col": 3,
            "title": "desync",
            "stacked": false,
            "normalize": false,
            "signals": [
                {
                    "title": "desync",
                    "color": "<< colors[0] >>",
                    "tag": "<< tags >>",
                    "host": "<<host>>",
                    "name": "balancer_report-worker-cpu_usage_time_desync_summ"
                },
                <% if host_old %>
                {
                    "title": "desync old",
                    "color": "<< old_colors[0] >>",
                    "tag": "<< tags >>",
                    "host": "<<host_old>>",
                    "name": "balancer_report-worker-cpu_usage_time_desync_summ"
                },
                <% endif %>
            ],
            "consts": []
        },
        {
            "type": "graphic",
            "width": 1,
            "height": 1,
            "row": 1,
            "col": 4,
            "title": "fails",
            "stacked": false,
            "normalize": false,
            "signals": [
                {
                    "title": "const 0.5",
                    "color": "<< colors[4] >>",
                    "tag": "<< tags >>",
                    "host": "<<host>>",
                    "name": "const(0.5)"
                },
                {
                    "title": "fails perc",
                    "color": "<< colors[0] >>",
                    "tag": "<< tags >>",
                    "host": "<<host>>",
                    "name": "perc(or(balancer_report-report-service_total-fail_summ, 0), balancer_report-report-service_total-requests_summ)"
                },
                <% if host_old %>
                {
                    "title": "fails perc old",
                    "color": "<< old_colors[0] >>",
                    "tag": "<< tags >>",
                    "host": "<<host_old>>",
                    "name": "perc(or(balancer_report-report-service_total-fail_summ, 0), balancer_report-report-service_total-requests_summ)"
                },
                <% endif %>
            ],
            "consts": []
        },
        {
            "width": 1,
            "height": 1,
            "row": 2,
            "col": 3,
            "type": "graphic",
            "title": "desync per cycle",
            "description": "",
            "yAxis": [
                {},
                {},
                {},
                {},
            ],
            "consts": [
            ],
            "minValue": 0,
            "stacked": false,
            "normalize": false,
            "signals": [
                {
                    "tag": "<< tags >>",
                    "host": "<< host >>",
                    "color": "<< colors[0] >>",
                    "name": "perc(balancer_report-worker-cpu_usage_time_desync_summ,balancer_report-worker-conts_cycle_summ)",
                    "title": "desync per cycle",
                },
                <% if host_old %>
                {
                    "tag": "<< tags >>",
                    "host": "<<host_old>>",
                    "color": "<< old_colors[0] >>",
                    "name": "perc(balancer_report-worker-cpu_usage_time_desync_summ,balancer_report-worker-conts_cycle_summ)",
                    "title": "desync per cycle old",
                },
                <% endif %>
            ],
        },
        {
            "width": 1,
            "height": 1,
            "row": 2,
            "col": 4,
            "type": "graphic",
            "title": "cycle duration",
            "description": "",
            "yAxis": [
                {},
                {},
                {},
                {},
            ],
            "consts": [
            ],
            "minValue": 0,
            "stacked": false,
            "normalize": false,
            "signals": [
                {
                    "tag": "<< tags >>",
                    "host": "<< host >>",
                    "color": "<< colors[0] >>",
                    "name": "quant(balancer_report-worker-conts_cycle_duration_hgram, 99)",
                    "title": "coro cycle duration (quant=99)",
                },
                <% if host_old %>
                {
                    "tag": "<< tags >>",
                    "host": "<<host_old>>",
                    "color": "<< old_colors[0] >>",
                    "name": "quant(balancer_report-worker-conts_cycle_duration_hgram, 99)",
                    "title": "coro cycle duration old (quant=99)",
                },
                <% endif %>
            ],
        },

        # 3rd-4th rows
        {
                "type": "graphic",
                "width": 2,
                "height": 2,
                "row": 3,
                "col": 1,
                "title": "cpu usage",
                "stacked": false,
                "normalize": false,
                "signals": [
                    {
                        "title": "p50",
                        "color": "<< colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "quant(balancer_report-worker-cpu_usage_hgram, 50)"
                    },
                    {
                        "title": "p70",
                        "color": "<< colors[1] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "quant(balancer_report-worker-cpu_usage_hgram, 70)"
                    },
                    {
                        "title": "p99",
                        "color": "<< colors[2] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "quant(balancer_report-worker-cpu_usage_hgram, 99)"
                    },
                    {
                        "title": "usage",
                        "color": "<< colors[3] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "perc(portoinst-cpu_usage_cores_tmmv, portoinst-cpu_guarantee_cores_tmmv)"
                    },
                    {
                        "title": "const 100",
                        "color": "<< colors[4] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "const(100)"
                    },
                    <% if host_old %>
                    {
                        "title": "p99 old",
                        "color": "<< old_colors[1] >>",
                        "tag": "<< tags >>",
                        "host": "<<host_old>>",
                        "name": "quant(balancer_report-worker-cpu_usage_hgram, 99)"
                    },
                    <% endif %>
                ],
                "consts": []
        },
        {
                "type": "graphic",
                "width": 1,
                "height": 1,
                "row": 3,
                "col": 3,
                "title": "portoinst memory usage",
                "stacked": false,
                "normalize": false,
                "signals": [
                    {
                        "title": "anon usage (gb)",
                        "color": "<< colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "portoinst-anon_usage_gb_tmmv"
                    },
                    <% if host_old %>
                    {
                        "title": "anon usage (gb) old",
                        "color": "<< old_colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host_old>>",
                        "name": "portoinst-anon_usage_gb_tmmv"
                    },
                    <% endif %>
                ],
                "consts": []
        },
        {
                "type": "graphic",
                "width": 1,
                "height": 1,
                "row": 3,
                "col": 4,
                "title": "cpu wait/throttled cores",
                "stacked": false,
                "normalize": false,
                "signals": [
                    {
                        "title": "cpu wait",
                        "color": "<< colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "perc(portoinst-cpu_wait_cores_tmmv, portoinst-cpu_guarantee_cores_tmmv)"
                    },
                    {
                        "title": "cpu throttled cores",
                        "color": "<< colors[1] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "perc(portoinst-cpu_throttled_cores_tmmv, portoinst-cpu_guarantee_cores_tmmv)"
                    },
                    <% if host_old %>
                    {
                        "title": "cpu wait old",
                        "color": "<< old_colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host_old>>",
                        "name": "perc(portoinst-cpu_wait_cores_tmmv, portoinst-cpu_guarantee_cores_tmmv)"
                    },
                    {
                        "title": "cpu throttled cores old",
                        "color": "<< old_colors[1] >>",
                        "tag": "<< tags >>",
                        "host": "<<host_old>>",
                        "name": "perc(portoinst-cpu_throttled_cores_tmmv, portoinst-cpu_guarantee_cores_tmmv)"
                    },
                    <% endif %>
                ],
                "consts": []
        },
        {
            "width": 1,
            "height": 1,
            "row": 4,
            "col": 3,
            "type": "graphic",
            "title": "switches/interrupts",
            "description": "",
            "yAxis": [
                {},
                {},
                {},
                {},
            ],
            "consts": [
            ],
            "minValue": 0,
            "stacked": false,
            "normalize": false,
            "signals": [
                {
                    "tag": "<< tags >>",
                    "host": "<< host >>",
                    "name": "div(quant(cpu-context_switches_hgram, 99), 5)",
                    "title": "Context switches/s quant=99",
                    "yAxis": 1,
                    "normalizable": false,
                },
                {
                    "tag": "<< tags >>",
                    "host": "<< host >>",
                    "name": "div(quant(cpu-interrupts_hgram, 99), 5)",
                    "title": "Interrupts/s quant=99",
                    "yAxis": 3,
                    "normalizable": false,
                },
                {
                    "tag": "<< tags >>",
                    "host": "<< host >>",
                    "name": "div(quant(cpu-soft_interrupts_hgram, 99), 5)",
                    "title": "Soft Interrupts/s quant=99",
                    "yAxis": 3,
                    "normalizable": false,
                },
            ],
        },
        {
            "width": 1,
            "height": 1,
            "row": 4,
            "col": 4,
            "type": "graphic",
            "title": "system load (quant=99)",
            "description": "",
            "yAxis": [
                {},
                {},
                {},
                {},
            ],
            "consts": [
            ],
            "minValue": 0,
            "stacked": false,
            "normalize": false,
            "signals": [
                {
                    "tag": "<< tags >>",
                    "host": "<< host >>",
                    "name": "sum(quant(cpu-usage_cores_hgram, 99), quant(cpu-wait_cores_hgram, 99))",
                    "title": "Active tasks (quant=99)",
                    "yAxis": 0,
                    "normalizable": false,
                },
                {
                    "tag": "<< tags >>",
                    "host": "<< host >>",
                    "name": "quant(loadavg-abs_xhhh, 99)",
                    "title": "Loadavg quant=99",
                    "yAxis": 0,
                    "normalizable": false,
                },
                {
                    "tag": "<< tags >>",
                    "host": "<< host >>",
                    "name": "div(quant(cpu-task_forks_hgram, 99), 5)",
                    "title": "Task forks/s quant=99",
                    "yAxis": 2,
                    "normalizable": false,
                }
            ],
        },

        # 5th row
        {
                "type": "graphic",
                "width": 2,
                "height": 1,
                "row": 5,
                "col": 1,
                "title": "page faults",
                "stacked": false,
                "normalize": false,
                "signals": [
                    {
                        "title": "major page faults",
                        "color": "<< colors[4] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "portoinst-major_page_faults_summ"
                    },
                    {
                        "title": "minor page faults",
                        "color": "<< colors[1] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "portoinst-minor_page_faults_summ"
                    },
                    <% if host_old %>
                    {
                        "title": "major page faults old",
                        "color": "<< old_colors[1] >>",
                        "tag": "<< tags >>",
                        "host": "<<host_old>>",
                        "name": "portoinst-major_page_faults_summ"
                    },
                    {
                        "title": "minor page faults old",
                        "color": "<< old_colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host_old>>",
                        "name": "portoinst-minor_page_faults_summ"
                    },
                    <% endif %>
                ],
                "consts": []
        },
        {
                "type": "graphic",
                "width": 0.5,
                "height": 1,
                "row": 5,
                "col": 3,
                "title": "pings",
                "stacked": false,
                "normalize": false,
                "signals": [
                    {
                        "title": "pings",
                        "color": "<< colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "balancer_report-report-<< pings >>-succ_summ"
                    },
                    <% if host_old %>
                    {
                        "title": "pings old",
                        "color": "<< old_colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host_old>>",
                        "name": "balancer_report-report-<< pings >>-succ_summ"
                    },
                    <% endif %>
                ],
                "consts": []
        },
        {
                "type": "graphic",
                "width": 0.5,
                "height": 1,
                "row": 5,
                "col": 3.5,
                "title": "retransmits",
                "stacked": false,
                "normalize": false,
                "signals": [
                    {
                        "title": "retransmits",
                        "color": "<< colors[1] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "netstat-tcp_retrans_segs_summ"
                    },
                    <% if host_old %>
                    {
                        "title": "retransmits old",
                        "color": "<< old_colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host_old>>",
                        "name": "netstat-tcp_retrans_segs_summ"
                    },
                    <% endif %>
                ],
                "consts": []
        },
        {
                "type": "graphic",
                "width": 0.5,
                "height": 1,
                "row": 5,
                "col": 4,
                "title": "ipkts/opkts eth0",
                "stacked": false,
                "normalize": false,
                "signals": [
                    {
                        "title": "ipkts",
                        "color": "<< colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "netstat-ipkts-eth0_summ"
                    },
                    {
                        "title": "opkts",
                        "color": "<< colors[1] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "netstat-opkts-eth0_summ"
                    }
                ],
                "consts": []
        },
        {
                "type": "graphic",
                "width": 0.5,
                "height": 1,
                "row": 5,
                "col": 4.5,
                "title": "ibytes/obytes eth0",
                "stacked": false,
                "normalize": false,
                "signals": [
                    {
                        "title": "obytes",
                        "color": "<< colors[0] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "netstat-obytes-eth0_summ"
                    },
                    {
                        "title": "ibytes",
                        "color": "<< colors[1] >>",
                        "tag": "<< tags >>",
                        "host": "<<host>>",
                        "name": "netstat-ibytes-eth0_summ"
                    }
                ],
                "consts": []
        },
    ]
}
