Tuesday, May 26, 2015
Docker: check the memory used by docker containers at specific host
for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do echo "" && docker ps | grep $line | awk '{printf $NF" "}' && echo -e "\nmemory usage: $(( `cat /sys/fs/cgroup/memory/docker/$line*/memory.usage_in_bytes` / 1024 / 1024 ))MB" && echo max memory usage: $(( `cat /sys/fs/cgroup/memory/docker/$line*/memory.max_usage_in_bytes` / 1024 / 1024 ))MB ; done
Thursday, May 21, 2015
Tuesday, April 28, 2015
Oneliner for displaying apt packages which could be updated
function a { read input;dpkg -l ${input} | grep " ${input} " | awk '{$1=$2=$3=$4="";print $0}' | sed 's/^ *//';unset input;};{ apt-get --just-print upgrade 2>&1 | perl -ne 'if (/Inst\s([\w,\-,\d,\.,~,:,\+]+)\s\[([\w,\-,\d,\.,~,:,\+]+)\]\s\(([\w,\-,\d,\.,~,:,\+]+)\)? /i) {print "$1 (\e[1;34m$2\e[0m -> \e[1;32m$3\e[0m)\n"}';} | while read -r line; do echo -en "$line $(echo $line | awk '{print $1}' | a )\n"; done;
Example output (colored):
policykit-1 (0.105-4ubuntu2 -> 0.105-4ubuntu2.14.04.1) framework for managing administrative policies and privileges
python-urllib3 (1.7.1-1build1 -> 1.7.1-1ubuntu3) HTTP library with thread-safe connection pooling for Python
python-requests (2.2.1-1ubuntu0.1 -> 2.2.1-1ubuntu0.2) elegant and simple HTTP library for Python, built for human beings
software-properties-common (0.92.37.2 -> 0.92.37.3) manage the repositories that you install software from (common)
python3-software-properties (0.92.37.2 -> 0.92.37.3) manage the repositories that you install software from
cloud-guest-utils (0.27-0ubuntu9 -> 0.27-0ubuntu9.1) cloud guest utilities
cloud-init (0.7.5-0ubuntu1.3 -> 0.7.5-0ubuntu1.5) Init scripts for cloud instances
grub-legacy-ec2 (0.7.5-0ubuntu1.3 -> 0.7.5-0ubuntu1.5) Handles update-grub for ec2 instances
icinga2-doc (2.3.4-2~ppa1~trusty1 -> 2.3.4-3~ppa1~trusty1) host and network monitoring system - documentation
Monday, April 27, 2015
Useful nmap commands
Nmap scan of opened ports (including both udp and tcp ports):
sudo nmap --min-parallelism 100 -sT -sU -Pn localhost
sudo nmap --min-parallelism 100 -sT -sU -Pn localhost
Sunday, March 29, 2015
How do I check the default value for specific Java parameter at my OS?
java -XX:+PrintFlagsFinal -version | grep ThreadStackSize
Friday, October 10, 2014
Sevntu Checkstyle release 1.12.0
Official page: http://sevntu-checkstyle.github.io/sevntu.checkstyle/#1.12.0
New and noteworthy:
- Update in RedundantReturnCheck
Increased Check's handling of redundant returns in constructors and void methods, particularly: fixed problem of handling redundant returns in try-catch-finally blocks. Done by Aleksey Nesterenko.
- Update in ForbidThrowAnonymousExceptionsCheck
Now this Check puts violation on throwing anonymous exception even in case if it is defined before throwing. Done by Aleksey Nesterenko.
- Update in LineLengthCheck
Now check prints The Current Line Length In all it's warnings. Done by Aleksey Nesterenko.
This Check highlights variable definition statements where diamond operator could be used.
Rationale: using diamond operator (introduced in Java 1.7) leads to shorter code
and better code readability. It is suggested by Oracle that the diamond primarily using
for variable declarations. E.g. of statements:
Without diamond operator:
Map<String, Map<String, Integer>> someMap = new HashMap<String, Map<String, Integer>>();
With diamond operator:
Map<String, Map<String, Integer>> someMap = new HashMap<>();
Done by Aleksey Nesterenko.
This Check warns on propagation of inner private types to outer classes:
- Externally accessible method if it returns private inner type.
- Externally accessible field if it's type is a private inner type.
These types could be private inner classes, interfaces or enumerations.
Example:
class OuterClass {
public InnerClass innerFromMain = new InnerClass(); //WARNING
private class InnerClass { ... }
public InnerClass getValue() { //WARNING
return new InnerClass();
}
private interface InnerInterface { ... }
public Set<InnerInterface> getValue() { //WARNING
return new TreeSet<InnerInterface>;
}
private Enum Fruit {Apple, Pear}
public Fruit getValue() { //WARNING
return Fruit.Apple;
}
public someMethod(InnerClass innerClass) { ... } //WARNING
}
Rationale: it is possible to return private inner type or use it as the parameter of non-private method, but it is impossible to use it in other classes (besides inner classes) unless it extends or implements at least one non-private class or interface. Such situation usually happens after bulk refactoring and usually means dead/useless code.
Done by Aleksey Nesterenko.
- Replaced existing NestedTernaryCheck with more general TernaryPerExpressionCountCheck.
New TernaryPerExpressionCountCheck restricts the number of ternary operators in expression to a specific limit.
Rationale: This Check helps to improve code readability by pointing developer on
expressions which contain more than user-defined count of ternary operators.
It points to complicated ternary expressions. Reason:
- Complicated ternary expressions are not easy to read.
- Complicated ternary expressions could lead to ambiguous result if user
does not know Java's operators priority well, e.g.:
String str = null;
String x = str != null ? "A" : "B" + str == null ? "C" : "D";
System.out.println(x);
Output for code above is "D", but more obvious would be "BC".
Check has following properties:
maxTernaryPerExpressionCount - limit of ternary operators per expression
ignoreTernaryOperatorsInBraces - if true Check will ignore ternary operators
in braces (braces explicitly set priority level)
ignoreIsolatedTernaryOnLine - if true Check will ignore one line ternary operators,
if only it is places in line alone.
Options ignoreTernaryOperatorsInBraces and ignoreIsolatedTernaryOnLine can
make Check less strict, e.g.:
Using ignoreTernaryOperatorsInBraces option (value = true)
does not put violation on code below:
callString = "{? = call " +
(StringUtils.hasLength(catalogNameToUse)
? catalogNameToUse + "." : "") +
(StringUtils.hasLength(schemaNameToUse)
? schemaNameToUse + "." : "") +
procedureNameToUse + "(";
When using ignoreIsolatedTernaryOnLine (value = true), even without
ignoreTernaryOperatorsInBraces option Check won't warn on code below:
int a = (d == 5) ? d : f
+
((d == 6) ? g : k);
Done by Aleksey Nesterenko.
- Update in CustomDeclarationOrderCheck
Updated Check to treat more king of methods as setters. E.g., now Check treats 'set' method as setter, in cases like:
public void setWorkMode(String workMode) {
this.workMode = WorkMode.valueOf(workMode);
}
public void setUserCache(UserCache userCache) {
super.setUserCache(userCache);
}
public void setY(Integer y) { // setter
this.y = Integer.parseInt(y + "");
}
Done by Alexey Nesterenko.
General information:
Repository: https://github.com/sevntu-checkstyle/sevntu.checkstyle
mail-list: https://groups.google.com/forum/?hl=en#!forum/sevntu-checkstyle
New and noteworthy:
- Update in RedundantReturnCheck
Increased Check's handling of redundant returns in constructors and void methods, particularly: fixed problem of handling redundant returns in try-catch-finally blocks. Done by Aleksey Nesterenko.
- Update in ForbidThrowAnonymousExceptionsCheck
Now this Check puts violation on throwing anonymous exception even in case if it is defined before throwing. Done by Aleksey Nesterenko.
- Update in LineLengthCheck
Now check prints The Current Line Length In all it's warnings. Done by Aleksey Nesterenko.
This Check highlights variable definition statements where diamond operator could be used.
Rationale: using diamond operator (introduced in Java 1.7) leads to shorter code
and better code readability. It is suggested by Oracle that the diamond primarily using
for variable declarations. E.g. of statements:
Without diamond operator:
Map<String, Map<String, Integer>> someMap = new HashMap<String, Map<String, Integer>>();
With diamond operator:
Map<String, Map<String, Integer>> someMap = new HashMap<>();
Done by Aleksey Nesterenko.
This Check warns on propagation of inner private types to outer classes:
- Externally accessible method if it returns private inner type.
- Externally accessible field if it's type is a private inner type.
These types could be private inner classes, interfaces or enumerations.
Example:
class OuterClass {
public InnerClass innerFromMain = new InnerClass(); //WARNING
private class InnerClass { ... }
public InnerClass getValue() { //WARNING
return new InnerClass();
}
private interface InnerInterface { ... }
public Set<InnerInterface> getValue() { //WARNING
return new TreeSet<InnerInterface>;
}
private Enum Fruit {Apple, Pear}
public Fruit getValue() { //WARNING
return Fruit.Apple;
}
public someMethod(InnerClass innerClass) { ... } //WARNING
}
Rationale: it is possible to return private inner type or use it as the parameter of non-private method, but it is impossible to use it in other classes (besides inner classes) unless it extends or implements at least one non-private class or interface. Such situation usually happens after bulk refactoring and usually means dead/useless code.
Done by Aleksey Nesterenko.
- Replaced existing NestedTernaryCheck with more general TernaryPerExpressionCountCheck.
Rationale: This Check helps to improve code readability by pointing developer on
expressions which contain more than user-defined count of ternary operators.
It points to complicated ternary expressions. Reason:
- Complicated ternary expressions are not easy to read.
- Complicated ternary expressions could lead to ambiguous result if user
does not know Java's operators priority well, e.g.:
String str = null;
String x = str != null ? "A" : "B" + str == null ? "C" : "D";
System.out.println(x);
Output for code above is "D", but more obvious would be "BC".
Check has following properties:
maxTernaryPerExpressionCount - limit of ternary operators per expression
ignoreTernaryOperatorsInBraces - if true Check will ignore ternary operators
in braces (braces explicitly set priority level)
ignoreIsolatedTernaryOnLine - if true Check will ignore one line ternary operators,
if only it is places in line alone.
Options ignoreTernaryOperatorsInBraces and ignoreIsolatedTernaryOnLine can
make Check less strict, e.g.:
Using ignoreTernaryOperatorsInBraces option (value = true)
does not put violation on code below:
callString = "{? = call " +
(StringUtils.hasLength(catalogNameToUse)
? catalogNameToUse + "." : "") +
(StringUtils.hasLength(schemaNameToUse)
? schemaNameToUse + "." : "") +
procedureNameToUse + "(";
When using ignoreIsolatedTernaryOnLine (value = true), even without
ignoreTernaryOperatorsInBraces option Check won't warn on code below:
int a = (d == 5) ? d : f
+
((d == 6) ? g : k);
Done by Aleksey Nesterenko.
- Update in CustomDeclarationOrderCheck
Updated Check to treat more king of methods as setters. E.g., now Check treats 'set' method as setter, in cases like:
public void setWorkMode(String workMode) {
this.workMode = WorkMode.valueOf(workMode);
}
public void setUserCache(UserCache userCache) {
super.setUserCache(userCache);
}
public void setY(Integer y) { // setter
this.y = Integer.parseInt(y + "");
}
Done by Alexey Nesterenko.
General information:
Repository: https://github.com/sevntu-checkstyle/sevntu.checkstyle
mail-list: https://groups.google.com/forum/?hl=en#!forum/sevntu-checkstyle
Tuesday, October 7, 2014
Oracle: check real table size on disk
SELECT
owner, table_name, TRUNC(sum(bytes)/1024/1024) Meg
FROM
(SELECT segment_name table_name, owner, bytes
FROM dba_segments
WHERE segment_type = 'TABLE'
UNION ALL
SELECT i.table_name, i.owner, s.bytes
FROM dba_indexes i, dba_segments s
WHERE s.segment_name = i.index_name
AND s.owner = i.owner
AND s.segment_type = 'INDEX'
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.segment_name
AND s.owner = l.owner
AND s.segment_type = 'LOBSEGMENT'
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.index_name
AND s.owner = l.owner
AND s.segment_type = 'LOBINDEX')
WHERE owner in ('SCHEMA_NAME')
GROUP BY table_name, owner
HAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */
ORDER BY SUM(bytes) desc ;
owner, table_name, TRUNC(sum(bytes)/1024/1024) Meg
FROM
(SELECT segment_name table_name, owner, bytes
FROM dba_segments
WHERE segment_type = 'TABLE'
UNION ALL
SELECT i.table_name, i.owner, s.bytes
FROM dba_indexes i, dba_segments s
WHERE s.segment_name = i.index_name
AND s.owner = i.owner
AND s.segment_type = 'INDEX'
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.segment_name
AND s.owner = l.owner
AND s.segment_type = 'LOBSEGMENT'
UNION ALL
SELECT l.table_name, l.owner, s.bytes
FROM dba_lobs l, dba_segments s
WHERE s.segment_name = l.index_name
AND s.owner = l.owner
AND s.segment_type = 'LOBINDEX')
WHERE owner in ('SCHEMA_NAME')
GROUP BY table_name, owner
HAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */
ORDER BY SUM(bytes) desc ;
Subscribe to:
Posts (Atom)