sobota, 29 kwietnia 2017

Run Docker Commands without Sudo

1. curl -sSL https://get.docker.io/ubuntu/ | sudo sh
or apt-get install docker docker.io

2. sudo usermod -a -G docker $USER

3. sudo service docker restart

4. logout

output:

marek@ubuntu:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

how to list and delete users in windows cmd terminal

C:\WINDOWS\system32>net user

Konta użytkowników dla \\LAPTOP-UCG24LRB

-------------------------------------------------------------------------------
Administrator            defaultuser0             Gość
Konto domyślne           Marek                    SvcCOPSSH
SvcCWRSYNC



C:\WINDOWS\system32>net user SvcCWRSYNC /delete
Polecenie zostało wykonane pomyślnie.

vagrant problem - kernel_require.rb:54:in `require': cannot load such file

issue:
C:\Users\Marek
λ vagrant
C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- vagrant-share/helper/api (LoadError)
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-share-1.1.7/lib/vagrant-share/activate.rb:244:in `<encoded>'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-share-1.1.7/lib/vagrant-share/activate.rb:16:in `RGLoader_load'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-share-1.1.7/lib/vagrant-share/activate.rb:16:in `<top (required)>'
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-share-1.1.7/lib/vagrant-share.rb:23:in `block in <class:Plugin>'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:75:in `call'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:75:in `block (2 levels) in help'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/registry.rb:49:in `block in each'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/registry.rb:48:in `each'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/registry.rb:48:in `each'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:69:in `block in help'
        from C:/HashiCorp/Vagrant/embedded/lib/ruby/2.2.0/optparse.rb:917:in `initialize'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:57:in `new'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:57:in `help'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/cli.rb:32:in `execute'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/lib/vagrant/environment.rb:308:in `cli'
        from C:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.9.4/bin/vagrant:127:in `<main>'


Solution:

C:\Users\Marek
λ vagrant plugin install vagrant-share --plugin-version 1.1.8
Installing the 'vagrant-share --version '1.1.8'' plugin. This can take a few minutes...
Fetching: vagrant-share-1.1.8.gem (100%)

piątek, 28 kwietnia 2017

docker laboratory

http://labs.play-with-docker.com/

if you want to test your app / deployment you can use it - very handy and use full tool.

czwartek, 27 kwietnia 2017

sed handy examples

example file:

-> cat test.file
1 file
2 line
3 lin
4 l
5
#6 comment

1. delete first line from file

sed -e '1d' test.file
bunny-> sed -e '1d' test.file
2 line
3 lin
4 l
5
#6 comment


2. delete lines 1,2,3 from file
sed -e '1,3d' test.file
bunny-> sed -e '1,3d' test.file
4 l
5
#6 comment

3. delete lines started with '#'
sed -e '/^#/d' test.file
bunny-> sed -e '/^#/d' test.file
1 file
2 line
3 lin
4 l
5

4. change char to string
bunny-> sed -e 's/l$/another line/' test.file
1 file
2 line
3 lin
4 another line
5
#6 comment

5. insert double/single spaces between lines
ansible-> sed 'G;G' test.file - for double
ansible-> sed G test.file - for single
1 file


2 line


3 lin


4 l


5


#6 comment


7 l


8 l


6. 

środa, 26 kwietnia 2017

check if docker was killed by OOM error

docker inspect -f '{{.Config.Hostname}} {{.State.ExitCode}} {{.State.OOMKilled}}' $(docker ps -q)

output:
crm-prd-n1-3 0 false
crm-prd-n1-2 0 false
crm-prd-n1-1 0 false

Menu build in python with KeyboardInterrupt exception

import sys
import os
import requests

def print_menu():

    print 30 * "-", "MENU", 30 * "-"
    print "1. Call Date"
    print "2. Check logged users"
    print "3. GET Request"
    print "4. Exit"
    print 67 * "-"

loop = True
try:
      while loop:
            print_menu()
            choice = input("enter your choice [1-4]: ")
            if choice == 1:
                  x = os.system('date')
                  print x
            elif choice == 2:
                  print "logged uers"
                  os.system('who')
            elif choice == 3:
                  address = 'https://google.com'
                  print "GET Request of {}".format(address)
                  req = requests.get(address)
                  print(req.encoding)
                  print(req.status_code)
            else:
                  print "exit"
                  sys.exit()
except KeyboardInterrupt:

wtorek, 25 kwietnia 2017

how to run nginx on docker with index page on local resource

docker run -d -v /var/www/html:/usr/share/nginx/html/:ro -p 80:80 nginx

root@bunny:~# docker inspect 40c5179cabef | grep -i nginx
"Path": "nginx",
"/var/www/html:/usr/share/nginx/html/:ro"
"Destination": "/usr/share/nginx/html",

analyze short strings – python

zd = "There are 123 apples"
alphas = 0
digits = 0
spaces = 0
for i in zd:
if i.isalpha():
alphas += 1
if i.isdigit():
digits += 1
if i.isspace():
spaces += 1
print 30*"-="
#marked string after we change it by separate string in quote
print("original string is: \"{}\"".format(zd))
print("there are {} characters".format(len(zd)))
print("there are {} alphas characters".format(alphas))
print("there are {} digits ".format(digits))
print("there are {} spaces.".format(spaces))
output:

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
original string is: "There are 123 apples"
there are 20 characters
there are 14 alphas characters
there are 3 digits
there are 3 dpaces.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
string formatting
height: 189.50 cm
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
hex: 12c
0x12c
100101100
454
3.000000e+05
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Python regexp example

import re
exampleString = '''My Name is Marek Borkowski and i have 34 years old'''
ages = re.findall(r'\d{1,3}',exampleString)
print(ages)
names = re.findall(r'[A-Z][a-z]*',exampleString)
print(names)

ansible-> python regexp.py
['34']
['My', 'Name', 'Marek', 'Borkowski']

Platform-independent python script

import os
if (os.name == “posix”):
    print(os.system(‘ls -ltr’))
elif(os.name == “nt”):
    print(os.system(‘dir’))
else:
    print(“unknown os”)

poniedziałek, 10 kwietnia 2017

awk handy examples

Testing input:
Marek
Testing
Hello
TesT
123

1. All lines include string 
marek-> awk '/Test/ {print}' test.txt
Testing 1
123 Testing

2. All lines include numbers
marek-> awk '/[0-9]/ {print}' test.txt
Testing 1
123 Testing

3. All lines started with numbers

marek-> awk '/^[0-9]/ {print}' test.txt
123 Testing

4. All lines ended with numbers

marek-> awk '/[0-9]$/ {print}' test.txt
Testing 1


5. Print if in first column 123 will be found

marek-> awk '{ if($1 ~ /123/) print }' test.txt
123 Testing
123 Marek

6. Print if in second column awk found numbers

marek-> awk '{ if($2 ~/[0-9]/) print }' test.txt
Testing 1
Marek 1983


7. Grep Lines in file consist string

marek-> grep -i test test.txt
Testing 1
TesT
123 Testing

[~/dev/bash/awk]
marek-> grep -i test test.txt | awk '/[0-9]/{ print }'
Testing 1
123 Testing


8. Delete duplicate lines from file

[~/dev/bash/awk]
ansible-> cat file.txt
1
1
1
1
1
2
2
2
2
2
13
[~/dev/bash/awk]
ansible-> awk '!x[$0]++' file.txt
1
2
13
[~/dev/bash/awk]


9. print lines number - like wc

marek-> awk '{print NR-1 " " $0}' /etc/passwd
0 root:x:0:0:root:/root:/bin/bash
1 daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
2 bin:x:2:2:bin:/bin:/usr/sbin/nologin


10. sed vs. awk string replacement

marek-> sed 's/Marek/Wiktor/g' test.txt
Wiktor
Testing 1
Hello:World
TesT
123 Testing
123 Wiktor
Wiktor:1983
OMG:Test

marek-> cat test.txt | awk '{gsub("Wiktor","Marek"); system("echo " $0) }'
Marek
Testing 1
Hello:World
TesT
123 Testing
123 Marek
Marek:1983
OMG:Test



niedziela, 9 kwietnia 2017

python format vs python classic way output

def f(x,y):
       print("you called f({},{})".format(x,y))
       print("you called f(x,y), with a value x = "+str(x) + "and y = " + str(y))
       print("x * y = " + str(x*y))

f(4,2)

środa, 5 kwietnia 2017

check docker OOM state via python + paramiko

import sys
import time
import select
import paramiko
import time

hosty = ['app01.prod.crm.polsatc','app02.prod.crm.polsatc','app03.prod.crm.polsatc','app04.prod.crm.polsatc','app05.prod.crm.polsatc','app06.prod.crm.polsatc','app07.prod.crm.polsatc']
for h in hosty:

        i = 0
        imax = 5
        while True:
                print "Trying to connect to %s (%i/%i)" % (h, i, imax)

                try:
                        ssh = paramiko.SSHClient()
                        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
                        ssh.connect(h, port=3300)
                        print "Connected to %s" % h
                        break
                except paramiko.AuthenticationException:
                        print "Authentication failed when connecting to %s" % h
                        sys.exit(1)
                except:
                        print "Could not SSH to %s, waiting for it to start" % h
                        i += 1
                        time.sleep(2)

                        # If we could not connect within time limit
                if i == 5:
                        print "Could not connect to %s. Giving up" % h
                        sys.exit(1)


        stdin, stdout, stderr = ssh.exec_command("docker inspect -f '{{.Config.Hostname}} {{.State.ExitCode}} {{.State.OOMKilled}}' $(docker ps -q)")
        while not stdout.channel.exit_status_ready():
                if stdout.channel.recv_ready():
                        rl, wl, xl = select.select([stdout.channel], [], [], 0.0)
                        if len(rl) > 0:
                                print stdout.channel.recv(1024),
        print "Command done, closing SSH connection"
        ssh.close()



ansible-> python testParamiko.py
Trying to connect to app01.prod.crm.polsatc (0/5)
Connected to app01.prod.crm.polsatc
crm-prd-n1-3 0 false
crm-prd-n1-2 0 false
crm-prd-n1-1 0 false
Command done, closing SSH connection
Trying to connect to app02.prod.crm.polsatc (0/5)
Connected to app02.prod.crm.polsatc
crm-prd-n2-3 0 false
crm-prd-n2-2 0 false
crm-prd-n2-1 0 false
Command done, closing SSH connection
Trying to connect to app03.prod.crm.polsatc (0/5)
Connected to app03.prod.crm.polsatc
crm-prd-n3-3 0 false
crm-prd-n3-2 0 false
crm-prd-n3-1 0 false
Command done, closing SSH connection
Trying to connect to app04.prod.crm.polsatc (0/5)
Connected to app04.prod.crm.polsatc
crm-prd-n4-3 0 false
crm-prd-n4-2 0 false
crm-prd-n4-1 0 false
Command done, closing SSH connection
Trying to connect to app05.prod.crm.polsatc (0/5)
Connected to app05.prod.crm.polsatc
crm-prd-n5-3 0 false
crm-prd-n5-2 0 false
crm-prd-n5-1 0 false
Command done, closing SSH connection
Trying to connect to app06.prod.crm.polsatc (0/5)
Connected to app06.prod.crm.polsatc
crm-prd-n6-3 0 false
crm-prd-n6-2 0 false
crm-prd-n6-1 0 false
konfigurator-prd-n1 0 false
Command done, closing SSH connection
Trying to connect to app07.prod.crm.polsatc (0/5)
Connected to app07.prod.crm.polsatc
crm-prd-n7-3 0 false
crm-prd-n7-2 0 false
crm-prd-n7-1 0 false
Command done, closing SSH connection

poniedziałek, 3 kwietnia 2017

how to print function name in python

def say_my_name(func):
    def wrapped(*args, **kwargs):
        print(func.__name__)
        return func(*args, **kwargs)
    return wrapped

@say_my_name

def heisenberg():
    print("you are right")


heisenberg()
def Wiktor():
    print("Wiktor Borkowski")


Wiktor()

python timer with keyboard interruption

import time

timer = time.time()
try:
    while True:
        if time.time()-timer > 2:
            print("2 sec")
            timer = time.time()
except KeyboardInterrupt:
    print "you hit ctr+c"
except:

    print "error"

piątek, 31 marca 2017

python tricks - “_” operator.

t’s a useful feature which not many of us are aware.
In the Python console, whenever we test an expression or call a function, the result dispatches to a temporary name, _ (an underscore).


>>> 2 + 1
3
>>> print _
3
>>>

The “_” references to the output of the last executed expression.

czwartek, 23 marca 2017

check state of all docker instances

for((j=1;j<7;j++)); do for i in 9990 10090 10190; do echo -n "app0$j on port $i" && curl  --digest http://admin:pass@app0$j.prod.crm.polsatc:$i/management --header "Content-Type: application/json" -d '{"operation":"read-attribute","name":"server-state","json.pretty":1}'; done; done


desc:
make loop 7 times
make loop on 3 port numbers

paste two variables to http address and get data via docker api


10 largest file

find . -mount -type f -ls 2> /dev/null | sort -rnk7 | head -10 | awk '{printf "%10d MB\t%s\n",($7/1024)/1024,$NF}'

        20 MB   ./kontvmq19_1.1.log
         6 MB   ./kontvmq19_1.0.log
         0 MB   ./flopsar-agent-2.0.jar
         0 MB   ./kontwaw5.0.log
         0 MB   ./kontvmq19_1.0.log.lck

create menu bash

#!/bin/bash
show_menu()
{

        echo "what we can do: "
        echo "1) find oom"
        echo "2) delete oom"
        echo "3) check wf"
        echo "4) exit"
        echo "-=-=-=-=-=-=-=-=-=-"
        echo -n
        echo -n
}

read_options(){
        local choice
        read -p "enter choice [1 - 4] " choice
        case $choice in
                1)  for i in {1..7}; do ssh ansible@app0$i.prod.crm.polsatc 'bash -s' < oom.sh ;done ;;
                2)  for i in {1..7}; do ssh ansible@app0$i.prod.crm.polsatc 'bash -s' < eraseHprof.sh ;done ;;
                3)  for i in {1..7}; do ssh ansible@app0$i.prod.crm.polsatc 'bash -s' < wf.sh ;done ;;
                4)  exit 0;;
                *) echo -e "${RED}ERROR...${STD}" && sleep 2
        esac
}

while true
do
        show_menu
        read_options
done

wtorek, 21 marca 2017

detailed web response time

marek@bunny:~$ curl -s -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' -o /dev/null http://www.blogosit.blogspot.com

Lookup time:    0.125
Connect time:   0.137
PreXfer time:   0.137
StartXfer time: 0.269

Total time:     0.269

security - auth.log parse

how to check auth.log easly

marek@bunny:~$ uptime
 20:44:25 up  6:08,  2 users,  load average: 0.00, 0.00, 0.00


marek@bunny:~$ for i in `sudo grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" /var/log/auth.log  | sort | uniq | grep -v 0.0.0.0`; do geoiplookup $i; done

