How to retrive information of desktop number for each monitor under linux (by vala language) - vala

I'm working on a plank plugin recently, I want this plugin to display current desktop number and total number of desktops under current monitor.
I'm trying to get above numbers by examing root window's properties such as _NET_CURRENT_DESKTOP, _NET_NUMBER_OF_DESKTOPS, _NET_DESKTOP_NAMES, below is an example output of xprop command under linux:
>> xprop -frame
_NET_WM_ICON_NAME(UTF8_STRING) =
_NET_ACTIVE_WINDOW(WINDOW): window id # 0x3c005d0
_NET_CLIENT_LIST(WINDOW): window id # 0x3c005d0, 0x4200003, 0x3200002, 0x3c00007, 0x2a00003, 0x1c00003, 0x2800003
_NET_CLIENT_LIST_STACKING(WINDOW): window id # 0x1c00003, 0x3200002, 0x2800003, 0x2a00003, 0x3c00007, 0x4200003, 0x3c005d0
XIM_SERVERS(ATOM) = #server=fcitx5
XFree86_DDC_EDID1_RAWDATA(INTEGER) = ......
AT_SPI_BUS(STRING) = "unix:path=/run/user/974/at-spi/bus_0,guid=d2b64617d145d6b9bd20e88d6332dce1"
_NET_CURRENT_DESKTOP(CARDINAL) = 2
_NET_NUMBER_OF_DESKTOPS(CARDINAL) = 6
_NET_DESKTOP_NAMES(UTF8_STRING) = "Work", "Work", "Work", "2", "2", "3"
_NET_SUPPORTING_WM_CHECK(WINDOW): window id # 0x400005
And I've finished a demo like this, W is first desktop name's first letter, 2 is second desktop's name:
But there is still some problems:
PROBLEM 1 I'm using vala to subscribe signal of workspace change, but I can not get callback while the newly create Desktop is empty, in other ways, I can only get callback when there is at least one window in newly created desktop.
Wnck.Screen screen = Wnck.Screen.get_default ();
// will not be invoked in handle_workspace_changed
// if the newly created desktop is empty
screen.active_workspace_changed.connect_after (handle_workspace_changed);
PROBLEM 2 I want get current desktop and total desktop numbers for each monitor, but the windows properties above is the total number of all my 3 monitors. Such as I have these desktops of each monitor:
Monitor 1: Work
Monitor 2: Work、2、3
Monitor 3: Work、2
Assume I'm currently on Monitor 3 desktop 2(empty desktop).
The root window actual properties will be :
_NET_CURRENT_DESKTOP(CARDINAL) = 2
_NET_NUMBER_OF_DESKTOPS(CARDINAL) = 6
_NET_DESKTOP_NAMES(UTF8_STRING) = "Work", "Work", "Work", "2", "2", "3"
These is not the correct behavior I want, what expect is:
_NET_CURRENT_DESKTOP(CARDINAL) = 1 // because I'm currently on desktop 2, but this value will not change until I put some window in desktop 2 (problem 1)
_NET_NUMBER_OF_DESKTOPS(CARDINAL) = 2 // Monitor 3 has 2 desktops which are: Work、2
_NET_DESKTOP_NAMES(UTF8_STRING) = "Work", "2" // Monitor 3 has 2 desktops which are: Work、2
So I'm current on _NET_CURRENT_DESKTOP(CARDINAL) = 1 desktop with name _NET_DESKTOP_NAMES(UTF8_STRING)[1] = "2", and there are _NET_NUMBER_OF_DESKTOPS(CARDINAL) = 2 desktops on this monitor.
So any suggestions to solve problem 1&2 ?

Related

awesomewm - Dualscreen Problem with VirtualBox

I have a problem with Virtualbox VM windows when I use a dualscreen configuration. I want to have the VM windows on the right hand screen, however, the window always "jumps" to the left hand screen if the resolution of the VM changes or if the virtual monitor switchs to standby.
s2 = screen:count()
...
{ rule = { class = "VirtualBox Machine" },
properties = { screen = s2,tag = "8 VM" } },
Does somebody know how I can solve this problem?
I can't say for sure, but it sounds like you need
client.disconnect_signal("request::geometry", awful.ewmh.client_geometry_requests)
Somewhere in rc.lua. This disables the ability of an application to move itself around.

New Relic alert when application stop

