Data Structures | Defines | Typedefs | Enumerations | Functions | Variables

logstats.cc File Reference

A brief file description. More...

#include "libts.h"
#include "ink_config.h"
#include "ink_file.h"
#include "I_Layout.h"
#include "I_Version.h"
#include "LogStandalone.cc"
#include "LogObject.h"
#include "hdrs/HTTP.h"
#include <math.h>
#include <sys/utsname.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <functional>
#include <fcntl.h>
#include <ext/hash_map>
#include <ext/hash_set>
Include dependency graph for logstats.cc:

Go to the source code of this file.

Data Structures

struct  LastState
struct  StatsCounter
struct  ElapsedStats
struct  OriginStats
struct  UrlStats
struct  eqstr
struct  hash_fnv32
class  UrlLru
struct  CommandLineArgs
struct  ExitStatus

Defines

#define _XOPEN_SOURCE   600
#define PROGRAM_NAME   "traffic_logstats"
#define _BACKWARD_BACKWARD_WARNING_H

Typedefs

typedef std::list< UrlStatsLruStack
typedef __gnu_cxx::hash_map
< const char *, OriginStats
*, hash_fnv32, eqstr
OriginStorage
typedef __gnu_cxx::hash_set
< const char *, hash_fnv32,
eqstr
OriginSet
typedef __gnu_cxx::hash_map
< const char
*, LruStack::iterator,
hash_fnv32, eqstr
LruHash
typedef pair< const char
*, OriginStats * > 
OriginPair

Enumerations

enum  ExitLevel { EXIT_OK = 0, EXIT_WARNING = 1, EXIT_CRITICAL = 2, EXIT_UNKNOWN = 3 }
enum  ParseStates {
  P_STATE_ELAPSED, P_STATE_IP, P_STATE_RESULT, P_STATE_CODE,
  P_STATE_SIZE, P_STATE_METHOD, P_STATE_URL, P_STATE_RFC931,
  P_STATE_HIERARCHY, P_STATE_PEER, P_STATE_TYPE, P_STATE_END
}
enum  HTTPMethod {
  METHOD_OPTIONS, METHOD_GET, METHOD_HEAD, METHOD_POST,
  METHOD_PUT, METHOD_DELETE, METHOD_TRACE, METHOD_CONNECT,
  METHOD_PURGE, METHOD_NONE, METHOD_OTHER
}
enum  URLScheme { SCHEME_HTTP, SCHEME_HTTPS, SCHEME_NONE, SCHEME_OTHER }

Functions

template<class T , class N >
void rehash (T &container, N size)
void update_elapsed (ElapsedStats &stat, const int elapsed, const StatsCounter &counter)
void init_elapsed (OriginStats *stats)
void update_counter (StatsCounter &counter, int size)
void update_results_elapsed (OriginStats *stat, int result, int elapsed, int size)
void update_codes (OriginStats *stat, int code, int size)
void update_methods (OriginStats *stat, int method, int size)
void update_schemes (OriginStats *stat, int scheme, int size)
int parse_log_buff (LogBufferHeader *buf_header, bool summary=false)
int process_file (int in_fd, off_t offset, unsigned max_age)
int use_origin (const OriginStats *stat)
void format_center (const char *str)
void format_int (int64_t num)
void format_elapsed_header ()
void format_elapsed_line (const char *desc, const ElapsedStats &stat, bool json=false)
void format_detail_header (const char *desc)
void format_line (const char *desc, const StatsCounter &stat, const StatsCounter &total, bool json=false)
bool operator< (const OriginPair &a, const OriginPair &b)
void print_detail_stats (const OriginStats *stat, bool json=false)
void my_exit (const ExitStatus &status)
int open_main_log (ExitStatus &status)
int main (int, char *argv[])

Variables

const int MAX_LOGBUFFER_SIZE = 65536
const int DEFAULT_LINE_LEN = 78
const double LOG10_1024 = 3.0102999566398116
const int MAX_ORIG_STRING = 4096
const int GET_AS_INT = 5522759
const int PUT_AS_INT = 5526864
const int HEAD_AS_INT = 1145128264
const int POST_AS_INT = 1414745936
const int TEXT_AS_INT = 1954047348
const int JPEG_AS_INT = 1734701162
const int JPG_AS_INT = 6778986
const int GIF_AS_INT = 6711655
const int PNG_AS_INT = 6778480
const int BMP_AS_INT = 7368034
const int CSS_AS_INT = 7566179
const int XML_AS_INT = 7105912
const int HTML_AS_INT = 1819112552
const int ZIP_AS_INT = 7367034
const int JAVA_AS_INT = 1635148138
const int X_JA_AS_INT = 1634348408
const int RSSp_AS_INT = 728986482
const int PLAI_AS_INT = 1767992432
const int IMAG_AS_INT = 1734438249
const int HTTP_AS_INT = 1886680168
static LastState last_state
static OriginStats totals
static OriginStorage origins
static OriginSetorigin_set
static UrlLruurls
static int parse_errors
static CommandLineArgs cl
static ArgumentDescription argument_descriptions []
static const char * USAGE_LINE = " [-f logfile] [-o origin[,...]] [-O originfile] [-m minhits] [-inshv]"

