<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="icon" href="{% static 'favicon.ico' %}" type="image/x-icon">
    <title>By-hosts {{ ctype }}-{{ service }}</title>
    <script src="https://yandex.st/jquery/2.0.3/jquery.min.js" type="text/javascript"></script>
    <script src="https://yandex.st/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link href="https://yandex.st/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
    <link href="{% static 'css/navigation.css' %}" rel="stylesheet" />
</head>
<style>
    .page-title {
        color: #8bc2f5;
        cursor: pointer;
    }
</style>
<script type="text/javascript">
    let sprs = ['ASEARCH' {% for sp in data.searchproxy %},'{{ sp }}'{% endfor %}];
    let iprs = ['ASEARCH' {% for ip in data.indexerproxy %},'{{ ip }}'{% endfor %}];
    let bes = ['ASEARCH' {% for be in data.backend %},'{{ be }}'{% endfor %}];
    let dms = ['ASEARCH' {% for dm in data.deploy_manager %},'{{ dm }}'{% endfor %}];
    const ctype= '{{ ctype }}';
    const service = '{{ service_mon }}';
    const service_title = '{{ service }}';
    const periods = [
        {hr: '25m', sec: ''},
        {hr: '24h', sec: '86400000'},
        {hr: 'week', sec: '604800000'}
    ];

    const timings = ['5', '10', '20', '30', '50', '100', '200', '500', '1000', '2000', 'inf'];
    const timings_kv = ['1', '2', '3', '5', '10', '20', '50', '100', '200', 'inf'];

    const wait_in_queue_timings = [0.001, 0.05, 0.075, 1, 'inf'];
    const age_levels = [1, 2, 3, 5, 10, 60, 5*60, 15*60, 30*60, 3600, 6*3600, 12*3600, 24*3600, 'inf'];

    const quantiles = [50, 90, 95, 97, 98, 99];
    const quantiles_high = [99, 999, 9997];

    const crash_signals = ['', '_1', '_4', '_6', '_9', '_11'];

    function get_iproxy_itype() {
        if (ctype === 'prestable') {
            return 'indexerproxydisc';
        }
        return 'indexerproxy';
    }

    function names_only(hosts) {
        let res = [];
        for (let i=0; i<hosts.length; ++i) {
            let ind = hosts[i].indexOf('.search');
            if (ind !== -1) {
                res.push(hosts[i].slice(0, ind));
            } else {
                res.push(hosts[i]);
            }
        }
        return res;
    }

    function get_times_siglist(base_signal_name) {
        let res = '';
        for (let i=0; i<timings.length; ++i) {
            if (i>0) { res += ','; }
            res += base_signal_name + timings[i] + ')';
        }
        return res;
    }
    function custom_times_siglist(base_signal_name, timings) {
        let res = '';
        for (let i=0; i<timings.length; ++i) {
            if (i>0) { res += ','; }
            res += base_signal_name + timings[i] + ')';
        }
        return res;
    }

    function gen_links(text, signals, itype, hosts, omit_sum) {
        let hr_sum = 'https://yasm.yandex-team.ru/chart/itype=' + itype + ';hosts=ASEARCH;graphs={' + signals + '}';
        let hr = 'https://yasm.yandex-team.ru/chart/itype=' + itype + ';hosts=' + hosts + ';graphs={' + signals + '}';
        let div = document.createElement('div');
        div.innerHTML = text + ' ';
        if (!omit_sum) {
            let link_sum = document.createElement('a');
            link_sum.href = hr_sum;
            link_sum.innerHTML = 'sum';
            link_sum.setAttribute('target', '_blank');
            div.appendChild(link_sum);
        }
        for (let i=0; i<periods.length; ++i) {
            let link_el = document.createElement('a');
            link_el.innerHTML = periods[i].hr;
            link_el.href = hr + '/?range=' + periods[i].sec;
            link_el.setAttribute('target', '_blank');
            link_el.style.marginLeft = '5px';
            div.appendChild(link_el);
        }
        return div;
    }

    function gen_links_block(links, itype, hosts_str, parent_el, omit_sum=false) {
        for (let i=0; i<links.length; ++i) {
            if (links[i] === '') {
                parent_el.appendChild(document.createElement('br'));
                continue;
            }
            let ldiv_el = gen_links(links[i].txt, links[i].sig,
                itype, hosts_str, omit_sum);
            parent_el.appendChild(ldiv_el);
        }
    }

    function gen_balancer_siglist(hosts) {
        let hosts_no_domen = names_only(hosts);
        let balancer_sig = '';
        for (let i=1; i<hosts_no_domen.length; ++i) {
            if (i>1) { balancer_sig += ','; }
            balancer_sig += 'balancer_log-errors-' + hosts_no_domen[i] + '_dmmm';
        }
        return balancer_sig;
    }

    function fill_searchproxy_links() {
        let el = document.getElementById('sproxy-links');
        let hosts_str = sprs.join(',');
        let serv_part = (service === '') ? '' : '-' + service;

        let bytimes_sig = get_times_siglist('hcount(saas_unistat-times-' + ctype + serv_part + '_dhhh,0,');
        let bytimes_sig_perc = get_times_siglist('hperc(saas_unistat-times-' + ctype + serv_part + '_dhhh,0,');

        let bytimes_cache = get_times_siglist('hcount(saas_unistat-times-' + ctype + '-cache' + serv_part + '_dhhh,0,');
        let bytimes_nocache = get_times_siglist('hcount(saas_unistat-times-' + ctype + '-chno' + serv_part + '_dhhh,0,');
        let cache_vs_nocache = 'hcount(saas_unistat-times-' + ctype + '-cache' + serv_part + '_dhhh,0,inf),hcount(saas_unistat-times-' + ctype + '-chno' + serv_part + '_dhhh,0,inf)';

        let wait_queue_sig = custom_times_siglist('hcount(saas_unistat-times-' + ctype + '-wait_in_queue' + serv_part + '_dhhh,0,', wait_in_queue_timings);

        let code_sig_base = 'saas_unistat-search-' + ctype + serv_part;

        gen_links_block([
            {txt:'ans by times', sig:bytimes_sig},
            {txt:'perc by times', sig:bytimes_sig_perc},
            '',
            {txt: '5xx', sig:code_sig_base+'-5xx_dmmm'},
            {txt: '4xx', sig:code_sig_base+'-4xx_dmmm'},
            {txt: 'timeouted', sig:code_sig_base+'-timeouted_dmmm'},
            {txt: 'not fetched', sig:code_sig_base+'-not-fetched_dmmm'},
            {txt: 'incomplete', sig:code_sig_base+'-incomplete_dmmm'},
            '',
            {txt:'cache by times', sig:bytimes_cache},
            {txt:'nocache by times', sig:bytimes_nocache},
            {txt:'cache vs nocache', sig:cache_vs_nocache},
            '',
            {txt:'empty results', sig:code_sig_base+'-count-zero_dmmm'},
            {txt:'empty results perc', sig:'perc('+code_sig_base+'-count-zero_dmmm,'+code_sig_base+'-200_dmmm)'},
            '',
            {txt:'wait in queue', sig:wait_queue_sig},
            ''
        ], 'searchproxy', hosts_str, el);

        let balancer_sig = gen_balancer_siglist(sprs);
        gen_links_block([
            {txt:'balancer errors', sig:balancer_sig},
            ''
        ], 'balancer', 'ASEARCH', el);

    }

    function fill_indexerproxy_links() {
        let el = document.getElementById('iproxy-links');
        let hosts_str = iprs.join(',');
        let itype = get_iproxy_itype();
        let serv_part = (service === '') ? '' : '-' + service;

        let bytimes_sig = get_times_siglist('hcount(saas_unistat-times-' + ctype + serv_part + '_dhhh,0,');
        let bytimes_sig_perc = get_times_siglist('hperc(saas_unistat-times-' + ctype + serv_part + '_dhhh,0,');
        let bytimes_def_sig = get_times_siglist('hcount(saas_unistat-times-default-' + ctype + serv_part + '_dhhh,0,');
        let bytimes_exp_sig = get_times_siglist('hcount(saas_unistat-times-export-' + ctype + serv_part + '_dhhh,0,');

        let byages_def_sig = custom_times_siglist('hcount(saas_unistat-ages-default-' + ctype + serv_part + '_dhhh,0,', age_levels);
        let byages_exp_sig = custom_times_siglist('hcount(saas_unistat-ages-export-' + ctype + serv_part + '_dhhh,0,', age_levels);

        let code_sig_base = 'saas_unistat-index-' + ctype + serv_part;

        gen_links_block([
            {txt:'ans by times', sig:bytimes_sig},
            {txt:'perc by times', sig:bytimes_sig_perc},
            '',
            {txt:'5xx', sig:code_sig_base+'-5xx_dmmm'},
            {txt:'4xx', sig:code_sig_base+'-4xx_dmmm'},
            {txt:'3xx', sig:code_sig_base+'-3xx_dmmm'},
            {txt:'206', sig:code_sig_base+'-206_dmmm'},
            {txt:'202', sig:code_sig_base+'-202_dmmm'},
            {txt:'duplicated', sig:code_sig_base+'-duplicated_dmmm'},
            '',
            {txt:'default by times', sig:bytimes_def_sig},
            {txt:'export by times', sig:bytimes_exp_sig},
            {txt:'default by ages', sig:byages_def_sig},
            {txt:'export by ages', sig:byages_exp_sig},
            '',
            {txt:'queue docs', sig:'iproxy_infoserver-'+ctype+serv_part+'-queue_docs_tmmv'},
            {txt:'queue kbytes', sig:'iproxy_infoserver-'+ctype+serv_part+'-queue_kbytes_tmmv'},
            {txt:'tasks count', sig:'iproxy_infoserver-'+ctype+'-common-tasks_count_tmmv'},
            ''
        ], itype, hosts_str, el);

        let balancer_sig = gen_balancer_siglist(iprs);
        gen_links_block([
            {txt:'balancer errors', sig:balancer_sig},
            ''
        ], 'balancer', 'ASEARCH', el);
    }

    function fill_backend_links() {
        if (bes.length <= 1 && service !== '') {
            return;
        }
        let el = document.getElementById('backend-links');
        let hosts_str = bes.join(',');
        let serv_part = (service === '') ? '' : '-' + service;

        let avg_sig = 'havg(saas_unistat-search-times-' + ctype + serv_part + '-full_dhhh)';
        let quant_sig = custom_times_siglist('quant(saas_unistat-search-times-' + ctype + serv_part + '-full_dhhh,', quantiles);
        let quant_sig_high = custom_times_siglist('quant(saas_unistat-search-times-' + ctype + serv_part + '-full_dhhh,', quantiles_high);

        let bytimes_sig = get_times_siglist('hcount(saas_unistat-search-times-' + ctype + serv_part + '-full_dhhh,0,');
        let bytimes_sig_perc = get_times_siglist('hperc(saas_unistat-search-times-' + ctype + serv_part + '-full_dhhh,0,');
        let bytimes_sig_work = get_times_siglist('hcount(saas_unistat-search-times-' + ctype + serv_part + '-work_dhhh,0,');
        let bytimes_sig_queue = get_times_siglist('hcount(saas_unistat-search-times-' + ctype + serv_part + '-queue_dhhh,0,');
        let bytimes_sig_df = get_times_siglist('hcount(saas_unistat-search-times-' + ctype + '-dfda' + serv_part + '-full_dhhh,0,');
        let bytimes_sig_cache = get_times_siglist('hcount(saas_unistat-search-times-' + ctype + '-cache' + serv_part + '-full_dhhh,0,');
        let bytimes_sig_nocache = get_times_siglist('hcount(saas_unistat-search-times-' + ctype + '-chno' + serv_part + '-full_dhhh,0,');

        let cache_vs_nocache = 'hcount(saas_unistat-search-times-' + ctype + '-cache' + serv_part + '-full_dhhh,0,inf),hcount(saas_unistat-search-times-' + ctype + '-chno' + serv_part + '-full_dhhh,0,inf)';
        let zero_vs_nonzero = 'saas_unistat-backend-search-' + ctype + serv_part + '-count-zero_dmmm,saas_unistat-backend-search-' + ctype + serv_part + '-count-nonzero_dmmm';
        let search_fail_on_zero = 'saas_unistat-backend-search-' + ctype + serv_part + '-fail-on-zero_dmmm';
        let search_result_0 = 'saas_unistat-backend-search-' + ctype + serv_part + '-result-fail_dmmm';
        let search_unavail = 'saas_unistat-backend-search-' + ctype + serv_part + '-error_dmmm,saas_unistat-backend-search-' + ctype + serv_part + '-unavailable_dmmm';
        let search_unans = 'saas_unistat-backend-source-' + ctype + serv_part + '-unanswers_dmmm';

        gen_links_block([
            {txt:'replytimes avg', sig:avg_sig},
            {txt:'replytimes medians', sig:quant_sig},
            {txt:'replytimes high med', sig:quant_sig_high},
            '',
            {txt:'search-full by times', sig:bytimes_sig},
            {txt:'search perc by times', sig:bytimes_sig_perc},
            {txt:'search-work by times', sig:bytimes_sig_work},
            {txt:'search-queue by times', sig:bytimes_sig_queue},
            {txt:'search-fetch by times', sig:bytimes_sig_df},
            '',
            {txt:'zero&nonzero count', sig:zero_vs_nonzero},
            {txt:'fail on zero', sig:search_fail_on_zero},
            {txt:'search err (result=0)', sig:search_result_0},
            {txt:'search unavailable', sig:search_unavail},
            {txt:'source unanswers', sig:search_unans},
            '',
            {txt:'search-cache by times', sig:bytimes_sig_cache},
            {txt:'search-nocache by times', sig:bytimes_sig_nocache},
            {txt:'cache vs nocache', sig:cache_vs_nocache},
            ''
        ], 'rtyserver', hosts_str, el, (service === ''));

        let bytimes_ind_sig = get_times_siglist('hcount(saas_unistat-index-times-' + ctype + serv_part + '_dhhh,0,');
        let base_code_ind_sig = 'saas_unistat-backend-index-' + ctype + serv_part;

        gen_links_block([
            {txt:'index by times', sig:bytimes_ind_sig},
            {txt:'index 5xx', sig:base_code_ind_sig+'-5xx_dmmm'},
            {txt:'index 503', sig:base_code_ind_sig+'-503_dmmm'},
            {txt:'index 4xx', sig:base_code_ind_sig+'-4xx_dmmm'},
            {txt:'index 400', sig:base_code_ind_sig+'-400_dmmm'},
            {txt:'index 304', sig:base_code_ind_sig+'-304_dmmm'},
            {txt:'index 200', sig:base_code_ind_sig+'-200_dmmm'},
            ''
        ], 'rtyserver', hosts_str, el, (service === ''));

        const INFS_PREF = 'rty_infoserver' + serv_part + '-' + ctype;
        let infs_queues_sig = INFS_PREF + '-queue_mem_tmmv,' + INFS_PREF + '-queue_disk_tmmv';
        let infs_merger_tasks_sig = INFS_PREF + '-merger_tasks_tmmv';
        let infs_sources_sig = INFS_PREF + '-search_sources_count_tmmv';
        let infs_sources_max_sig = INFS_PREF + '-search_sources_count_txxv';
        let infs_doccount_tmp_sig = INFS_PREF + '-docs_in_memory_indexes_tmmv,' + INFS_PREF + '-docs_in_disk_indexers_tmmv';
        let infs_doccount_sig = INFS_PREF + '-docs_in_final_indexes_tmmv,' + infs_doccount_tmp_sig;
        let infs_index_size_sig = INFS_PREF + '-index_size_gb_max_txxv';
        let infs_segment_size_sig = INFS_PREF + '-segment_size_gb_max_txxv';
        let infs_files_cnt_sig = INFS_PREF + '-index_files_cnt_max_txxv,aver(' + INFS_PREF + '-index_files_cnt_tvvv)';
        let infs_age_sig = 'aver(' + INFS_PREF + '-age_tvvv)';

        let infs_archive_cnt_sig = INFS_PREF + '-archive_alive_count_tmmv,' + INFS_PREF + '-archive_removed_count_tmmv';
        const arch_digits = ['01', '03', '04', '05', '06', '07'];
        let infs_arch_docs_stat = '';
        let infs_arch_parts_stat = '';
        for (let i=0; i<arch_digits.length; ++i) {
            if (i>0) {
                infs_arch_docs_stat += ',';
                infs_arch_parts_stat += ',';
            }
            infs_arch_docs_stat += INFS_PREF + '-archive-opt-docs-02-' + arch_digits[i] + '_tmmv';
            infs_arch_parts_stat += INFS_PREF + '-archive-opt-parts-02-' + arch_digits[i] + '_tmmv';
        }

        gen_links_block([
            {txt:'indexing queues', sig:infs_queues_sig},
            {txt:'merger tasks', sig:infs_merger_tasks_sig},
            {txt:'search sources sum', sig:infs_sources_sig},
            {txt:'search sources max', sig:infs_sources_max_sig},
            {txt:'docs count', sig:infs_doccount_sig},
            {txt:'docs count tmp', sig:infs_doccount_tmp_sig},
            {txt:'index size max', sig:infs_index_size_sig},
            {txt:'segment size max', sig:infs_segment_size_sig},
            {txt:'files cnt', sig:infs_files_cnt_sig},
            {txt:'archive counts', sig:infs_archive_cnt_sig},
            {txt:'archive docs stat', sig:infs_arch_docs_stat},
            {txt:'archive parts stat', sig:infs_arch_parts_stat},
            {txt:'last doc age', sig:infs_age_sig},
            ''
        ], 'rtyserver', hosts_str, el, (service === ''));

        let infs_mem_sig = 'aver(' + INFS_PREF + '-mem_size_real_tvvv)';
        let infs_mem_virt_sig = 'aver(' + INFS_PREF + '-mem_size_virtual_tvvv)';
        let infs_mem_ratio_sig = INFS_PREF + '-mem_lock_ratio_txxv';
        let infs_mems_anon_sig = INFS_PREF + '-mem_vm_locked_gb_txxv,' + INFS_PREF + '-mem_rss_anon_gb_txxv,' + INFS_PREF + '-mem_rss_file_gb_txxv';
        let infs_cpu_sig = 'aver(' + INFS_PREF + '-cpu_load_user_tvvv)';

        let crashes_sig = '';
        for (let i=0; i<crash_signals.length; ++i) {
            if (i>0) { crashes_sig += ','; }
            crashes_sig += 'crashes_log-saas_' + ctype + serv_part + '_exit_signal' + crash_signals[i] + '_mmmm';
        }
        gen_links_block([
            {txt:'instances memory', sig:infs_mem_sig},
            {txt:'inst virtual mem', sig:infs_mem_virt_sig},
            {txt:'anon&locked mem', sig:infs_mems_anon_sig},
            {txt:'mem limit ratio', sig:infs_mem_ratio_sig},
            {txt:'instances cpu', sig:infs_cpu_sig},
            {txt:'crashes', sig:crashes_sig},
            ''
        ], 'rtyserver', hosts_str, el, (service === ''));

        if (service !== '') {
            let ipr_hosts_str = iprs.join(',');
            let ipr_itype = get_iproxy_itype();
            let hosts_no_domen = names_only(bes);
            let ipr_queues_sig = '';
            for (let i=1; i<hosts_no_domen.length; ++i) {
                if (i>1) { ipr_queues_sig += ','; }
                ipr_queues_sig += 'iproxy_infoserver-queue_docs-h-' + hosts_no_domen[i] + '_tmmv';
            }
            gen_links_block([
                {txt:'queues from iproxy', sig:ipr_queues_sig},
                ''
            ], ipr_itype, ipr_hosts_str, el, (service === ''));
        }

        let replics_respond_sig = 'aver(dm_dashboard-' + ctype + serv_part + '-respond_replics_tvvv)';
        let replics_inconsist_sig = 'aver(dm_dashboard-' + ctype + serv_part + '-inconsistent-ratio_tvvv)'
            + ',aver(dm_dashboard-' + ctype + serv_part + '-size-inconsistent-ratio_tvvv)';
        let replics_doccount_sig = 'dm_dashboard-' + ctype + serv_part + '-min-replica-docs_txxv,dm_dashboard-' + ctype + serv_part + '-max-replica-docs_txxv';
        let replics_size_sig = 'dm_dashboard-' + ctype + serv_part + '-min-replica-size-gb_txxv,dm_dashboard-' + ctype + serv_part + '-max-replica-size-gb_txxv';
        let alive_bes_cnt = 'aver(dm_broadcast-alives-' + ctype + serv_part + '_tvvv)';
        let downs_bes_cnt = 'aver(dm_broadcast-downs-' + ctype + serv_part + '_tvvv)';

        gen_links_block([
            {txt:'min replics respond', sig:replics_respond_sig},
            {txt:'inconsistent replics ratio', sig:replics_inconsist_sig},
            {txt:'alive backends cnt', sig:alive_bes_cnt},
            {txt:'down backends cnt', sig:downs_bes_cnt},
            {txt:'docs in replica', sig:replics_doccount_sig},
            {txt:'replica size gb', sig:replics_size_sig},
            ''
        ], 'deploymanager', 'ASEARCH', el, true);
    }

    function fill_dm_links() {
        document.getElementById('sp-th').innerHTML = 'Deploy_manager';
        document.getElementById('ip-th').innerHTML = '';
        document.getElementById('be-th').innerHTML = '';

        let el = document.getElementById('sproxy-links');
        let hosts_str = dms.join(',');

        let sig_all_times = get_times_siglist(
            'hcount(saas_unistat-requests-' + ctype +'-all_dhhh,0,' );
        gen_links_block([
            {txt: 'all by times', sig: sig_all_times}
        ], 'deploymanager', hosts_str, el);

        let sig_err = 'diff(hcount(saas_unistat-requests-' + ctype +
            '-all_dhhh),hcount(saas_unistat-requests-' + ctype +'-ok_dhhh))';
        gen_links_block([
            {txt: 'errors', sig: sig_err}
        ], 'deploymanager', hosts_str, el);

        let requests = [
            'activate_slots', 'add_endpointsets', 'allocate_same_slots', 'allocate_slots_replicas',
            'broadcast', 'check_configs', 'cluster_control', 'ctypes',
            'dashboard', 'deploy', 'deploy_info',
            'fml_ops', 'free_slots',
            'get_cluster_map', 'get_conf', 'get_files', 'get_services', 'get_sla_table',
            'list_conf', 'modify_searchmap', 'modify_tags_info', 'ping',
            'process_alerts', 'process_sla_description', 'process_storage',
            'restore_index', 'release_endpointsets', 'release_slots',
            'secret_key', 'set_conf', 'slots_by_tag',
            'total_alerts', 'using_slots'
        ];
        let main_getters = [
            'broadcast', 'check_configs', 'ctypes',
            'dashboard', 'deploy_info', 'docfetcher', 'free_slots',
            'get_cluster_map', 'get_conf', 'get_files', 'get_services', 'get_sla_table',
            'list_conf',
            'process_alerts', 'process_sla_description', 'process_storage',
            'secret_key', 'slots_by_tag',
            'using_slots'
        ];
        let sigs_cnt = [];
        let sigs_avg = [];
        let sigs_q95 = [];

        let sigs_other_cnt = [];
        let sigs_other_avg = [];
        let sigs_other_q95 = [];
        for (let i=0; i<requests.length; ++i) {
            sigs_cnt.push(
                'hcount(saas_unistat-requests-' + ctype + '-' + requests[i] +'_dhhh)');
            sigs_avg.push(
                'havg(saas_unistat-requests-' + ctype + '-' + requests[i] +'_dhhh)');
            sigs_q95.push(
                'quant(saas_unistat-requests-' + ctype + '-' + requests[i] +'_dhhh,95)');
            let req = requests[i];
            if (req !== 'ping' && main_getters.indexOf(req) === -1) {
                sigs_other_cnt.push(
                    'hcount(saas_unistat-requests-' + ctype + '-' + req +'_dhhh)');
                sigs_other_avg.push(
                    'havg(saas_unistat-requests-' + ctype + '-' + req +'_dhhh)');
                sigs_other_q95.push(
                    'quant(saas_unistat-requests-' + ctype + '-' + req +'_dhhh,95)');
            }
        }
        let sigs_mg_cnt = [];
        let sigs_mg_avg = [];
        let sigs_mg_q95 = [];
        for (let i=0; i<main_getters.length; ++i) {
            sigs_mg_cnt.push(
                'hcount(saas_unistat-requests-' + ctype + '-' + main_getters[i] +'_dhhh)');
            sigs_mg_avg.push(
                'havg(saas_unistat-requests-' + ctype + '-' + main_getters[i] +'_dhhh)');
            sigs_mg_q95.push(
                'quant(saas_unistat-requests-' + ctype + '-' + main_getters[i] +'_dhhh,95)');
        }
        let sig_all_cnts = sigs_cnt.join(',');
        gen_links_block([
            {txt: 'cnts by url', sig: sig_all_cnts},
            {txt: 'avg_time by url', sig: sigs_avg.join(',')},
            {txt: 'q95_time by url', sig: sigs_q95.join(',')},
            ''
        ], 'deploymanager', hosts_str, el);

        gen_links_block([
            {txt: 'frequent gets cnt', sig: sigs_mg_cnt.join(',')},
            {txt: 'avg_time getters', sig: sigs_mg_avg.join(',')},
            {txt: 'q95_time getters', sig: sigs_mg_q95.join(',')},
            ''
        ], 'deploymanager', hosts_str, el);

        gen_links_block([
            {txt: 'other reqs cnt', sig: sigs_other_cnt.join(',')},
            {txt: 'avg_time other', sig: sigs_other_avg.join(',')},
            {txt: 'q95_time other', sig: sigs_other_q95.join(',')},
            ''
        ], 'deploymanager', hosts_str, el);
        let dm_fqdn = (ctype === 'prestable') ? 'saas-dm-test' : 'saas-dm';
        let dm_bal = 'https://yasm.yandex-team.ru/template/panel/balancer_common_panel/fqdn=' + dm_fqdn + '.yandex.net;itype=balancer;ctype=prestable,prod;metaprj=balancer;locations=man,sas,vla;prj=saas-dm;signal=service_total;';
        {
            let link_dm_bal = document.createElement('a');
            link_dm_bal.href = dm_bal;
            link_dm_bal.innerHTML = 'balancer panel';
            link_dm_bal.setAttribute('target', '_blank');
            el.appendChild(link_dm_bal);
        }
        el.appendChild(document.createElement('br'));
        {
            let link_zk = document.createElement('a');
            link_zk.href = 'https://yasm.yandex-team.ru/chart/itype=zookeeper;hosts=ASEARCH;graphs='
                + '%7Bconst(0),zookeeper-zk_avg_latency_tmmv,const(50)%7D,%7Bconst(0),zookeeper-zk_synced_followers_tmmv,zookeeper-zk_followers_tmmv,counter-instance_tmmv%7D,'
                + '%7Bconst(0),zookeeper-zk_znode_count_tmmv%7D,%7Bconst(0),zookeeper-zk_ephemerals_count_tmmv%7D,%7Bconst(0),zookeeper-zk_approximate_data_size_tmmv%7D'
                + ';ctype=prod;prj=saas/?range=7200000';
            link_zk.innerHTML = 'zookeeper';
            link_zk.setAttribute('target', '_blank');
            el.appendChild(link_zk);
        }
    }

    $(document).ready( function() {
        if (service_title === 'deploy_manager') {
            fill_dm_links();
        } else {
            fill_searchproxy_links();
            fill_indexerproxy_links();
            fill_backend_links();
        }
    });
