Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ext-respondd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
infrastruktur
ext-respondd
Commits
3fd79f43
Commit
3fd79f43
authored
Jun 21, 2017
by
Marcus Scharf
Browse files
Options
Downloads
Patches
Plain Diff
enable limit by default / add caching / add rootfs usage
parent
1dea7ed0
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
ext-respondd.py
+4
-1
4 additions, 1 deletion
ext-respondd.py
lib/respondd.py
+12
-2
12 additions, 2 deletions
lib/respondd.py
lib/respondd_client.py
+4
-1
4 additions, 1 deletion
lib/respondd_client.py
lib/statistics.py
+7
-0
7 additions, 0 deletions
lib/statistics.py
with
27 additions
and
4 deletions
ext-respondd.py
+
4
−
1
View file @
3fd79f43
...
@@ -20,7 +20,10 @@ config = {
...
@@ -20,7 +20,10 @@ config = {
'
bridge
'
:
'
br-client
'
,
'
bridge
'
:
'
br-client
'
,
'
batman
'
:
'
bat0
'
,
'
batman
'
:
'
bat0
'
,
'
port
'
:
1001
,
'
port
'
:
1001
,
'
addr
'
:
'
ff02::2:1001
'
'
addr
'
:
'
ff02::2:1001
'
,
'
caching
'
:
5
,
'
rate_limit
'
:
30
,
'
rate_limit_burst
'
:
10
}
}
try
:
try
:
...
...
This diff is collapsed.
Click to expand it.
lib/respondd.py
+
12
−
2
View file @
3fd79f43
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
import
json
import
json
import
zlib
import
zlib
import
time
import
lib.helper
import
lib.helper
...
@@ -9,6 +10,8 @@ class Respondd:
...
@@ -9,6 +10,8 @@ class Respondd:
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
self
.
_config
=
config
self
.
_config
=
config
self
.
_aliasOverlay
=
{}
self
.
_aliasOverlay
=
{}
self
.
__cache
=
{}
self
.
__cacheTime
=
0
try
:
try
:
with
open
(
'
alias.json
'
,
'
r
'
)
as
fh
:
# TODO: prevent loading more then once !
with
open
(
'
alias.json
'
,
'
r
'
)
as
fh
:
# TODO: prevent loading more then once !
self
.
_aliasOverlay
=
json
.
load
(
fh
)
self
.
_aliasOverlay
=
json
.
load
(
fh
)
...
@@ -23,12 +26,19 @@ class Respondd:
...
@@ -23,12 +26,19 @@ class Respondd:
return
lib
.
helper
.
getInterfaceMAC
(
self
.
_config
[
'
batman
'
]).
replace
(
'
:
'
,
''
)
return
lib
.
helper
.
getInterfaceMAC
(
self
.
_config
[
'
batman
'
]).
replace
(
'
:
'
,
''
)
def
getStruct
(
self
,
rootName
=
None
):
def
getStruct
(
self
,
rootName
=
None
):
if
'
caching
'
in
self
.
_config
and
time
.
time
()
-
self
.
__cacheTime
<=
self
.
_config
[
'
caching
'
]:
ret
=
self
.
__cache
else
:
ret
=
self
.
_get
()
ret
=
self
.
_get
()
self
.
__cache
=
ret
self
.
__cacheTime
=
time
.
time
()
ret
[
'
node_id
'
]
=
self
.
getNodeID
()
ret
[
'
node_id
'
]
=
self
.
getNodeID
()
if
rootName
is
not
None
:
if
rootName
is
not
None
:
ret_tmp
=
ret
ret_tmp
=
ret
ret
=
{}
ret
=
{}
ret
[
rootName
]
=
ret_tmp
ret
[
rootName
]
=
ret_tmp
return
ret
return
ret
def
getJSON
(
self
,
rootName
=
None
):
def
getJSON
(
self
,
rootName
=
None
):
...
...
This diff is collapsed.
Click to expand it.
lib/respondd_client.py
+
4
−
1
View file @
3fd79f43
...
@@ -4,6 +4,7 @@ import socket
...
@@ -4,6 +4,7 @@ import socket
import
select
import
select
import
struct
import
struct
import
json
import
json
import
time
from
lib.ratelimit
import
rateLimit
from
lib.ratelimit
import
rateLimit
from
lib.nodeinfo
import
Nodeinfo
from
lib.nodeinfo
import
Nodeinfo
...
@@ -50,6 +51,8 @@ class ResponddClient:
...
@@ -50,6 +51,8 @@ class ResponddClient:
print
(
'
rate limit reached!
'
)
print
(
'
rate limit reached!
'
)
return
return
tStart
=
time
.
time
()
responseClass
=
None
responseClass
=
None
if
responseType
==
'
statistics
'
:
if
responseType
==
'
statistics
'
:
responseClass
=
self
.
_statistics
responseClass
=
self
.
_statistics
...
@@ -68,6 +71,6 @@ class ResponddClient:
...
@@ -68,6 +71,6 @@ class ResponddClient:
self
.
_sock
.
sendto
(
responseClass
.
getJSON
(
responseType
),
destAddress
)
self
.
_sock
.
sendto
(
responseClass
.
getJSON
(
responseType
),
destAddress
)
if
self
.
_config
[
'
verbose
'
]
or
self
.
_config
[
'
dry_run
'
]:
if
self
.
_config
[
'
verbose
'
]
or
self
.
_config
[
'
dry_run
'
]:
print
(
'
%35s %5d %13s:
'
%
(
destAddress
[
0
],
destAddress
[
1
],
responseType
),
end
=
''
)
print
(
'
%14.3f
%35s %5d %13s
%5.3f
:
'
%
(
tStart
,
destAddress
[
0
],
destAddress
[
1
],
responseType
,
time
.
time
()
-
tStart
),
end
=
''
)
print
(
json
.
dumps
(
responseClass
.
getStruct
(
responseType
),
sort_keys
=
True
,
indent
=
4
))
print
(
json
.
dumps
(
responseClass
.
getStruct
(
responseType
),
sort_keys
=
True
,
indent
=
4
))
This diff is collapsed.
Click to expand it.
lib/statistics.py
+
7
−
0
View file @
3fd79f43
...
@@ -4,6 +4,7 @@ import socket
...
@@ -4,6 +4,7 @@ import socket
import
re
import
re
import
sys
import
sys
import
json
import
json
import
os
from
lib.respondd
import
Respondd
from
lib.respondd
import
Respondd
import
lib.helper
import
lib.helper
...
@@ -148,6 +149,11 @@ class Statistics(Respondd):
...
@@ -148,6 +149,11 @@ class Statistics(Respondd):
return
ret
return
ret
@staticmethod
def
getRootFS
():
statFS
=
os
.
statvfs
(
'
/
'
)
return
1
-
(
statFS
.
f_bfree
/
statFS
.
f_blocks
)
def
_get
(
self
):
def
_get
(
self
):
ret
=
{
ret
=
{
'
clients
'
:
self
.
getClients
(),
'
clients
'
:
self
.
getClients
(),
...
@@ -155,6 +161,7 @@ class Statistics(Respondd):
...
@@ -155,6 +161,7 @@ class Statistics(Respondd):
'
idletime
'
:
float
(
open
(
'
/proc/uptime
'
).
read
().
split
(
'
'
)[
1
]),
'
idletime
'
:
float
(
open
(
'
/proc/uptime
'
).
read
().
split
(
'
'
)[
1
]),
'
loadavg
'
:
float
(
open
(
'
/proc/loadavg
'
).
read
().
split
(
'
'
)[
0
]),
'
loadavg
'
:
float
(
open
(
'
/proc/loadavg
'
).
read
().
split
(
'
'
)[
0
]),
'
memory
'
:
self
.
getMemory
(),
'
memory
'
:
self
.
getMemory
(),
'
rootfs
'
:
round
(
self
.
getRootFS
(),
4
),
'
processes
'
:
dict
(
zip
((
'
running
'
,
'
total
'
),
map
(
int
,
open
(
'
/proc/loadavg
'
).
read
().
split
(
'
'
)[
3
].
split
(
'
/
'
)))),
'
processes
'
:
dict
(
zip
((
'
running
'
,
'
total
'
),
map
(
int
,
open
(
'
/proc/loadavg
'
).
read
().
split
(
'
'
)[
3
].
split
(
'
/
'
)))),
'
uptime
'
:
float
(
open
(
'
/proc/uptime
'
).
read
().
split
(
'
'
)[
0
]),
'
uptime
'
:
float
(
open
(
'
/proc/uptime
'
).
read
().
split
(
'
'
)[
0
]),
'
mesh_vpn
'
:
{
# HopGlass-Server: node.flags.uplink = parsePeerGroup(_.get(n, 'statistics.mesh_vpn'))
'
mesh_vpn
'
:
{
# HopGlass-Server: node.flags.uplink = parsePeerGroup(_.get(n, 'statistics.mesh_vpn'))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment