Giter VIP home page Giter VIP logo

gonginxlogger's Introduction

NginxLogger - Nginx Log parser in Go for MongoDB

This tool parses nginx access log in following format[1] and inserts them into MongoDB in format[2]

Nginx default log format[1]

$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"

MongoDB document format[2]

{
    "_id" : ObjectId("59ce205c460c807614ce4728"),
	"remoteip" : {
		"continent" : "",
		"ip" : "",
		"country" : "",
		"countrycode" : "",
		"city" : "",
		"location" : {
			"latitude" : 0,
			"longitude" : 0
		}
	},
	"timestamp" : ISODate("2017-08-05T14:55:00Z"),
	"requestinguser" : "-",
	"method" : "",
	"request" : "/",
	"httpversion" : "",
	"responsecode" : "",
	"size" : 0,
	"referrer" : "",
	"client" : {
		"useragent" : {
			"family" : "",
			"major" : "",
			"minor" : "",
			"patch" : ""
		},
		"os" : {
			"family" : "",
			"major" : "",
			"minor" : "",
			"patch" : "",
			"patchminor" : ""
		},
		"device" : {
			"family" : ""
		}
	}
}

Installing dependencies

Make sure your GOROOT environment variable is corrent.

$ go get github.com/oschwald/geoip2-golang
$ go get github.com/tobie/ua-parser/go/uaparser
$ go get github.com/fsnotify/fsnotify
$ go get gopkg.in/mgo.v2/bson
$ go get golang.org/x/crypto/bcrypt

Database Configuration

Database configuration is defined in dbmanager.go

const DATABASE = "nginxLogger"
const C_USER = "user"
const C_LOG = "access_log"
const C_FILE = "file_position"

DATABASE - database name.

C_USER - collection to store username/password (to facilitate login for other applications using data ).

C_LOG - collection to store logs.

C_FILE - collection to store file pointer.

Usage

  1. Install and start MongoDB
  2. Install dependencies
  3. Build using make
  4. Start using ./dbmanager

Binary takes two arguments

-path - Path to nginx access logs. (Defaults to /var/log/nginx/access.log) -adduser (optional) - To add user for facilitating login for other applications using this data

gonginxlogger's People

Contributors

spl0i7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

go-archive zz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.