Category: Life

  • ansible connect unix domain socket “too long”

    改配置文件

    [ssh_connection]
    control_path = %(directory)s/%%h-%%p-%%r

  • linux 负载高排查

    机器 load avg 高

    首先看一下什么是 load avg

    man proc
    The first three fields in this file are load average figures giving the number of jobs  in  the  run  queue
                  (state  R)  or waiting for disk I/O (state D) averaged over 1, 5, and 15 minutes.  They are the same as the
                  load average numbers given by uptime(1) and other programs.  The fourth field consists of two numbers sepa‐
                  rated  by  a  slash (/).  The first of these is the number of currently runnable kernel scheduling entities
                  (processes, threads).  The value after the slash is the number of kernel scheduling entities that currently
                  exist  on the system.  The fifth field is the PID of the process that was most recently created on the sys‐
                  tem.
    

    查看 load avg

    cat /proc/loadavg 
    3.33 4.76 5.55 2/505 8687

    查看队列

    sar -q 1

    查看 cpu time 来说,如果 system time 不高,我们认为系统层面没有问题,更多的关注 user , nice, 如果有 io 问题关注 iowait. 如果 system time 高,需要解决。

    strace 是输出 system call 的工具,-c 可以进行一段时间的统计,之后按 ctrl + c 停止

    strace -c -p 6615

    打印出来会按 cpu time 占比来看

    uptime
    dimes -T | tail
    vmstat 1
    mpstatl -P ALL 1
    pidstat 1
    instate -xz 1
    free -m
    sar -n DEV 1
    sar -n TCP,ETCP 1
    top

    http://techblog.netflix.com/2015/11/linux-performance-analysis-in-60s.html

    http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages

  • python日志换行输出

    只有一行时替换 #012 为换行

    tail -f error.log | sed 's/#012/\n/g'
    
  • python打印pid

    $ python
    >>> import os
    >>> os.getpid()
    12252
    

    参考:
    http://stackoverflow.com/questions/8281345/how-to-get-current-linux-process-id-pid-from-cmdline-in-shell-and-language-i

  • supervisord使用

    启动 supervisord

    systemctl start supervisord.service

    在 /etc/supervisord.d 创建 cat.ini
    内容如下

     
    [program:bar]
    command=/bin/cat
    stdout_logfile=syslog
    stderr_logfile=syslog
    

    运行

    supervisorctl update
    supervisorctl start all
    supervisorctl status
    bar                              RUNNING   pid 681, uptime 0:05:53
    

    命令选项

    add
    exit
    open
    reload
    restart 重启
    start 启动
    tail
    supervisorctl tail -f foo 日志
    avail
    fg
    pid 获取进程号
    remove
    shutdown 关闭 supervisord
    status 查看状态
    update 更新
    clear
    maintail
    quit
    reread
    signal
    stop
    version

  • git lock

    ➜  ansible-roles git:(master) ✗ git add todo.md 
    fatal: Unable to create '/Users/jpuyy/ansible-roles/.git/index.lock': File exists.
    
    If no other git process is currently running, this probably means a
    git process crashed in this repository earlier. Make sure no other git
    process is running and remove the file manually to continue.
    

    解决办法

    rm -f .git/index.lock