feat: backoffice 사이트 트래픽 통계(방문·봇 크롤링) 추가
This commit is contained in:
1 parent
3854aef320
commit
01dd8e7522
33 files changed
+2253
-57
No files matched your search
@@ -0,0 +1,71 @@
|
||||
{% extends "sqladmin/layout.html" %}
|
||||
|
||||
{% block content_header %}
|
||||
<div class="row align-items-center">
|
||||
<div class="col">
|
||||
<h2 class="page-title">{{ title }}</h2>
|
||||
<div class="page-pretitle">{{ subtitle }}</div>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<div class="btn-group" role="group" aria-label="기간">
|
||||
{% for d in days_options %}
|
||||
<a href="?days={{ d }}" class="btn btn-sm {{ 'btn-primary' if d == period.days else 'btn-outline-primary' }}"
|
||||
{% if d == period.days %}aria-current="page"{% endif %}>{{ d }}일</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block tail %}
|
||||
<style>
|
||||
.traffic-chart { position: relative; height: 280px; }
|
||||
.traffic-num { font-variant-numeric: tabular-nums; }
|
||||
</style>
|
||||
<script type="application/json" id="traffic-charts">{{ charts | tojson }}</script>
|
||||
<script src="{{ chart_js_url }}"></script>
|
||||
<script>
|
||||
(function () {
|
||||
var el = document.getElementById("traffic-charts");
|
||||
if (!el || !window.Chart) return;
|
||||
var charts = JSON.parse(el.textContent);
|
||||
var ink = "#52514e", grid = "#e8e7e3", surface = "#ffffff";
|
||||
Chart.defaults.color = ink;
|
||||
Chart.defaults.font.family = getComputedStyle(document.body).fontFamily;
|
||||
|
||||
charts.forEach(function (c) {
|
||||
var canvas = document.getElementById(c.id);
|
||||
if (!canvas) return;
|
||||
var stacked = c.type === "stacked";
|
||||
var datasets = c.datasets.map(function (d) {
|
||||
if (stacked) {
|
||||
// 누적 막대: 조각 사이 2px 배경색 틈
|
||||
return { label: d.label, data: d.data, backgroundColor: d.color, borderColor: surface,
|
||||
borderWidth: { top: 2 }, borderSkipped: "bottom", maxBarThickness: 32 };
|
||||
}
|
||||
return { label: d.label, data: d.data, borderColor: d.color, backgroundColor: d.color,
|
||||
borderWidth: 2, pointRadius: 0, pointHoverRadius: 4, pointHitRadius: 12, tension: 0 };
|
||||
});
|
||||
new Chart(canvas, {
|
||||
type: stacked ? "bar" : "line",
|
||||
data: { labels: c.labels, datasets: datasets },
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
interaction: { mode: "index", intersect: false },
|
||||
plugins: {
|
||||
// 범례 키: 선 그래프는 짧은 선, 막대는 사각형
|
||||
legend: { position: "top", align: "start",
|
||||
labels: { usePointStyle: true, pointStyle: stacked ? "rect" : "line", pointStyleWidth: 18 } },
|
||||
tooltip: { mode: "index", intersect: false }
|
||||
},
|
||||
scales: {
|
||||
x: { stacked: stacked, grid: { display: false } },
|
||||
y: { stacked: stacked, beginAtZero: true, grid: { color: grid }, ticks: { precision: 0 } }
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,39 @@
|
||||
{% extends "sqladmin/traffic_base.html" %}
|
||||
{% from "sqladmin/traffic_macros.html" import num, when, stat_card, chart_card, table_card %}
|
||||
|
||||
{% block content %}
|
||||
{% set s = stats.summary %}
|
||||
<div class="col-12">
|
||||
<div class="row row-deck row-cards mb-2">
|
||||
{{ stat_card('총 봇 요청', num(s.total)) }}
|
||||
{{ stat_card('AI 봇 요청', num(s.ai_total)) }}
|
||||
{{ stat_card('봇 종류', num(s.bot_kinds)) }}
|
||||
{{ stat_card('마지막 크롤링', when(s.last_seen)) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ chart_card('일별 봇 요청 (용도별)', 'chart-crawlers-daily', stats.daily,
|
||||
(stats.purpose_labels.items() | list) + [('total', '합계')]) }}
|
||||
|
||||
{{ table_card('봇별', stats.bots,
|
||||
[('bot', '봇', false), ('company', '회사', false), ('purpose_label', '용도', false),
|
||||
('hits', '요청', true), ('last_seen', '마지막', false)],
|
||||
col='col-12 col-xl-7') }}
|
||||
|
||||
{{ table_card('많이 읽힌 경로 (상위 20)', stats.paths,
|
||||
[('path', '경로', false), ('kind', '종류', false), ('hits', '요청', true)],
|
||||
col='col-12 col-xl-5') }}
|
||||
|
||||
{{ table_card('robots.txt · sitemap.xml · llms.txt', stats.root_files,
|
||||
[('kind', '파일', false), ('bot', '봇', false), ('hits', '요청', true)],
|
||||
col='col-12 col-lg-5') }}
|
||||
|
||||
{{ table_card('목록 밖 봇 (기타, 상위 20)', stats.others,
|
||||
[('user_agent', 'User-Agent', false), ('hits', '요청', true), ('last_seen', '마지막', false)],
|
||||
col='col-12 col-lg-7') }}
|
||||
|
||||
{{ table_card('최근 크롤링 50건', stats.recent,
|
||||
[('at', '시각', false), ('bot', '봇', false), ('purpose_label', '용도', false),
|
||||
('path', '경로', false), ('status', '상태', false), ('ip', 'IP', false)],
|
||||
col='col-12') }}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,85 @@
|
||||
{# 사이트 트래픽 화면 공통 조각 #}
|
||||
|
||||
{% macro num(value) -%}{{ '{:,}'.format(value or 0) }}{%- endmacro %}
|
||||
|
||||
{% macro when(value) -%}{{ value.strftime('%m-%d %H:%M') if value else '-' }}{%- endmacro %}
|
||||
|
||||
{% macro stat_card(label, value, cls='') %}
|
||||
<div class="col-sm-6 col-lg-3">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="subheader">{{ label }}</div>
|
||||
<div class="h1 mb-1 traffic-num {{ cls }}">{{ value }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{# 차트 + "표로 보기"(색 대비가 낮은 계열이 있어 표를 항상 함께 둔다) #}
|
||||
{% macro chart_card(title, chart_id, daily, columns, col='col-12') %}
|
||||
<div class="{{ col }}">
|
||||
<div class="card">
|
||||
<div class="card-header"><h3 class="card-title">{{ title }}</h3></div>
|
||||
<div class="card-body">
|
||||
<div class="traffic-chart"><canvas id="{{ chart_id }}" role="img" aria-label="{{ title }}"></canvas></div>
|
||||
<details class="mt-3">
|
||||
<summary class="text-muted">표로 보기</summary>
|
||||
<div class="table-responsive mt-2">
|
||||
<table class="table table-sm table-vcenter card-table traffic-num">
|
||||
<thead><tr><th>날짜</th>{% for key, label in columns %}<th class="text-end">{{ label }}</th>{% endfor %}</tr></thead>
|
||||
<tbody>
|
||||
{% for d in daily | reverse %}
|
||||
<tr>
|
||||
<td>{{ d.date.strftime('%Y-%m-%d') }}</td>
|
||||
{% for key, label in columns %}<td class="text-end">{{ num(d[key]) }}</td>{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{# rows: dict 목록, columns: [(키, 제목, 숫자여부)] #}
|
||||
{% macro table_card(title, rows, columns, col='col-12 col-lg-6', empty='기록 없음') %}
|
||||
<div class="{{ col }}">
|
||||
<div class="card">
|
||||
<div class="card-header"><h3 class="card-title">{{ title }}</h3></div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-vcenter card-table">
|
||||
<thead>
|
||||
<tr>{% for key, label, numeric in columns %}<th class="{{ 'text-end' if numeric }}">{{ label }}</th>{% endfor %}</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in rows %}
|
||||
<tr>
|
||||
{% for key, label, numeric in columns %}
|
||||
{% if numeric %}
|
||||
<td class="text-end traffic-num">{{ num(row[key]) }}</td>
|
||||
{% elif key in ('last_seen', 'at') %}
|
||||
<td class="text-nowrap traffic-num">{{ when(row[key]) }}</td>
|
||||
{% else %}
|
||||
<td class="text-break" style="max-width: 420px;">{{ row[key] if row[key] is not none else '-' }}</td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="{{ columns | length }}" class="text-center text-muted">{{ empty }}</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro content_path(content_type, content_id) -%}
|
||||
{%- if content_type == 'video' -%}/video/{{ content_id }}
|
||||
{%- elif content_type == 'ssul' -%}/ssul/{{ content_id }}
|
||||
{%- elif content_type == 'p2v_f1' -%}/p2v/f1/{{ content_id }}
|
||||
{%- elif content_type == 'p2v_playreel' -%}/p2v/playreel/{{ content_id }}
|
||||
{%- else -%}{{ content_type }}/{{ content_id }}{%- endif -%}
|
||||
{%- endmacro %}
|
||||
@@ -0,0 +1,70 @@
|
||||
{% extends "sqladmin/traffic_base.html" %}
|
||||
{% from "sqladmin/traffic_macros.html" import num, when, stat_card, chart_card, table_card, content_path %}
|
||||
|
||||
{% block content %}
|
||||
{% set s = stats.summary %}
|
||||
<div class="col-12">
|
||||
<div class="row row-deck row-cards mb-2">
|
||||
{{ stat_card('오늘 방문자', num(stats.today_visitors)) }}
|
||||
{{ stat_card('페이지뷰', num(s.pageviews)) }}
|
||||
{{ stat_card('방문자', num(s.visitors)) }}
|
||||
{{ stat_card('마지막 방문', when(s.last_seen)) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ chart_card('일별 방문자 · 페이지뷰', 'chart-visits-daily', stats.daily,
|
||||
[('visitors', '방문자'), ('pageviews', '페이지뷰')]) }}
|
||||
|
||||
{{ table_card('페이지 종류', stats.page_kinds,
|
||||
[('label', '종류', false), ('views', '페이지뷰', true), ('visitors', '방문자', true)]) }}
|
||||
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="card">
|
||||
<div class="card-header"><h3 class="card-title">많이 본 콘텐츠 (상위 20)</h3></div>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-vcenter card-table">
|
||||
<thead><tr><th>경로</th><th class="text-end">페이지뷰</th><th class="text-end">방문자</th></tr></thead>
|
||||
<tbody>
|
||||
{% for c in stats.contents %}
|
||||
<tr>
|
||||
<td>{{ content_path(c.content_type, c.content_id) }}</td>
|
||||
<td class="text-end traffic-num">{{ num(c.views) }}</td>
|
||||
<td class="text-end traffic-num">{{ num(c.visitors) }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="3" class="text-center text-muted">기록 없음</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ table_card('유입 도메인 (상위 20)',
|
||||
[{'host': '직접·알 수 없음', 'views': s.direct_views, 'visitors': s.direct_visitors}] + stats.referrers,
|
||||
[('host', '도메인', false), ('views', '페이지뷰', true), ('visitors', '방문자', true)]) }}
|
||||
|
||||
{{ table_card('AI 엔진 유입', stats.ai_engines,
|
||||
[('engine', '엔진', false), ('views', '페이지뷰', true), ('referrer', 'referrer 로 판별', true), ('utm', 'utm 으로 판별', true)]) }}
|
||||
|
||||
{{ table_card('캠페인 (utm_source, 상위 20)', stats.utm,
|
||||
[('source', 'utm_source', false), ('views', '페이지뷰', true), ('visitors', '방문자', true)]) }}
|
||||
|
||||
{{ table_card('기기', stats.devices,
|
||||
[('label', '기기', false), ('views', '페이지뷰', true), ('visitors', '방문자', true)]) }}
|
||||
|
||||
{{ table_card('많이 본 경로 (상위 20)', stats.pages,
|
||||
[('path', '경로', false), ('views', '페이지뷰', true), ('visitors', '방문자', true)]) }}
|
||||
|
||||
<div class="col-12 col-lg-6">
|
||||
<div class="card">
|
||||
<div class="card-header"><h3 class="card-title">참고: 접근 로그의 첫 화면(/) 요청</h3></div>
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col"><div class="subheader">요청</div><div class="h2 traffic-num">{{ num(stats.log_landing.requests) }}</div></div>
|
||||
<div class="col"><div class="subheader">고유 IP 해시</div><div class="h2 traffic-num">{{ num(stats.log_landing.ip_hashes) }}</div></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user