53
|
1 #!bin/python
|
|
2
|
|
3 """
|
|
4 X server idle time is now available over http!
|
|
5 """
|
|
6
|
|
7 from bottle import run, get, put, request, response
|
|
8 import subprocess, sys, socket
|
|
9 from rdflib import Namespace, URIRef, Literal
|
|
10
|
|
11 # from http://bebop.bigasterisk.com/python/
|
|
12 import xss
|
|
13 # another option: http://thp.io/2007/09/x11-idle-time-and-focused-window-in.html
|
|
14
|
|
15 DEV = Namespace("http://projects.bigasterisk.com/device/")
|
|
16 ROOM = Namespace("http://projects.bigasterisk.com/room/")
|
|
17
|
|
18 sys.path.append("/my/site/magma")
|
|
19 from stategraph import StateGraph
|
|
20
|
|
21 host = socket.gethostname()
|
|
22
|
|
23 @get("/")
|
|
24 def index():
|
|
25 xss.get_info() # fail if we can't get the display or something
|
|
26 return '''
|
|
27 Get the <a href="idle">X idle time</a> on %s.
|
|
28 <a href="graph">rdf graph</a> available.''' % host
|
|
29
|
|
30 @get("/idle")
|
|
31 def monitor():
|
|
32 return {"idleMs" : xss.get_info().idle}
|
|
33
|
|
34 @get("/graph")
|
|
35 def graph():
|
|
36 g = StateGraph(ctx=DEV['xidle/%s' % host])
|
|
37 g.add((URIRef("http://bigasterisk.com/host/%s/xidle" % host),
|
|
38 ROOM['idleTimeMs'],
|
|
39 Literal(xss.get_info().idle)))
|
|
40
|
|
41 response.set_header('Content-type', 'application/x-trig')
|
|
42 return g.asTrig()
|
|
43
|
|
44 run(host="0.0.0.0", server='gunicorn', port=9107, quiet=True)
|
|
45
|