I'm trying to get CPU and memory usage with SNMP. I have a Java code which takes the oid and runs the "get" command. I can reach the values with MIB-II. However when i import HOST-RESOURCES-MIB in the code i can't get CPU information it returns Null. But some oids work properly in HOST-RESOURCES-MIB.
For example:
hrSystemUpTime(.1.3.6.1.2.1.25.1.1.0) gives me the value 3:51:15.07
hrProcessorLoad(.1.3.6.1.2.1.25.3.3.1.2.0) gives me the value Null
What is the problem?
I've solved the problem. In MIBs the information kept in indexes. Thus, in order to reach a particular information, you need to know which index it's kept.So, i did SNMPWalk on .1.3.6.1.2.1.25.3.3.1.2 for hrProcessorLoad (omit zero) and i got the values. We can also use getNext command to reach the correct index.
Related
I have configAllowedUsers.properties.
It has single in Entry like the following:
users = abc, pew, rt, me1, me3, ku3,........
I have some doubts about length of value stored in it. I will read it using java.util.Properties. Thousands of usernames would be stored in it and I could not store them in database.
I had the same question in mind today, so I started researching. I did not find any limitations originating from java.util.Properties, so it is probably safe to assume that the rules are the same as for String:
A String of length Integer.MAX_VALUE (which is 231-1)
Or half your maximum heap size,
Whichever is reached first in your environment.
Of course, not finding any official statements on this topic does not prove that these assumptions are correct, but let's consider the Properties class innocent unless proven guilty.
I am a new bee to Automation and Java. I am working on a problem which requires me to read the read time stock market data from the database and verify it with the same with the value seen on the UI. I am ok having approximations up to 5% in the value. To verify if these tests have passed its important for me to assert the values with the value in the UI.
I have a small logic to verify these values, I wanted to know if this is a good way of coding on java or do i have a better way to achieve these results.
Alorigthm.
I read the int/float value from db.
Calculate 5% of the value in step 1.
Get the value in the UI and assert if its greater then or equal to value in step 2.
If greater i say Asseert.assertEquals(true,true) else i fail my assert.
If any better way to work for these values, request a better answer.
It's more usual to have your Assertion represent the meaning of your test, having to assert(true, true) does not do this. So:
3. Calculate the absoluete difference between the value obtained in step 1 and the UI value (when I say absolute value, you need to remember that the UI might be higher or lower than the db value, you need to make the difference to be always positive)
4. Assert.assertThat( difference < theFivePercentValue)
Also you could consider using the Hamcrest extension to JUnit that includes a closeTo() method.
I need to look for all web requests received by Application Server to check if the URL has extensions like .css, .gif, etc
Referred how tomcat is listening for every request and they pick the right configured Servlet to serve.
CharChunk , MessageBytes , Mapper
Here is my idea to implement:
Load all the extensions we like to compare and get the byte
representation of them.
get a unique value for this xtension by summing up the bytes in the byte Array // eg: "css".getBytes()
Add the result value to Sorted List
Whenever we receive the request, get the byte representation of the URL // eg: "flipkart.com/eshopping/images/theme.css".getBytes()
Start summing the bytes from the byte array's last index and break when we encounter "." dot byte value
Search for existence of the value thus summed with the Sorted List // Use binary Search here
Kindly give your feed backs about the implementation and issues if any.
-With thanks, Krishna
This sounds way more complicated than it needs to be.
Use String.lastIndeXOf to find the last dot in the URL
Use String.substring to get the extension based on that
Have a HashSet<String> for a set of supported extensions, or a HashMap<String, Whatever> if you want to map the extension to something else
I would be absolutely shocked to discover that this simple approach turned out to be a performance bottleneck - and indeed I suspect it would be more efficient than the approach you suggested, given that it doesn't require the entire URL to be converted into a byte array... (It's not clear why your approach uses byte arrays anyway instead of forming the hash from char values.)
Fundamentally, my preferred approach to performance is:
Do up-front design and testing around things which are hard to change later, architecturally
For everything else:
Determine the performance criteria first so you know when you can stop
Write the simplest code that works
Test it with realistic data
If it doesn't perform well enough, use profilers (etc) to work out where the bottleneck is, and optimize that making sure that you can prove the benefits using your existing tests
I'm writing some Java code using MongoDB with Java API and I'm unsure of some part of the Javadoc.
In a multi-thread context I use DBCollection.html#update(com.mongodb.DBObject, com.mongodb.DBObject) to update a unique document, but I saw that two threads could try to write concurrently. In this context, I observed that only one write was done, as Mongodb seems to use optimistic write lock, but I wanted to find out programmatically in which thread the write was the one who wrote, and which one was not. As a "no update" behavior was silent (I mean no exception or something), I searched into the API some way to answer my issue and after some tests found out this method: WriteResult#getN()
public int getN()
Gets the "n" field
Returns:
The description is, hum... not really exhaustive. My tests showed that the thread that win the write has a getN() that return 1, and the other 0.
So my question is: Could someone confirm this ?
From the GetLastError() documentation
The return value from the command is an object with various fields. The common fields are listed below; there may also be other fields.
ok - true indicates the getLastError command completed successfully. This does NOT indicate there wasn't a last error.
err - if non-null, indicates an error occurred. Value is a textual description of the error.
code - if set, indicates the error code which occurred. connectionId - the id of the connection
lastOp - the op-id from the last operation
For updates:
n - if an update was done, this is the number of documents updated.
So in this context, 'get "n" field' means get n which is the number of documents updated. Without "multi" being set to true it can only be either 0 or 1.
I'm playing with ServerSocket and I don't see / find what the limit of the backlog is. The docs don't say anything about this:
http://download.oracle.com/javase/6/docs/api/java/net/ServerSocket.html#ServerSocket(int, int)
My code is like this:
serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind(null, 10000);
but I assume that 10000 might be too much if a system doesn't have enough RAM. So is there a way to determine the maximum value for backlog that I can use?
It seems like in c++ you can use SOMAXCONN - does something similar exist for Java?
If there were, it would be system dependent: for Windows
The backlog parameter is limited
(silently) to a reasonable value as
determined by the underlying service
provider. Illegal values are replaced
by the nearest legal value. There is
no standard provision to find out the
actual backlog value.
Linux states it a little differently but you would need to go through the sysctl interface (or possibly /proc).
In any case, it would appear you would need to execute some system specific code.
I believe most implementations will just use their maximum value if the specified value is "too big" so this may not be a concern for your application?