Detailed Description

A brief file description.

License

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file logstats.cc.


Define Documentation

#define _BACKWARD_BACKWARD_WARNING_H

Definition at line 362 of file logstats.cc.

#define _XOPEN_SOURCE   600

Definition at line 56 of file logstats.cc.

#define PROGRAM_NAME   "traffic_logstats"

Definition at line 62 of file logstats.cc.

Referenced by main().


Typedef Documentation

typedef __gnu_cxx::hash_map<const char *, LruStack::iterator, hash_fnv32, eqstr> LruHash

Definition at line 367 of file logstats.cc.

typedef std::list<UrlStats> LruStack

Definition at line 345 of file logstats.cc.

typedef pair<const char *, OriginStats *> OriginPair

Definition at line 1902 of file logstats.cc.

typedef __gnu_cxx::hash_set<const char *, hash_fnv32, eqstr> OriginSet

Definition at line 366 of file logstats.cc.

typedef __gnu_cxx::hash_map<const char *, OriginStats *, hash_fnv32, eqstr> OriginStorage

Definition at line 365 of file logstats.cc.


Enumeration Type Documentation

enum ExitLevel
Enumerator:
EXIT_OK 
EXIT_WARNING 
EXIT_CRITICAL 
EXIT_UNKNOWN 

Definition at line 747 of file logstats.cc.

enum HTTPMethod
Enumerator:
METHOD_OPTIONS 
METHOD_GET 
METHOD_HEAD 
METHOD_POST 
METHOD_PUT 
METHOD_DELETE 
METHOD_TRACE 
METHOD_CONNECT 
METHOD_PURGE 
METHOD_NONE 
METHOD_OTHER 

Definition at line 801 of file logstats.cc.

Enumerator:
P_STATE_ELAPSED 
P_STATE_IP 
P_STATE_RESULT 
P_STATE_CODE 
P_STATE_SIZE 
P_STATE_METHOD 
P_STATE_URL 
P_STATE_RFC931 
P_STATE_HIERARCHY 
P_STATE_PEER 
P_STATE_TYPE 
P_STATE_END 

Definition at line 784 of file logstats.cc.

enum URLScheme
Enumerator:
SCHEME_HTTP 
SCHEME_HTTPS 
SCHEME_NONE 
SCHEME_OTHER 

Definition at line 817 of file logstats.cc.


Function Documentation

void format_center ( const char *  str  )  [inline]

Definition at line 1800 of file logstats.cc.

References cl, and CommandLineArgs::line_len.

Referenced by my_exit().

void format_detail_header ( const char *  desc  ) 

Definition at line 1860 of file logstats.cc.

References cl, and CommandLineArgs::line_len.

Referenced by print_detail_stats().

void format_elapsed_header (  ) 

Definition at line 1827 of file logstats.cc.

References cl, and CommandLineArgs::line_len.

Referenced by print_detail_stats().

void format_elapsed_line ( const char *  desc,
const ElapsedStats stat,
bool  json = false 
) [inline]
void format_int ( int64_t  num  )  [inline]

Definition at line 1806 of file logstats.cc.

Referenced by format_elapsed_line(), format_line(), and my_exit().

void format_line ( const char *  desc,
const StatsCounter stat,
const StatsCounter total,
bool  json = false 
) [inline]

Definition at line 1869 of file logstats.cc.

References StatsCounter::bytes, StatsCounter::count, format_int(), and LOG10_1024.

Referenced by print_detail_stats().

void init_elapsed ( OriginStats stats  )  [inline]

Definition at line 829 of file logstats.cc.

References OriginStats::elapsed, OriginStats::hits, and OriginStats::misses.

Referenced by main(), and parse_log_buff().

int main ( int  ,
char *  argv[] 
)
void my_exit ( const ExitStatus status  ) 
int open_main_log ( ExitStatus status  ) 

Definition at line 2252 of file logstats.cc.

References ExitStatus::append(), and Layout::get().

Referenced by main().

bool operator< ( const OriginPair a,
const OriginPair b 
) [inline]

Definition at line 1904 of file logstats.cc.

int parse_log_buff ( LogBufferHeader buf_header,
bool  summary = false 
)
void print_detail_stats ( const OriginStats stat,
bool  json = false 
)

