JNA is unable to get system idle time in ubuntu 11.10 version onwards - jna

JNA is unable to get system idle time in ubuntu 11.10 version onwards.
public static long getIdleTimeMillis() {
X11.Window win = null;
Xss.XScreenSaverInfo info = null;
X11.Display dpy = null;
final X11 x11 = X11.INSTANCE;
final Xss xss = Xss.INSTANCE;
long idlemillis = 0L;
try {
dpy = x11.XOpenDisplay(null);
win = x11.XDefaultRootWindow(dpy);
info = xss.XScreenSaverAllocInfo();
xss.XScreenSaverQueryInfo(dpy, win, info);
idlemillis = info.idle.longValue();
} finally {
if (info != null)
x11.XFree(info.getPointer());
info = null;
if (dpy != null)
x11.XCloseDisplay(dpy);
dpy = null;
}
return idlemillis;
I am using this code to capture idle time. It is working fine in lower versions of ubuntu. but it is not working in latest versions.
It is not moving from the line
final Xss xss = Xss.INSTANCE;
please suggest me a proper solution.

In fact, this code works only if "libxss1" package is installed on system.
Since ubuntu 11.10, libXss.so is not installed by default.
sudo apt-get install libxss1
solve this, but require additional system package installation

Related

Resolve mx records for a domain using dnsjava in kubernetes/ docker

I'm trying to resolve mx records in a kubernetes pod.
The dnsjava library works when tested on mac and ubuntu outside of a container but returns an empty array once deployed.
What needs to be available in k8s or the docker image for this to work?
See https://github.com/dnsjava/dnsjava
EDIT 1
Record[] records;
try {
records = new Lookup(mailDomain, Type.MX).run();
} catch (TextParseException e) {
throw new IllegalStateException(e);
}
if (records != null && records.length > 0) {
for (final Record record : records) {
MXRecord mx = (MXRecord) record;
//do something with mx...
}
} else {
log.warn("Failed to determine MX record for {}", mailDomain);
}
The log.warn is always executed in K8s. The docker image is openjdk:11-jdk-slim i.e. it's Debian. I just tested on Debian outside of Docker and it worked as well.
In the end I couldn't get dnsjava to work in docker/k8s.
I used JNDI directly, following https://stackoverflow.com/a/16448180/400048
this works without any issues exactly as given in that answer.

How to find ESXi host serial number using pyvmomi?

Previously for VCenter software version 6.0.0 I was using vim.host.SystemIdentificationInfo which was giving me the desired value inside identifierValue
But for VCenter software version 6.5.0 vim.host.SystemIdentificationInfo is returning me an empty list
Output:
'hardware': (vim.host.HardwareInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
systemInfo = (vim.host.SystemInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
vendor = 'Cisco Systems Inc',
model = 'UCSB-B200-M4',
uuid = '16fa7876-059e-e711-0000-00000000001f',
otherIdentifyingInfo = (vim.host.SystemIdentificationInfo) []
}
However I am checking from the ESXi host cli I am getting the serial number by using the command:
esxcfg-info | grep "Serial N"
|----Serial Number............................................FLM1950CK2X
So, the value is available but not returned by pyvmomi currently.
Could anyone please help me to find it out?
host.hardware.systemInfo.serialNumber

ASP.NET Core 2.0 application running in Linux container suffers from locking issues when there are many calls to Trace.WriteLine()

Our application is an ASP.NET Core 2.0 WebAPI deployed in Linux Docker containers and running in Kubernetes.
During load testing, we discovered intermittent spikes in CPU usage that our application would never recover from.
We used perfcollect to collect traces from a container so that we could compare a successful test and a test with CPU spikes. We discovered that around 75% of the CPU time in the failing test was spent in JIT_MonRelaibleEnter_Protable, an interface of lock operations. The caller was System.Diagnostics.TraceSource.dll.
Our application was ported from .NET Framework and contained a lot of calls to System.Diagnostics.Trace.WriteLine(). When we removed all of these, our CPU/memory usage reduced by more than 50% and we don't see the CPU spikes anymore.
I want to understand the cause of this issue.
In the corefx repo, I can see that a default trace listener is setup in TraceInternal.cs:
public static TraceListenerCollection Listeners
{
get
{
InitializeSettings();
if (s_listeners == null)
{
lock (critSec)
{
if (s_listeners == null)
{
// In the absence of config support, the listeners by default add
// DefaultTraceListener to the listener collection.
s_listeners = new TraceListenerCollection();
TraceListener defaultListener = new DefaultTraceListener();
defaultListener.IndentLevel = t_indentLevel;
defaultListener.IndentSize = s_indentSize;
s_listeners.Add(defaultListener);
}
}
}
return s_listeners;
}
}
I can see that DefaultTraceListener.cs calls Debug.Write():
private void Write(string message, bool useLogFile)
{
if (NeedIndent)
WriteIndent();
// really huge messages mess up both VS and dbmon, so we chop it up into
// reasonable chunks if it's too big
if (message == null || message.Length <= InternalWriteSize)
{
Debug.Write(message);
}
else
{
int offset;
for (offset = 0; offset < message.Length - InternalWriteSize; offset += InternalWriteSize)
{
Debug.Write(message.Substring(offset, InternalWriteSize));
}
Debug.Write(message.Substring(offset));
}
if (useLogFile && !string.IsNullOrEmpty(LogFileName))
WriteToLogFile(message);
}
In Debug.Unix.cs, I can see that there is a call to SysLog:
private static void WriteToDebugger(string message)
{
if (Debugger.IsLogging())
{
Debugger.Log(0, null, message);
}
else
{
Interop.Sys.SysLog(Interop.Sys.SysLogPriority.LOG_USER | Interop.Sys.SysLogPriority.LOG_DEBUG, "%s", message);
}
}
I don't have a lot of experience working with Linux but I believe that I can simulate the call to SysLog by running the following command in the container:
logger --socket-errors=on 'SysLog test'
When I run that command, I get the following response:
socket /dev/log: No such file or directory
So it looks like I can't successfully make calls to SysLog from the container. If this is indeed what is going on when I call Trace.WriteLine(), why is it causing locking issues in my application?
As far as I can tell, EnvVar_DebugWriteToStdErr is not set in my container so it should not be attempting to write to StdErr.
The solution can be that rsyslog is not running. Is that installed in your container? Use a base image that has rsyslog built in.
This link can help too.

Android Espresso Turn OFF Cellular Data on Android Emulator through Runtime() not working

I am writing instrumentation test for a scenario where data is not available on android emulator (api 16 and api 23). I tried the following code to disable data,
#Test
public void disconnectData() throws IOException {
String line;
Process p = Runtime.getRuntime().exec("svc data disable");
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = in.readLine()) != null) {
System.out.println(line);
Log.d("asdf", line);
}
in.close();
}
It does not do anything. Data is not disabled. It simply passed without error. There is no output.
If I run the same command from terminal using adb, it works:
adb -s emulator-5554 shell
svc data disable
Alternative solution is to use mockwebserver. E.g.,
server.enqueue(new MockResponse()
.setResponseCode(HttpURLConnection.HTTP_INTERNAL_ERROR)
.setBody(getStringFromFile(getInstrumentation().getContext(), "login.json")));

