Skip to content

Commit 5a3045f

Browse files
committed
Add script for posting average CPU load to specific stream
1 parent 84ac0af commit 5a3045f

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎scripts/python/README.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## Resource for polling
2+
13
This script acts as a dummy resource which you can poll.
24
You start a small webserver which you can request a
35
resource JSON-object from.
@@ -17,3 +19,18 @@ Make sure you have the right permissions to resource.py
1719
by typing
1820

1921
chmod 755 resource.py
22+
23+
## Self-posting stream
24+
25+
The script post_avg.py reads the average load from the file "/proc/loadavg" and sends the value to the specified
26+
stream at the engine url. the script is called using:
27+
28+
python post_avg.py <stream_id> <interval_in_seconds> <engine_base_address>
29+
30+
Example use
31+
32+
python post_avg.py asd21 30 http://localhost:8000
33+
34+
the above example will post '{"value": <load_avg>}' every 30 seconds to http://localhost:8000/streams/asd21/data
35+
36+
The script posts using curl and thus requires curl to be installed.

‎scripts/python/post_avg.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
import time
3+
import sys
4+
import subprocess
5+
6+
stream_id = str(sys.argv[1])
7+
interval = int(sys.argv[2])
8+
base_url = str(sys.argv[3])
9+
while 1:
10+
time.sleep(interval)
11+
a = open("/proc/loadavg")
12+
b = a.readline().split(" ")
13+
loadavg = float(b[0])*100
14+
a.close()
15+
value = '{"value": %f}' % loadavg
16+
url = base_url + '/streams/'+ stream_id +'/data'
17+
subprocess.call(['curl', '-XPOST', '-H', 'Content-type: application/json', '-d', value, url])
18+

0 commit comments

Comments
 (0)