コンテンツにスキップ

Squid

設定

squid-exporter で Squid のメトリクスデータを収集します。DataKit は prom コレクターを使って squid-exporter が送信したメトリクスデータを受信します。

Squid の公開メトリクス

  1. squid-exporter をダウンロードする

  2. squid-exporter を実行する

squid-exporter9301 ポートで Prometheus 形式のメトリクスデータを公開します

nohup  ./squid-exporter -squid-hostname "localhost" -squid-port 3128 -listen ":9301" &

コレクター設定

prom.conf.samplesquid.conf にコピーします

cd /usr/local/datakit/conf.d/samples/
cp 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 ディレクトリに移動し、次のコマンドを実行します:

cp logging.conf.sample squid.conf

設定ファイルを調整します:

[[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

  • 生ログ
    1756280173.452    362 116.62.210.211 TCP_TUNNEL/200 56389 CONNECT www.guance.com:443 - HIER_DIRECT/61.170.77.75 -
    1756280241.702    303 120.253.192.179 TCP_TUNNEL/200 56249 CONNECT www.guance.com:443 - HIER_DIRECT/61.170.77.74 -
    

フィールド説明:

フィールド名 意味
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 元のログ本文

フィードバック

このページは役に立ちましたか?