I have an application deployed on PCF and have a new relic service binded to it. In new relic I want to get an alert when my application is stopped . I don't know whether it is possible or not. If it is possible can someone tell me how?
Edit: I don't have access to New Relic Infrastructure
Although an 'app not reporting' alert condition is not built into New Relic Alerts, it's possible to rig one using NRQL alerts. Here are the steps:
Go to New Relic Alerts and begin creating a NRQL alert condition:
NRQL alert conditions
Query your app with:
SELECT count(*) FROM Transaction WHERE appName = 'foo'
Set your threshold to :
Static
sum of query results is below x
at least once in y minutes
The query runs once per minute. If the app stops reporting then count will turn the null values into 0 and then we sum them. When the number goes below whatever your threshold is then you get a notification. I recommend using the preview graph to determine how low you want your transactions to get before receiving a notification. Here's some good information:
Relic Solution: NRQL alerting with “sum of the query results”
Basically you need to create a NewRelic Alert with conditions that check if application available, Specially you can use Host not reporting alert condition
The Host not reporting event triggers when data from the Infrastructure agent does not reach the New Relic collector within the time frame you specify.
You could do something like this:
// ...
aggregation_method = "cadence" // Use cadence for process monitoring otherwise it might not alert
// ...
nrql {
// Limitation: only works for processes with ONE instance; otherwise use just uniqueCount() and set a LoS (loss of signal)
query = "SELECT filter(uniqueCount(hostname), WHERE processDisplayName LIKE 'cdpmgr') OR -1 FROM ProcessSample WHERE GENERIC_CONDITIONS FACET hostname, entityGuid as 'entity.guid'"
}
critical {
operator = "below"
threshold = 0
threshold_duration = 5*60
threshold_occurrences = "ALL"
}
Previous solution - turned out it is not that robust:
// ...
critical {
operator = "below"
threshold = 0.0001
threshold_duration = 600
threshold_occurrences = "ALL"
}
nrql {
query = "SELECT percentage(uniqueCount(entityAndPid), WHERE commandLine LIKE 'yourExecutable.exe') FROM ProcessSample FACET hostname"
}
This will calculate the fraction your process has against all other processes.
If the process is not running the percentage will turn to 0. If you have a system running a vast amount of processes it could fall below 0.0001 but this is very unprobable.
The advantage here is that you can still have an active alert even if the process slips out of your current time alert window after it stopped. Like this you prevent the alert from auto-recovering (compared to just filtering with WHERE).

How can I reset ESP8266 MicroPython after main.py crashes?

I have a NodeMCU ESP8266 board running MicroPython. I'm running a web server on my ESP8266. This is my first IoT project based on one of these boards.
The below is a snippet of the code.
This is being executed within main.py. Every now and then, something causes the code to crash (perhaps timing and request based). When main.py exits, for whatever reason, I'm dropped back at the python CLI.
I'd like for the board to reset when this happens (if there isn't a better way).
What is the best method of restarting/reseting the ESP8266?
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen(5)
print('listening on', addr)
while True:
cl, addr = s.accept()
print('client connected from', addr)
cl_file = cl.makefile('rwb', 0)
print("Request:")
while True:
line = cl_file.readline()
print("Line:" , line)
if not line or line == b'\r\n':
print("breaking")
break
if line == b'GET /active HTTP/1.1\r\n':
MicroPython has machine.reset() function to reset a board.
Python (not just MicroPython) uses exception handling to handle errors.
Combining the two, you can easily achieve what you want. For example:
a = 4
b = 2
try:
a / b
except:
machine.reset()
If in the code above you replace value of b with 0, your board will reset. If you think about it for a bit, you probably will find out that it doesn't make much sense - you don't want your board suddenly reset if you just divide by 0 by mistake or otherwise. There're got to be better ways to handle errors! Likewise, you may want to think about your own case and see if resetting the board is really the best choice. If you think that yes, that's fine, just always keep in mind that you programmed your board to suddenly reset. Otherwise, your next question here may be "My board suddenly resets! Why???" ;-)
It may be late for the original question, but the answer I am going to share might help other people. Consider it is not a final solution, but in many scenarios, it may save a day. You can explore your case.
The solution is using the internal scheduling function of MicroPython. since its execution is guaranteed, then its behavior can be used as a tool to mimic a functional watchdog.
Following code will run with given timers and threshold which can be customized in your case, and if the timer reaches its threshold, and the value of wd_buffer is not updated for that time, then the function might be called, and we repeat the process again.
So in order to prevent the ESP getting restarted in this case after 12 sec, you have to in someplace in your code, periodically (shorter than 12 sec or adjust the timer and threshold according to your need) update the value of the Global wd_buffer variable. Hope it helps.
# Simple WD - Global Variable
wd_feeder = 0
wd_buffer = 0
wd_counter = 0
wd_threshold = 4
def wd_checker(calledvalue):
print('watchdog is checking... feeder= {} buffer= {}'.format(wd_feeder, wd_buffer))
global wd_counter
global wd_buffer
global wd_feeder
if wd_feeder == wd_buffer:
print('state is suspicious ... counter is {} incrementing the counter'.format(wd_counter))
wd_counter += 1
else:
wd_counter = 0
wd_feeder = wd_buffer
if wd_counter == wd_threshold:
print('Counter is reached its threshold, following function will be called')
wd_feeder = wd_buffer = wd_counter = 0
machine.reset()
if __name__ == '__main__':
scheduler_wd = machine.Timer(-1)
scheduler_wd.init(period=3000, mode=machine.Timer.PERIODIC, callback=wd_checker)
you could add a while loop checking for the Flash Button (GPIO pin 0) like this:
import machine
pin = machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP)
while pin.value():
print('Put your code here...')
print('..this will looping until the Flash button is pressed...')
print('...and then it continues here.')
You could execute your code (which should be outside of the main.py -> other file) from the boot or the main.py. if it drops out it should execute the following code, which could trigger a reset.
You may have to catch the error first.
I hope I helped

Xvfb - start or attach a window manager to xvfb

For testing purpose, I used Xvfb.
Today, I want to do some test with wmctrl commmand. I do some test in python like this :
display = ":99"
pXvfb = subprocess.Popen(["Xvfb", display, "-screen", "0", "1024x768x24"])
# wait that xvfb is up
time.sleep(1)
os.environ["DISPLAY"] = display
p = subprocess.Popen( ["wmctrl", "-l" ] )
p.wait()
pXvfb.terminate()
In this test, wmctrl says :
Cannot get client list properties.
(_NET_CLIENT_LIST or _WIN_CLIENT_LIST)
I think, it's normal because I haven't any window manager attach to my Xvfb.
How to start a windows manager (Enlighenment should be good for my case) to manage only Xvfb ?
After some days of works, I can answer myself. Solution is easy as possible : just start windows manager with variable DISPLAY set. So in my python script, I just do :
display = ":99"
pXvfb = subprocess.Popen(["Xvfb", display, "-screen", "0", "1024x768x24"])
# wait that xvfb is up
time.sleep(1)
os.environ["DISPLAY"] = display
# start windows manager
pWM = subprocess.Popen( ["/usr/bin/enlightenment_start", ] )
p = subprocess.Popen( ["wmctrl", "-l" ] )
p.wait()
pXvfb.terminate()

On local PC IIS and Browser maxes out CPU with large result set

I just upgraded to VS 2013 and also started a new MVC project, and am being faced with 99% CPU usage for a couple minutes by IIS while debugging on my local PC. (Happens in both Release and Debug mode) I just realized that the problem is proportional to the number of lines returned by by Linq Query. If I use Take(1) or Take(10) it's fine. If I use Take(100) the problem occurs.
Here is my actionresult (with private info altered):
public ActionResult Summary(string daystoshow, DateTime? day = null)
{
int daysToShow = daystoshow.ToSafeInt();
if (daysToShow < 1) daysToShow = 2;
if (day == null) day = Convert.ToDateTime("4/14/2014");
SummaryViewModel m = new SummaryViewModel();
string warnings = "";
var ef1 = new carshowEntities();
DateTime dayAtMidnight = Convert.ToDateTime(((DateTime)day).AddDays(daysToShow).ToShortDateString());
var diplayItems = (from x in ef1.islands
join y in ef1.cars on x.serid equals y.serid where x.dt==12
join z in ef1.ITEMS on y.serviceno equals z.ITEMNO
join x2 in ef1.islands on x.serid equals x2.serid where x2.dt==8
join i in ef1.INVOICES on x.carStyle equals i.carStyle where i.STATUS==8
where x.LiscenceDate > day && x.LiscenceDate < dayAtMidnight
orderby x.LiscenceDate, y.serviceno, x.serid
select new ReturnedItem()
{
CarOrderDate = (DateTime)x.LiscenceDate,
serial = x.serid,
ItemCode = y.serviceno,
Description = z.Color,
DateSold = (DateTime)x2.LiscenceDate,
ID = i.IX_ID
}).Take(100).ToList();
m.daystoshow = daysToShow;
m.day = day;
m.diplayItems = diplayItems;
m.warnings = warnings;
return View(m);
}
I haven't found any other posts that describe the exact circumstances here.
1) When the site is published, it works perfectly fine from the server.
2) CPU usage goes up to 99% when running my MVC project in debug mode.
3) The problem does not happen if I publish locally.
4) This happens in both IIS and IIS Express when run from VS in Debug or Release mode.
5) It doesn't happen with other sites, just this one project so far.
6) It's a simple project, one actionresult, and one page with a table of about 200 lines, populated with a Linq query.
Is there any way for the debugger to at least show me what it's doing?
EDIT:
With further investigation, I notice that if I wait 2 minutes the CPU comes back from IIS, but THEN the Web Browser (Firefox or Chrome) takes up 99% CPU for another 2 minutes.
I found that the solution was simply to turn off "Browser Link" which was a new feature in VS 2013, after much debugging and searching.
Browser Link can be turned off in the toolbar by clicking the down arrow on the icon that looks like a refresh button.
Browser link is some way of making changes to the page in the browser itself, which seems to be CPU intensive, so doing that with a large number of elements causes the CPU to spike.

Resources