GeoIP Country Edition: VN, Vietnam
GeoIP Country Edition: US, United States
GeoIP Country Edition: DZ, Algeria
GeoIP Country Edition: MU, Mauritius
GeoIP Country Edition: DZ, Algeria
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: KR, Korea, Republic of
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: BR, Brazil
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: IR, Iran, Islamic Republic of
GeoIP Country Edition: EG, Egypt
GeoIP Country Edition: IT, Italy
GeoIP Country Edition: IP Address not found
GeoIP Country Edition: US, United States
GeoIP Country Edition: TR, Turkey
GeoIP Country Edition: ES, Spain
GeoIP Country Edition: RU, Russian Federation
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: CN, China
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: IR, Iran, Islamic Republic of
GeoIP Country Edition: RO, Romania
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: PE, Peru
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: UA, Ukraine
GeoIP Country Edition: GB, United Kingdom
GeoIP Country Edition: RU, Russian Federation
GeoIP Country Edition: RU, Russian Federation
GeoIP Country Edition: MA, Morocco
GeoIP Country Edition: CL, Chile
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: AR, Argentina
GeoIP Country Edition: IT, Italy
GeoIP Country Edition: PL, Poland
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: RU, Russian Federation
GeoIP Country Edition: PL, Poland
GeoIP Country Edition: US, United States
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: CN, China
GeoIP Country Edition: RU, Russian Federation
GeoIP Country Edition: CN, China
GeoIP Country Edition: IT, Italy
GeoIP Country Edition: RU, Russian Federation
GeoIP Country Edition: RU, Russian Federation
GeoIP Country Edition: RU, Russian Federation
GeoIP Country Edition: CZ, Czech Republic
GeoIP Country Edition: RU, Russian Federation


