Skip to content

Instantly share code, notes, and snippets.

@vadv
Created November 24, 2017 14:50
Show Gist options
  • Save vadv/fd8a802f0f1cf5b369993a163b3abea9 to your computer and use it in GitHub Desktop.
Save vadv/fd8a802f0f1cf5b369993a163b3abea9 to your computer and use it in GitHub Desktop.
Line =
^"" IP(string) " " # 10.143.71.203
^"[" HttpForwardedFor(string) "]" # [-]
^" [" SmartLabsSessionID(string) "]" # [1607333981]
^" " SmartLabsMacAddress(string) " " # 1C:BB:A8:01:A3:65
^"[" LocalTime(string) "]" # [24/Nov/2017:17:10:29 +0300]
^" " UpstreamCacheStatus(string) " " # HIT
^"" Request(string) " " # GET
^"" Url(string) " " # /hls/CH_R01_FRIDAY/1511510400/1511515800.ts/0r2_95670004r8048.ts
^"" HttpVersion(string) " " # HTTP/1.1
^"\"" HttpStatus(string) "\"" # "200"
^" " BytesSend(string) " " # 1513400
^"" HlsBufferTotalBytes(string) " " # 8388608
^"" HlsBufferFreeBytes(string) " " # 8084
^"\"" HlsChunkDuration(string) "\"" # "6"
^" " SmartLabsRequestID(string) " " # -
^"" RequestUniqueID(string) " " # 39929-1511532628-916-20448073
^"\"" HttpRefer(string) "\"" # "-"
^" \"" HttpUA(string) "\"" # "Restream/5.20248.170919 (ps7105; PS7105) SmartSDK/1.5.63-rt-25 Qt/4.7.3 API/0.30.0"
^" \"" UpstreamAddr(string) "\"" # "-"
^" \"" ServerPort(string) "\"" # "80"
^" \"" ServerHost(string) "\"" # "178.45.252.45"
^" \"" RequestTime(string) "\"" # "0.192"
^" \"" UpstreamResponseTime(string) "\"" # "-"
^" \"" RequestSendTime(string) "\"" # "0"
;
//go:generate ldetool generate --package main line.lde
package main
import (
"bufio"
"log"
"os"
)
func main() {
count := 0
line := &Line{}
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
ok, err := line.Extract(scanner.Bytes())
if !ok {
if err != nil {
panic(err)
}
continue
}
if string(line.HttpStatus) == "200" {
count++
}
}
log.Printf(">>>> 200: %d\n", count)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment