콘텐츠로 이동

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 시작 이후 분당 평균 HTTP 요청 수 회/분
info_Average_ICP_messages_per_minute_since_start 시작 이후 분당 평균 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 원시 로그 본문

문서 평가

이 페이지가 도움이 되었나요?