how to count this sinners?


marek@bunny:~$ cat ip_tst.txt | sort | uniq | xargs -n 1 geoiplookup { } | sort | uniq -c | sort
     12 GeoIP Country Edition: AR, Argentina
      1 GeoIP Country Edition: BR, Brazil
      1 GeoIP Country Edition: CL, Chile
      1 GeoIP Country Edition: CZ, Czech Republic
      1 GeoIP Country Edition: EG, Egypt
      1 GeoIP Country Edition: ES, Spain
      1 GeoIP Country Edition: GB, United Kingdom
      1 GeoIP Country Edition: IP Address not found
      1 GeoIP Country Edition: KR, Korea, Republic of
      1 GeoIP Country Edition: MA, Morocco
      1 GeoIP Country Edition: MU, Mauritius
      1 GeoIP Country Edition: PE, Peru
      1 GeoIP Country Edition: RO, Romania
      1 GeoIP Country Edition: TR, Turkey
      1 GeoIP Country Edition: UA, Ukraine
      1 GeoIP Country Edition: VN, Vietnam
     27 GeoIP Country Edition: CN, China
      2 GeoIP Country Edition: DZ, Algeria
      2 GeoIP Country Edition: IR, Iran, Islamic Republic of
      2 GeoIP Country Edition: PL, Poland
      3 GeoIP Country Edition: IT, Italy
      3 GeoIP Country Edition: US, United States
      9 GeoIP Country Edition: RU, Russian Federation


