Squid
設定¶
squid-exporter で Squid のメトリクスデータを収集します。DataKit は prom コレクターを使って squid-exporter が送信したメトリクスデータを受信します。
Squid の公開メトリクス¶
-
squid-exporter をダウンロードする
-
squid-exporterを実行する
squid-exporter は 9301 ポートで Prometheus 形式のメトリクスデータを公開します
コレクター設定¶
prom.conf.sample を squid.conf にコピーします
設定ファイル squid.conf を調整します
## Exporter URLs.
urls = ["http://127.0.0.1:9301/metrics"]
## Stream Size.
## The source stream segmentation size, (defaults to 1).
## 0 source stream undivided.
# stream_size = 1
## Unix Domain Socket URL. Using socket to request data when not empty.
uds_path = ""
## Ignore URL request errors.
ignore_req_err = false
## Collector alias.
source = "squid-prom"
...
メトリクス¶
| メトリクス | 説明 | 単位 |
|---|---|---|
client_http_errors_total |
クライアントの HTTP リクエストで返されたエラー(4xx/5xx)の総回数 | 回 |
client_http_hit_kbytes_out_bytes_total |
クライアントの HTTP ヒット(HIT)時に外向きへ送信したトラフィック | KB |
client_http_hits_total |
クライアントの HTTP リクエストがキャッシュヒットした総回数 | 回 |
client_http_kbytes_in_kbytes_total |
クライアントの HTTP リクエスト時にクライアントから受信したトラフィック | KB |
client_http_kbytes_out_kbytes_total |
クライアントの HTTP リクエスト時にクライアントへ送信したトラフィック | KB |
client_http_requests_total |
クライアントの HTTP リクエスト総回数 | 回 |
exporter_build_info |
Squid exporter のビルド情報(バージョン、リビジョン番号など) | なし |
info_Available_number_of_file_descriptors |
現在利用可能なファイルディスクリプタ数 | 個 |
info_Average_HTTP_requests_per_minute_since_start |
起動以来の 1 分あたり平均 HTTP リクエスト数 | 回/分 |
info_Average_ICP_messages_per_minute_since_start |
起動以来の 1 分あたり平均 ICP メッセージ数 | 回/分 |
info_CPU_Time |
Squid プロセスが累積で消費した CPU 時間 | 秒 |
info_CPU_Usage |
現在の瞬間的な CPU 使用率 | % |
info_CPU_Usage_5_minute_avg |
直近 5 分間の平均 CPU 使用率 | % |
info_CPU_Usage_60_minute_avg |
直近 60 分間の平均 CPU 使用率 | % |
info_Disk_hits_as_pct_of_hit_requests_5min |
直近 5 分間のキャッシュヒットのうちディスクヒットの割合 | % |
info_Disk_hits_as_pct_of_hit_requests_60min |
直近 60 分間のキャッシュヒットのうちディスクヒットの割合 | % |
info_Files_queued_for_open |
ファイルを開く待ち行列の長さ | 個 |
info_Hits_as_pct_of_all_requests_5min |
直近 5 分間のヒット率(ヒット/総リクエスト) | % |
info_Hits_as_pct_of_all_requests_60min |
直近 60 分間のヒット率 | % |
info_Hits_as_pct_of_bytes_sent_5min |
直近 5 分間のヒットトラフィックが送信総トラフィックに占める割合 | % |
info_Hits_as_pct_of_bytes_sent_60min |
直近 60 分間のヒットトラフィックが送信総トラフィックに占める割合 | % |
info_Hot_Object_Cache_Items |
ホットオブジェクトのキャッシュエントリ数 | 個 |
info_Largest_file_desc_currently_in_use |
現在使用中の最大ファイルディスクリプタ番号 | 個 |
info_Maximum_Resident_Size |
Squid プロセスの最大常駐メモリ | KB |
info_Maximum_number_of_file_descriptors |
システムが許可する最大ファイルディスクリプタ数 | 個 |
info_Mean_Object_Size |
キャッシュオブジェクトの平均サイズ | KB |
info_Memory_hits_as_pct_of_hit_requests_5min |
直近 5 分間のキャッシュヒットのうちメモリヒットの割合 | % |
info_Memory_hits_as_pct_of_hit_requests_60min |
直近 60 分間のキャッシュヒットのうちメモリヒットの割合 | % |
info_Number_of_HTCP_messages_received |
受信した HTCP メッセージ総数 | 回 |
info_Number_of_HTCP_messages_sent |
送信した HTCP メッセージ総数 | 回 |
info_Number_of_HTTP_requests_received |
受信した HTTP リクエスト総数 | 回 |
info_Number_of_ICP_messages_received |
受信した ICP メッセージ総数 | 回 |
info_Number_of_ICP_messages_sent |
送信した ICP メッセージ総数 | 回 |
info_Number_of_clients_accessing_cache |
現在キャッシュにアクセスしているクライアント数 | 個 |
info_Number_of_file_desc_currently_in_use |
現在使用中のファイルディスクリプタ数 | 個 |
info_Number_of_queued_ICP_replies |
返信待ちの ICP キュー長 | 個 |
info_Request_failure_ratio |
リクエスト失敗率(失敗/総リクエスト) | % |
info_Requests_given_to_unlinkd |
unlinkd に渡して削除したリクエスト数 | 回 |
info_Reserved_number_of_file_descriptors |
予約済みのファイルディスクリプタ数 | 個 |
info_Select_loop_called |
select/poll ループの呼び出し回数 | 回 |
info_Storage_Mem_capacity |
メモリキャッシュの最大容量 | KB |
info_Storage_Mem_size |
メモリキャッシュの現在使用容量 | KB |
info_Storage_Swap_capacity |
ディスクキャッシュの最大容量 | KB |
info_Storage_Swap_size |
ディスクキャッシュの現在使用容量 | KB |
info_StoreEntries |
現在の Store エントリ総数 | 個 |
info_StoreEntries_with_MemObjects |
メモリオブジェクトを持つ Store エントリ数 | 個 |
info_Store_Disk_files_open |
現在開いているディスクファイル数 | 個 |
info_Total_accounted |
Squid プロセスが確保したメモリ総量 | KB |
info_UP_Time |
Squid プロセスの起動後の稼働時間 | 秒 |
info_memPoolAlloc_calls |
memPool の割り当て呼び出し回数 | 回 |
info_memPoolFree_calls |
memPool の解放呼び出し回数 | 回 |
info_on_disk_objects |
現在ディスクに保存されているオブジェクト数 | 個 |
info_service |
Squid サービス状態フラグ(1=稼働中、0=停止) | なし |
server_all_errors_total |
すべてのバックエンド(HTTP/FTP/その他)エラー総回数 | 回 |
server_all_kbytes_in_kbytes_total |
すべてのバックエンドの受信トラフィック | KB |
server_all_kbytes_out_kbytes_total |
すべてのバックエンドの送信トラフィック | KB |
server_all_requests_total |
すべてのバックエンドのリクエスト総回数 | 回 |
server_ftp_errors_total |
FTP バックエンドのエラー回数 | 回 |
server_ftp_kbytes_in_kbytes_total |
FTP バックエンドの受信トラフィック | KB |
server_ftp_kbytes_out_kbytes_total |
FTP バックエンドの送信トラフィック | KB |
server_ftp_requests_total |
FTP バックエンドのリクエスト回数 | 回 |
server_http_errors_total |
HTTP バックエンドのエラー回数 | 回 |
server_http_kbytes_in_kbytes_total |
HTTP バックエンドの受信トラフィック | KB |
server_http_kbytes_out_kbytes_total |
HTTP バックエンドの送信トラフィック | KB |
server_http_requests_total |
HTTP バックエンドのリクエスト回数 | 回 |
server_other_errors_total |
その他プロトコルのバックエンドエラー回数 | 回 |
server_other_kbytes_in_kbytes_total |
その他プロトコルのバックエンド受信トラフィック | KB |
server_other_kbytes_out_kbytes_total |
その他プロトコルのバックエンド送信トラフィック | KB |
server_other_requests_total |
その他プロトコルのバックエンドリクエスト回数 | 回 |
swap_files_cleaned_total |
クリーンアップされた swap ファイル総数 | 個 |
swap_ins_total |
swap in(ディスク → メモリ)の回数 | 回 |
swap_outs_total |
swap out(メモリ → ディスク)の回数 | 回 |
up |
exporter が Squid メトリクスの取得に成功したときは 1、失敗時は 0 | なし |
ログ¶
ログ収集¶
squid のデフォルトログは /var/log/squid ディレクトリに出力されます:
- access.log: アクセスログ
- cache.log: キャッシュログ
/usr/local/datakit/conf.d/log ディレクトリに移動し、次のコマンドを実行します:
設定ファイルを調整します:
[[inputs.logging]]
# List of log files, supports batch specification using glob patterns.
# It is recommended to use absolute paths and specify file extensions.
# Narrow the scope as much as possible to avoid collecting unexpected files.
logfiles = [
"/var/log/squid/access.log",
"/var/log/squid/cache.log"
]
## Socket currently supports two protocols: tcp/udp. It is recommended to use internal
## network ports for security.
sockets = [
#"tcp://0.0.0.0:9540",
#"udp://0.0.0.0:9541",
]
# File path filtering using glob patterns, any file matching these patterns will not be collected
ignore = [""]
# Logging source, defaults to 'default' if empty
source = "squid"
...
ログ解析¶
grok(_, "%{NUMBER:timestamp:float}%{SPACE}%{INT:response_time:int}%{SPACE}%{IP:client_ip}%{SPACE}%{WORD:squid_result}/%{INT:http_status:int}%{SPACE}%{INT:bytes:int}%{SPACE}%{WORD:method}%{SPACE}%{NOTSPACE:uri}%{SPACE}-%{SPACE}(?:%{WORD:hier_status}/%{NOTSPACE:hier_ip}|%{NOTSPACE:hier_full})%{SPACE}%{GREEDYDATA:content_type}")
client_ip = get_key("client_ip")
if client_ip {
add_key("log_type", "squid_access")
geoip("client_ip")
}
grok(_, "%{DATE:d} %{TIME:t} %{WORD:process}(?:\\|)%{GREEDYDATA:raw_msg}")
if (raw_msg){
if ( "ERROR" in raw_msg ){
add_key("status","error")
}
drop_key("raw_msg")
add_key("log_type","squid_cache")
}
if d {
default_time("d + t", "2006/01/02 15:04:05")
drop_key("d")
drop_key("t")
}
access.log¶
- 生ログ
フィールド説明:
| フィールド名 | 例 | 意味 |
|---|---|---|
timestamp |
1755830457.018 | Unix タイムスタンプ(秒.ミリ秒) |
response_time |
0 | 応答時間(ミリ秒) |
client_ip |
113.87.27.138 | クライアント IP |
result |
TCP_DENIED | Squid の結果コード(例: TCP_DENIED) |
http_status |
403 | HTTP ステータスコード |
bytes |
3809 | レスポンスバイト数 |
method |
CONNECT | リクエストメソッド |
uri |
www.guance.com:443 | リクエスト URI |
hier_status |
HIER_NONE | 階層ステータス(HIER_NONE は上流なしを示す) |
hier_ip |
- | 上流サーバーアドレス(ない場合は -) |
content_type |
text/html | レスポンスの Content-Type |
cache.log¶
- 生ログ
2025/08/28 09:37:35 kid1| Logfile: opening log stdio:/var/spool/squid/netdb.state
2025/08/28 09:37:35 kid1| Logfile: closing log stdio:/var/spool/squid/netdb.state
2025/08/28 09:37:35 kid1| NETDB state saved; 9 entries, 0 msec
2025/08/28 10:14:17 pinger| SendEcho ERROR: sending to ICMPv6 packet to [2606:4700::6812:1dd6]: (101) Network is unreachable
2025/08/28 10:21:29 kid1| Logfile: opening log stdio:/var/spool/squid/netdb.state
2025/08/28 10:21:29 kid1| Logfile: closing log stdio:/var/spool/squid/netdb.state
2025/08/28 10:21:29 kid1| NETDB state saved; 9 entries, 0 msec
| フィールド | 例 | 意味 |
|---|---|---|
@timestamp |
2025-08-28 10:14:17 | ログ時間 |
process |
pinger | プロセス識別子 |
status |
ERROR | ログレベル |
message |
SendEcho ERROR: sending to ICMPv6 packet to [2606:4700::6812:1dd6]: (101) Network is unreachable | 元のログ本文 |