~ubuntu-branches/ubuntu/wily/ntopng/wily-proposed

« back to all changes in this revision

Viewing changes to scripts/lua/pid_stats.lua

  • Committer: Package Import Robot
  • Author(s): Ludovico Cavedon
  • Date: 2014-07-27 16:13:47 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140727161347-0i8n5upu69ibq5d2
Tags: 1.2.0+dfsg1-1
* Imported Upstream version 1.2.0+dfsg1
* Update watch rule for new upstream naming convention.
* get-roig-source: Support both +svn and ~svn in version.
* Remove external hiredis from orig tarball.
* Remove Rickshaw from orig tarball.
* Remove documentation without source from orig tarball and insert an http
* Remove corrupted unused serializeCFJSON-0.1.js from orig tarball.
  link to it in README.Debian.
* Remove nDPI from orig tarball.
* Remove all debian/missing-sources files that are now included not-minified
  by upstream. Remove build-deps on node-uglify and cleancss.
* Remove references to third-party/redis-lua (removed upstream).
* Update copyright.
* Refresh patches and remove those merged upstream.
* Add external-hiredis.patch to use system libhiredis.
* Add rickshaw-keep-one.patch to remove references to additional rickshaw
  library.
* Add no-svn.patch to drop requirement on SVN.
* Add manpage.patch to fix usage of minus signs, hyphens, and dashes,
  missing space and line breaks.
* Add rickshaw.patch to use single rickshaw.{css,js} files.
* Split library removing part of build-flags.patch into remove-libs.patch.
* Rename debian-defaults.patch to path-defaults.patch and use installation
  path from configure.
* Use dh-autoreconf instead of autotools-dev.
* Add build-dep on libsqlite3-dev.
* Update build-dep on newer libndpi-dev.
* Cleanup of dh_install rules.
* Fix typo in font-awesome symlink path and remove and updates symlink links
  in ntopng-data/
* Remove executable bit to non executable files.
* Use system linjs-jquery tablesorter and form.
* Add Build-Dep on libhiredis-dev.
* Remove empty httpdocs/ssl directory.
* Add systemd support.
* Stop supporting ENABLED in /etc/default/ntopng and debian/NEWS to notify
  users.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
--
 
2
-- (C) 2013-14 - ntop.org
 
3
--
 
4
 
 
5
dirs = ntop.getDirs()
 
6
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
 
7
 
 
8
require "lua_utils"
 
9
 
 
10
sendHTTPHeader('text/html')
 
11
 
 
12
mode = _GET["mode"] --l4,l7,host
 
13
pid = tonumber(_GET["pid"])
 
14
name = _GET["name"]
 
15
host = _GET["host"]
 
16
local debug = false
 
17
if (debug) then setTraceLevel(TRACE_DEBUG) end
 
18
 
 
19
interface.find(ifname)
 
20
 
 
21
if (pid ~= nil) then
 
22
 flows = interface.findPidFlows(pid)
 
23
 elseif (name ~= nil) then
 
24
   flows = interface.findNameFlows(name)
 
25
 end
 
26
 
 
27
 if(mode == nil) then
 
28
   mode = "host"
 
29
 end
 
30
 
 
31
 if(flows == nil) then
 
32
   print('[ { "label": "No flows", "value": 1 } ]') -- No flows found
 
33
 else   
 
34
   apps = { }
 
35
   tot = 0
 
36
   for k,f in pairs(flows) do 
 
37
    process = 1
 
38
    traceError(TRACE_DEBUG,TRACE_CONSOLE,"Cli:"..f["cli.ip"].." - Srv:"..f["srv.ip"])
 
39
  
 
40
    if((host ~= nil) and ((f["cli.ip"] ~= host) and (f["srv.ip"] ~= host))) then
 
41
     process = 0
 
42
   end
 
43
 
 
44
   if(mode == "l7") then
 
45
    key = f["proto.ndpi"]
 
46
    v = f["cli2srv.bytes"] + f["srv2cli.bytes"]
 
47
 
 
48
    elseif(mode == "l4") then
 
49
      key = f["proto.l4"]
 
50
    
 
51
      v = f["cli2srv.bytes"] + f["srv2cli.bytes"]
 
52
    elseif(mode == "host") then
 
53
      if ((f["client_process"] ~= nil) and (f["client_process"]["name"] == name)) then
 
54
        -- key = f["cli.source_id"].."-"..f["cli.ip"].."(client)"
 
55
        key = f["cli.ip"].."(client)"
 
56
        v = f["cli2srv.bytes"] 
 
57
        elseif ((f["server_process"] ~= nil) and (f["server_process"]["name"] == name)) then
 
58
        -- key = f["srv.source_id"].."-"..f["srv.ip"].."(server)"
 
59
        key = f["srv.ip"].."(server)"
 
60
        v = f["srv2cli.bytes"]
 
61
      end
 
62
    end
 
63
    
 
64
    if((key ~= nil) and (process == 1))then
 
65
     if(apps[key] == nil) then apps[key] = 0 end
 
66
     traceError(TRACE_DEBUG,TRACE_CONSOLE,"key: "..key..",value: "..apps[key])
 
67
     apps[key] = apps[key] + v
 
68
     tot = tot + v
 
69
   end
 
70
  end
 
71
 
 
72
-- Print up to this number of entries
 
73
max_num_entries = 10
 
74
 
 
75
-- Print entries whose value >= 5% of the total
 
76
threshold = (tot * 5) / 100
 
77
 
 
78
print "[\n"
 
79
num = 0
 
80
accumulate = 0
 
81
 
 
82
for key, value in pairs(apps) do
 
83
 if((num ~= 0) and (value < threshold)) then
 
84
  break
 
85
end
 
86
 
 
87
if(num > 0) then
 
88
  print ",\n"
 
89
end
 
90
 
 
91
print("\t { \"label\": \"" .. key .."\", \"value\": ".. value .." }")
 
92
accumulate = accumulate + value
 
93
num = num + 1
 
94
 
 
95
if(num == max_num_entries) then
 
96
  break
 
97
end
 
98
end
 
99
 
 
100
if((num == 0) and (top_key ~= nil)) then
 
101
 print("\t { \"label\": \"" .. top_key .."\", \"value\": ".. top_value ..", \"url\": \"/lua/host_details.lua?host=".. top_key .."\" }")
 
102
 accumulate = accumulate + top_value
 
103
end
 
104
 
 
105
-- In case there is some leftover do print it as "Other"
 
106
if(accumulate < tot) then
 
107
 if(num > 0) then print(",") end 
 
108
 print("\n\t { \"label\": \"Other\", \"value\": ".. (tot-accumulate) .." }")
 
109
end
 
110
 
 
111
print "\n]"
 
112
end
 
113
 
 
114
 
 
115