How to start Edge browser in Incognito mode using selenium remote webdriver?

Currently we are working on selenium (2.53.0) with Edge browser using C#.
Edge browser stores cache information at 'localAppdata' folder because of cache, we are facing some issues while test cases execution.
I try to delete all cookies information using selenium (DeleteAllCookies) but it not working for Edge browser.
I read couple of Microsoft forums only way to skip cache, when we start Edge browser on incognito mode.
Can any one suggest how to start Edge browser instance in private (incognito mode) using selenium remote-webdriver
if you want to open Edge in Private (Incognito) mode, you can use this C# code:
EdgeOptions options = new EdgeOptions();
options.AddAdditionalCapability("InPrivate", true);
this.edgeDriver = new EdgeDriver(options);
Here is an example of what I use when setting up an EdgeDriver instance. (C#)
private IWebDriver SetupEdgeWebDriver(bool runHeadlessOnPipeline, int implicitWait = 12500)
{
IWebDriver webDriverInstance;
EdgeOptions edgeOptions = new EdgeOptions
{
//Microsoft Edge (Chromium)
UseChromium = true
};
if (EnableIncognito)
{
edgeOptions.AddArgument("inprivate");
}
edgeOptions.BinaryLocation = "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe";
//azure devops pipeline
if (PipelineRun)
{
edgeOptions.AddArgument("disable-gpu");
edgeOptions.AddArgument("window-size=1920,960");
if (runHeadlessOnPipeline)
{
edgeOptions.AddArgument("headless");
}
}
//running on your local machine
else
{
edgeOptions.AddArgument("start-maximized");
}
edgeOptions.SetLoggingPreference(LogType.Driver, LogLevel.Debug);
webDriverInstance = new EdgeDriver(edgeOptions);
webDriverInstance.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(implicitWait);
return webDriverInstance;
}
This is the code I'm using with Selenium.WebDriver 4.0.0 and C# dotnet 5.0
EdgeOptions options = new();
options.AddArguments("InPrivate");
driver = new EdgeDriver(options);

Resources