<commit_before>#output something like this
#http_metrics total=343243 inbound=102313 outbound=3423432 exe_download=23

@load global-ext
@load http-ext

export {
    global http_metrics: table[string] of count &default=0 &synchronized;
    global http_metrics_interval = +60sec;
    const http_metrics_log = open_log_file("http-ext-metrics");
}

event http_write_stats()
    {
    if (http_metrics["total"]!=0)
        {
        print http_metrics_log, fmt("http_metrics time=%.6f total=%d inbound=%d outbound=%d exe_download=%d",
            network_time(),
            http_metrics["total"],
            http_metrics["inbound"],
            http_metrics["outbound"],
            http_metrics["exe_download"]);
        clear_table(http_metrics);
        }
    schedule http_metrics_interval { http_write_stats() };
    }

event bro_init()
    {
    set_buf(http_metrics_log, F);
    schedule http_metrics_interval { http_write_stats() };
    }


event http_ext(id: conn_id, si: http_ext_session_info) &priority=-10
    {
    ++http_metrics["total"];
    if(is_local_addr(id$orig_h))
        ++http_metrics["outbound"];
    else
        ++http_metrics["inbound"];

    if (/\.exe$/ in si$uri)
        ++http_metrics["exe_download"];
    }
<commit_msg>add youtube/video stats<commit_after>#output something like this
#http_metrics total=343243 inbound=102313 outbound=3423432 exe_download=23

@load global-ext
@load http-ext

export {
    global http_metrics: table[string] of count &default=0 &synchronized;
    global http_metrics_interval = +60sec;
    const http_metrics_log = open_log_file("http-ext-metrics");
}

event http_write_stats()
    {
    if (http_metrics["total"]!=0)
        {
        print http_metrics_log, fmt("http_metrics time=%.6f total=%d inbound=%d outbound=%d video_download=%d youtube_watches=%d",
            network_time(),
            http_metrics["total"],
            http_metrics["inbound"],
            http_metrics["outbound"],
            http_metrics["video_download"],
            http_metrics["youtube_watches"]
            );
        clear_table(http_metrics);
        }
    schedule http_metrics_interval { http_write_stats() };
    }

event bro_init()
    {
    set_buf(http_metrics_log, F);
    schedule http_metrics_interval { http_write_stats() };
    }


event http_ext(id: conn_id, si: http_ext_session_info) &priority=-10
    {
    ++http_metrics["total"];
    if(is_local_addr(id$orig_h))
        ++http_metrics["outbound"];
    else
        ++http_metrics["inbound"];

    if (/\.(avi|flv|mp4|mpg)/ in si$uri)
        ++http_metrics["video_download"];
    if (/watch\?v=/ in si$uri && /youtube/ in si$host)
        ++http_metrics["youtube_watches"];

    }
{'fraction_non_alphanumeric': 0.1294378698224852, 'fraction_numerical': 0.021079881656804734, 'mean_word_length': 3.273301737756714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3583942', 'n_tokens_mistral': 919, 'n_tokens_neox': 874, 'n_words': 154}