</script>
{% include "navigation.html" %}
{% include "nav_ctype.html" %}
<body>
<div style="border-bottom: 2px solid #eddde0">
    <button class="btn-main-link"><a href="{% url 'main' %}" class="main-link">SAAS</a></button>
    <span class="dropdown"><span class="page-title" data-toggle="dropdown">Monitor-hosts<span class="caret"></span></span>
        <ul id="nav-screens-menu" class="dropdown-menu">
            <li><a href="{% url 'deploy_page' %}?service={{ service }}&ctype={{ ctype }}">Cluster & deploy</a></li>
            <li><a href="{% url 'cluster_total' %}?service={{ service }}&ctype={{ ctype }}">Cluster hardware</a></li>
            <li><a href="{% url 'service_info' %}?service={{ service }}&ctype={{ ctype }}">Service conf</a></li>
            <li><a href="{% url 'monitor_hosts' %}?service={{ service }}&ctype={{ ctype }}">Monitor hosts</a></li>
            <li><a href="{% url 'monitor_gui' %}?service={{ service }}&ctype={{ ctype }}">Monitor</a></li>
        </ul></span>
    <span id="ctype_selector" style="font-weight:bold">{{ ctype }}</span><span class="caret"></span>
    <span class="nav-service-link" style="margin-left:10px">{{ service }}</span>
</div>
<table>
    <tr>
        <td style="vertical-align: top">
            <div style='transform: rotate(270deg)' hidden>Services</div>
            <div id="nav-services-list"></div>
        </td>
        <td style="vertical-align:top">
<table>
    <thead>
        <tr>
            <th id="sp-th">Searchproxy</th>
            <th id="ip-th">Indexerproxy</th>
            <th id="be-th">Backend</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td id="sproxy-links" style="vertical-align: top"></td>
            <td id="iproxy-links" style="vertical-align: top"></td>
            <td id="backend-links" style="vertical-align: top"></td>
        </tr>
    </tbody>
</table>
        </td>
    </tr>
</table>
</body>
</html>