sobota, 11 marca 2017

delete first line from command output

ubuntu@ip-172-31-44-77:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jboss/wildfly       latest              27e70d979161        12 weeks ago        582.8 MB

ubuntu@ip-172-31-44-77:~$ sudo docker images | awk '{if(NR>1)print}'
jboss/wildfly       latest              27e70d979161        12 weeks ago        582.8 MB

czwartek, 9 marca 2017

swap consuming process - bash script

SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"`
do
    PID=`echo $DIR | cut -d / -f 3`
    PROGNAME=`ps -p $PID -o comm --no-headers`
    for SWAP in `grep VmSwap $DIR/status 2>/dev/null | awk '{ print $2 }'`
    do
        let SUM=$SUM+$SWAP
    done
    if (( $SUM > 0 )); then
        echo "PID=$PID swapped $SUM KB ($PROGNAME)"
    fi
    let OVERALL=$OVERALL+$SUM
    SUM=0
done
echo "Overall swap used: $OVERALL KB"

środa, 8 marca 2017

winrm python

import winrm

s = winrm.Session('kontvmq08', auth=('test', 'Redhat2017'))
r = s.run_cmd('net stop K_KIL_BIL')
print(r.status_code)
print(r.std_out)

necessary configuration:

winrm quickonfig
Test-WSMan -ComputerName <name>

