Skip to content

aorith/varnishlog-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
Dec 17, 2024
Jan 3, 2025
Nov 1, 2024
Mar 25, 2025
Jan 3, 2025
Nov 1, 2024
Dec 17, 2024
Feb 13, 2025
Nov 1, 2024
Nov 12, 2024
Nov 1, 2024
Mar 26, 2025
Mar 26, 2025
Nov 1, 2024

Repository files navigation

varnishlog-parser

A varnishlog parser library and web user interface

An instance is available here: https://varnishlog.iou.re/

Run the web-ui locally

Either clone this repository and run:

go run . server

Or with docker/podman:

docker run --rm -p 8080:8080 ghcr.io/aorith/varnishlog-parser:latest

Use as a library

Here's an example:

package main

import (
	"fmt"
	"strings"

	"github.com/aorith/varnishlog-parser/vsl"
)

const incompleteExample = `*   << Session  >> 1
-   Begin          sess 0 HTTP/1
-   SessOpen       192.168.50.1 55650 http 192.168.50.10 80 1728889150.256391 26
-   Link           req 2 rxreq
-   SessClose      REM_CLOSE 0.123
-   End
**  << Request  >> 2
--  Begin          req 1 rxreq
--  Timestamp      Start: 1728889150.256523 0.021300 0.021300
--  VCL_use        boot
--  End
`

func main() {
	p := vsl.NewTransactionParser(strings.NewReader(incompleteExample))
	txsSet, err := p.Parse()
	if err != nil {
		fmt.Println(err)
		return
	}

	// Iterate all the transactions VSL log records
	for _, tx := range txsSet.Transactions() {
		fmt.Printf("%v\n", tx.TXID())
		for _, r := range tx.LogRecords() {
			switch record := r.(type) {
			case vsl.TimestampRecord:
				fmt.Printf("  [%s]  %s: %s\n", record.Tag(), record.EventLabel(), record.SinceLast().String())
			case vsl.SessCloseRecord:
				fmt.Printf("  [%s]  %s: %s\n", record.Tag(), record.Reason(), record.Duration().String())
			default:
				fmt.Printf("  [%s]  %s\n", record.Tag(), record.Value())
			}
		}
	}
}

Output:

1_sess
  [Begin]  sess 0 HTTP/1
  [SessOpen]  192.168.50.1 55650 http 192.168.50.10 80 1728889150.256391 26
  [Link]  req 2 rxreq
  [SessClose]  REM_CLOSE: 123ms
  [End]  
2_req
  [Begin]  req 1 rxreq
  [Timestamp]  Start: 21.3ms
  [VCL_use]  boot
  [End]