Definition at line 1910 of file logstats.cc.

References OriginStats::application, OriginStats::audio, OriginStats::c_000, OriginStats::c_100, OriginStats::c_200, OriginStats::c_201, OriginStats::c_202, OriginStats::c_203, OriginStats::c_204, OriginStats::c_205, OriginStats::c_206, OriginStats::c_2xx, OriginStats::c_300, OriginStats::c_301, OriginStats::c_302, OriginStats::c_303, OriginStats::c_304, OriginStats::c_305, OriginStats::c_307, OriginStats::c_3xx, OriginStats::c_400, OriginStats::c_401, OriginStats::c_402, OriginStats::c_403, OriginStats::c_404, OriginStats::c_405, OriginStats::c_406, OriginStats::c_407, OriginStats::c_408, OriginStats::c_409, OriginStats::c_410, OriginStats::c_411, OriginStats::c_412, OriginStats::c_413, OriginStats::c_414, OriginStats::c_415, OriginStats::c_416, OriginStats::c_417, OriginStats::c_4xx, OriginStats::c_500, OriginStats::c_501, OriginStats::c_502, OriginStats::c_503, OriginStats::c_504, OriginStats::c_505, OriginStats::c_5xx, cl, OriginStats::codes, OriginStats::connect, OriginStats::content, OriginStats::del, OriginStats::direct, OriginStats::elapsed, OriginStats::empty, OriginStats::errors, format_detail_header(), format_elapsed_header(), format_elapsed_line(), format_line(), OriginStats::get, OriginStats::head, OriginStats::hierarchies, OriginStats::hits, OriginStats::http, OriginStats::https, OriginStats::image, ink_time_wall_seconds(), OriginStats::invalid, CommandLineArgs::line_len, OriginStats::methods, OriginStats::misses, OriginStats::none, OriginStats::options, OriginStats::other, OriginStats::parent, OriginStats::post, OriginStats::purge, OriginStats::put, OriginStats::results, OriginStats::schemes, OriginStats::sibling, OriginStats::text, OriginStats::total, and OriginStats::trace.

Referenced by my_exit().

int process_file ( int  in_fd,
off_t  offset,
unsigned  max_age 
)
template<class T , class N >
void rehash ( T &  container,
size 
)

Definition at line 372 of file logstats.cc.

void update_codes ( OriginStats stat,
int  code,
int  size 
) [inline]
void update_counter ( StatsCounter counter,
int  size 
) [inline]
void update_elapsed ( ElapsedStats stat,
const int  elapsed,
const StatsCounter counter 
) [inline]
void update_methods ( OriginStats stat,
int  method,
int  size 
) [inline]
void update_results_elapsed ( OriginStats stat,
int  result,
int  elapsed,
int  size 
) [inline]
void update_schemes ( OriginStats stat,
int  scheme,
int  size 
) [inline]
int use_origin ( const OriginStats stat  )  [inline]

Definition at line 1791 of file logstats.cc.

References cl, StatsCounter::count, CommandLineArgs::min_hits, OriginStats::server, and OriginStats::total.

Referenced by my_exit().


Variable Documentation

Initial value:
 {
  {"help", 'h', "Give this help", "T", &cl.help, NULL, NULL},
  {"log_file", 'f', "Specific logfile to parse", "S1023", cl.log_file, NULL, NULL},
  {"origin_list", 'o', "Only show stats for listed Origins", "S4095", cl.origin_list, NULL, NULL},
  {"origin_file", 'O', "File listing Origins to show", "S1023", cl.origin_file, NULL, NULL},
  {"max_orgins", 'M', "Max number of Origins to show", "I", &cl.max_origins, NULL, NULL},
  {"urls", 'u', "Produce JSON stats for URLs, argument is LRU size", "I", &cl.urls, NULL, NULL},
  {"show_urls", 'U', "Only show max this number of URLs", "I", &cl.show_urls, NULL, NULL},
  {"as_object", 'A', "Produce URL stats as a JSON object instead of array", "T", &cl.as_object, NULL, NULL},
  {"incremental", 'i', "Incremental log parsing", "T", &cl.incremental, NULL, NULL},
  {"statetag", 'S', "Name of the state file to use", "S1023", cl.state_tag, NULL, NULL},
  {"tail", 't', "Parse the last <sec> seconds of log", "I", &cl.tail, NULL, NULL},
  {"summary", 's', "Only produce the summary", "T", &cl.summary, NULL, NULL},
  {"json", 'j', "Produce JSON formatted output", "T", &cl.json, NULL, NULL},
  {"cgi", 'c', "Produce HTTP headers suitable as a CGI", "T", &cl.cgi, NULL, NULL},
  {"min_hits", 'm', "Minimum total hits for an Origin", "L", &cl.min_hits, NULL, NULL},
  {"max_age", 'a', "Max age for log entries to be considered", "I", &cl.max_age, NULL, NULL},
  {"line_len", 'l', "Output line length", "I", &cl.line_len, NULL, NULL},
  {"debug_tags", 'T', "Colon-Separated Debug Tags", "S1023", &error_tags, NULL, NULL},
  {"version", 'V', "Print Version Id", "T", &cl.version, NULL, NULL},
}

