Revision 978:bbb88c44f805 extra/soundsoftware

View differences:

extra/soundsoftware/get-apache-log-stats.rb
1

  
2
# Read an Apache log file from the SoundSoftware site and produce some
3
# per-project stats.
4
#
5
# Invoke with e.g.
6
#
7
# cat /var/log/apache2/code-access.log | \
8
#   script/runner -e production extra/soundsoftware/get-apache-log-stats.rb
9

  
1 10

  
2 11
# Use the ApacheLogRegex parser, a neat thing
3 12
# See http://www.simonecarletti.com/blog/2009/02/apache-log-regex-a-lightweight-ruby-apache-log-parser/
......
14 23
# project name -> count of hg pulls
15 24
pulls = Hash.new(0)
16 25

  
17
# project name -> count of hg commits
18
commits = Hash.new(0)
26
# project name -> count of hg pushes
27
pushes = Hash.new(0)
19 28

  
20 29
# project name -> count of hg archive requests (i.e. Download as Zip)
21 30
zips = Hash.new(0)
......
23 32
# project name -> count of hits to pages under /projects/projectname
24 33
hits = Hash.new(0)
25 34

  
35
# project name -> Project object
36
@projects = Hash.new
37

  
26 38
parseable = 0
27 39
unparseable = 0
28 40

  
41
def known_project?(project)
42
  if !project
43
    false
44
  elsif @projects.key?(project)
45
    true
46
  else
47
    pobj = Project.find_by_identifier(project)
48
    if pobj
49
      @projects[project] = pobj
50
      true
51
    else
52
      print "Project not found: ", project
53
      false
54
    end
55
  end
56
end
57

  
29 58
ARGF.each do |line|
30 59

  
31 60
  record = parser.parse(line)
......
75 104
    # path is /hg/project?something or /hg/project/something
76 105

  
77 106
    project = components[2].split("?")[0]
107
    if not known_project?(project)
108
      next
109
    end
78 110

  
79 111
    if components[2] =~ /&roots=00*$/
80 112
      clones[project] += 1
81 113
    elsif components[2] =~ /cmd=capabilities/
82 114
      pulls[project] += 1
115
    elsif components[2] =~ /cmd=unbundle/
116
      pushes[project] += 1
83 117
    elsif components[3] == "archive"
84 118
      zips[project] += 1
85 119
    end
......
89 123
    # path is /projects/project or /projects/project/something
90 124

  
91 125
    project = components[2]
92
    if project
93
      project = project.split("?")[0]
94
      hits[project] += 1
126
    if not known_project?(project)
127
      next
95 128
    end
96 129

  
130
    project = project.split("?")[0]
131
    hits[project] += 1
132

  
97 133
  end
98 134

  
99 135
  parseable += 1
......
108 144

  
109 145
print clones, "\n"
110 146
print pulls, "\n"
147
print pushes, "\n"
111 148
print zips, "\n"
112 149
print hits, "\n"
113 150

  

Also available in: Unified diff