winrm set winrm/config/service @{AllowUnencrypted="true"}
winrm set winrm/config/service/auth @{Basic="true"}
winrm set winrm/config/client/auth @{Basic="true"}


necessary module:

pip install "pywinrm>=0.2.2"

poniedziałek, 6 marca 2017

Something new in Docker / redhat


docker@gitvmd2:~$ docker --version
Docker version 1.13.1, build 092cba3
docker@gitvmd2:~$ docker system

Usage:  docker system COMMAND

Manage Docker

Options:
      --help   Print usage

Commands:
  df          Show docker disk usage
  events      Get real time events from the server
  info        Display system-wide information
  prune       Remove unused data

Run 'docker system COMMAND --help' for more information on a command.

poniedziałek, 13 lutego 2017

login to docker container as root

gitvmd1(/root)# docker exec -it --user root 72fde109eefb bash

[root@72fde109eefb jboss]# id
uid=0(root) gid=0(root) groups=0(root)

curl docker monitoring

[ansible@wildvmq5.polsatc ~]$ curl --digest http://admin:password@192.168.82.126:9990/management -d '{"operation":"read-resource", "include-runtime":"true", "address":[{"core-service":"platform-mbean"},{"type":"memory"}], "json.pretty":1}' -H Content-Type:application/json

{
    "outcome" : "success",
    "result" : {
        "heap-memory-usage" : {
            "init" : 1098907648,
            "used" : 2722441184,
            "committed" : 4260102144,
            "max" : 4260102144
        },
        "non-heap-memory-usage" : {
            "init" : 2555904,
            "used" : 1181620648,
            "committed" : 1251344384,
            "max" : -1
        },
        "object-name" : "java.lang:type=Memory",
        "object-pending-finalization-count" : 0,
        "verbose" : true
    }
}

[ansible@wildvmq5.polsatc ~]$ curl  --digest http://admin:password@192.168.82.126:9990/management --header "Content-Type: application/json" -d '{"operation":"read-attribute","name":"server-state","json.pretty":1}'
{
    "outcome" : "success",
    "result" : "running"
}

docker heap simple monitoring.

#!/bin/bash
for c in `docker ps -q`
do
        heapused=$(docker exec -i $c /opt/wildfly9/bin/jboss-cli.sh -c "/core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)" | grep "used" | awk '{print $3}' | sed 's/L,//')

        heapmax=$(docker exec -i  $c /opt/wildfly9/bin/jboss-cli.sh -c "/core-service=platform-mbean/type=memory:read-attribute(name=heap-memory-usage)" | grep "max" | awk '{print $3}' | sed 's/L//')
        freememory=$((heapmax - heapused))



        if [ $freememory -le 128000000 ]

        then
                echo "JVM Heap memory getting low: Remaining: $freememory bytes"
        else
                echo " $c - ok"
        fi
done

środa, 25 stycznia 2017

check docker jboss state

root@ubuntu:~# docker exec -it 885fa650d05e /opt/jboss/wildfly/bin/jboss-cli.sh --connect ":read-attribute(name=server-state)"
{
    "outcome" => "success",
    "result" => "running"
}