Definition at line 658 of file logstats.cc.

const int BMP_AS_INT = 7368034

Definition at line 83 of file logstats.cc.

Referenced by parse_log_buff().

CommandLineArgs cl [static]
const int CSS_AS_INT = 7566179

Definition at line 84 of file logstats.cc.

Referenced by parse_log_buff().

const int DEFAULT_LINE_LEN = 78

Definition at line 65 of file logstats.cc.

const int GET_AS_INT = 5522759

Definition at line 72 of file logstats.cc.

Referenced by parse_log_buff().

const int GIF_AS_INT = 6711655

Definition at line 81 of file logstats.cc.

Referenced by parse_log_buff().

const int HEAD_AS_INT = 1145128264

Definition at line 74 of file logstats.cc.

Referenced by parse_log_buff().

const int HTML_AS_INT = 1819112552

Definition at line 86 of file logstats.cc.

Referenced by parse_log_buff().

const int HTTP_AS_INT = 1886680168

Definition at line 94 of file logstats.cc.

Referenced by parse_log_buff().

const int IMAG_AS_INT = 1734438249

Definition at line 93 of file logstats.cc.

Referenced by parse_log_buff().

const int JAVA_AS_INT = 1635148138

Definition at line 89 of file logstats.cc.

Referenced by parse_log_buff().

const int JPEG_AS_INT = 1734701162

Definition at line 79 of file logstats.cc.

Referenced by parse_log_buff().

const int JPG_AS_INT = 6778986

Definition at line 80 of file logstats.cc.

Referenced by parse_log_buff().

Definition at line 102 of file logstats.cc.

Referenced by main(), and ClusterHandler::mainClusterEvent().

const double LOG10_1024 = 3.0102999566398116

Definition at line 66 of file logstats.cc.

Referenced by format_line().

const int MAX_LOGBUFFER_SIZE = 65536

Definition at line 64 of file logstats.cc.

Referenced by process_file().

const int MAX_ORIG_STRING = 4096

Definition at line 67 of file logstats.cc.

Referenced by CommandLineArgs::parse_arguments().

OriginSet* origin_set [static]

Definition at line 617 of file logstats.cc.

Referenced by main(), my_exit(), and parse_log_buff().

Definition at line 616 of file logstats.cc.

Referenced by my_exit(), and parse_log_buff().

int parse_errors [static]

Definition at line 619 of file logstats.cc.

Referenced by main(), and parse_log_buff().

const int PLAI_AS_INT = 1767992432

Definition at line 92 of file logstats.cc.

Referenced by parse_log_buff().

const int PNG_AS_INT = 6778480

Definition at line 82 of file logstats.cc.

Referenced by parse_log_buff().

const int POST_AS_INT = 1414745936

Definition at line 75 of file logstats.cc.

Referenced by parse_log_buff().

const int PUT_AS_INT = 5526864

Definition at line 73 of file logstats.cc.

Referenced by parse_log_buff().

const int RSSp_AS_INT = 728986482

Definition at line 91 of file logstats.cc.

Referenced by parse_log_buff().

const int TEXT_AS_INT = 1954047348

Definition at line 77 of file logstats.cc.

Referenced by parse_log_buff().

OriginStats totals [static]

Definition at line 615 of file logstats.cc.

Referenced by main(), my_exit(), and parse_log_buff().

UrlLru* urls [static]

Definition at line 618 of file logstats.cc.

Referenced by main(), my_exit(), parse_log_buff(), and SDK_API_TSUrlParse().

const char* USAGE_LINE = " [-f logfile] [-o origin[,...]] [-O originfile] [-m minhits] [-inshv]" [static]

Definition at line 680 of file logstats.cc.

Referenced by main(), and CommandLineArgs::parse_arguments().

const int X_JA_AS_INT = 1634348408

Definition at line 90 of file logstats.cc.

Referenced by parse_log_buff().

const int XML_AS_INT = 7105912

Definition at line 85 of file logstats.cc.

Referenced by parse_log_buff().

const int ZIP_AS_INT = 7367034

Definition at line 87 of file logstats.cc.

Referenced by parse_log_buff().