android : gradle 和 Plugin for Gradle 对应问题

  1.  android studio  gradle 的版本 如果跟 Plugin for Gradle  没对应上,经常出现编译问题
  2.  gradle 版本 [参考链接3]
    • 30963F53-6E23-4634-98A4-3DD6E0CF7963
    • A68D37B3-DA2C-45ED-9B10-4397839168A2
    • 00D87FFF-29C2-4179-9054-2BA822319315
    • 在编译的时候,将gradle的版本号打出来比较直观9C66A46D-8BB7-4305-A679-AE737E47406F

3.  Android Gradle Build Tools 版本号 [参考链接2]

buildscript {
  ...
  dependencies {
    classpath 'com.android.tools.build:gradle:2.3.0'
  }
}

12DA29B0-3919-40E3-AD13-51F211A55A45

 

参考:

  1. http://www.jianshu.com/p/f3c0adf8c897
  2. https://developer.android.com/studio/releases/gradle-plugin.html  [plugin 跟 gradle 配对图]
  3. https://services.gradle.org/distributions/  [gradle 版本]
  4. http://stormzhang.com/android/2016/07/02/gradle-for-android-beginners/

linux : 磁盘监控脚本

 

1.

#coding:utf-8
import os
import re
import smtplib
import datetime
import shelve
from email.mime.text import MIMEText

# 硬盘使用率报警阀值
hd_usage_rate_threshold = 80

# 要发给谁
mailto_list=["******@17guagua.com","******@17guagua.com"]

# 设置服务器,用户名、口令以及邮箱的后缀
mail_host="smtp.17guagua.com"
mail_user="******@17guagua.com"
mail_pass="******"
mail_postfix="17guagua.com"

# 日志偏移
log_offset = shelve.open('log_offset')

# 取当天日期
log_path_suffix=(datetime.date.today()).strftime('%Y-%m-%d')

# 当前日期key
cur_time = 'cur_time'

# 日志路径
app_info = {}
app_info['event'] = ['/opt/log/guagua_web_event_extends/event-ext-'+log_path_suffix+'.log',['失败','异常'],[]]

# 处理日志
def analysis_log(appName ,appInfo):
    cur_time_val = get_shelve_value(cur_time)
    if cur_time_val == -1:
        set_shelve_value(cur_time, log_path_suffix)
    elif log_path_suffix != cur_time_val:
        set_shelve_value(appName, 0)
        set_shelve_value(cur_time, log_path_suffix)

    f1 = file(appInfo[0], "r")
    offset = get_shelve_value(appName)
    if offset != -1:
        f1.seek(offset,1)
    else:
        set_shelve_value(appName, 0)
    count = 0
    exceptionStr = ""
    for s in f1.readlines():
        searchKey = appInfo[1]
        if len(searchKey) > 0:
            for i in searchKey:
                li = re.findall(i, s)
                if len(li) > 0:
                    count = count + li.count(i)
                    exceptionStr = exceptionStr + " " + s
        else:
            li = re.findall('Exception', s)
            if len(li) > 0:
                count = count + li.count('Exception')
                exceptionStr = exceptionStr + " " + s
    set_shelve_value(appName, f1.tell())
    print appName + " 异常数量为 " + str(count)
    return [count, "---------------------------------" + appName + " ----------------------------- \n " + exceptionStr]

#shelve 处理
def set_shelve_value(key, value):
    log_offset[key] = value

def get_shelve_value(key):
    if log_offset.has_key(key):
        return log_offset[key]
    else:
        return -1

def del_shelve_value(key):
    if log_offset.has_key(key):
        del log_offset[key]

# 发送邮件
def send_mail(to_list,sub,content):
  me = mail_user + "<"+ mail_user + "@" + mail_postfix + ">"
  msg = MIMEText(content, 'html', 'utf-8')
  msg['Subject'] = sub
  msg['From'] = me
  msg['To'] = ";".join(to_list)
  try:
    s = smtplib.SMTP()
    s.connect(mail_host)
    s.login(mail_user,mail_pass)
    s.sendmail(me, to_list, msg.as_string())
    s.close()
    return True
  except Exception, e:
    print str(e)
    return False

# 获得外网ip
def get_wan_ip():
    cmd_get_ip = "/sbin/ifconfig |grep 'inet addr'|awk -F\: '{print $2}'|awk '{print $1}' | grep -v '^127' | grep -v '192'"
        get_ip_info = os.popen(cmd_get_ip).readline().strip()
    return get_ip_info

# 检测硬盘使用
def check_hd_use():
        cmd_get_hd_use = '/bin/df'
        try:
            fp = os.popen(cmd_get_hd_use)
        except:
            ErrorInfo = r'get_hd_use_error'
            print ErrorInfo
            return ErrorInfo
        re_obj = re.compile(r'^/dev/.+\s+(?P<used>\d+)%\s+(?P<mount>.+)')
        hd_use = {}
        for line in fp:
            match = re_obj.search(line)
            if match is not None:
                hd_use[match.groupdict()['mount']] = match.groupdict()['used']
        fp.close()
        return  hd_use

# 硬盘使用报警
def hd_use_alarm():
    for v in check_hd_use().values():
    if int(v) > hd_usage_rate_threshold:
        if send_mail(mailto_list,
                 'System Disk Monitor',
             'nSystem Ip:%s\nSystem Disk Use:%s'
             % (get_wan_ip(),check_hd_use())):
             print  "sendmail success!!!!!"
    else:
         print "disk not mail"

if __name__ == '__main__':
  hd_use_alarm()
  exceptionCount = 0
  exceptionContents = "";
  for key in app_info:
    exceptionContent = analysis_log(key, app_info[key])
    exceptionCount += exceptionContent[0]
    exceptionContents += exceptionContent[1]
    exceptionContents = exceptionContents + "*********************************************** \n"

  print exceptionCount
  if exceptionCount > 0:
    if send_mail(mailto_list, get_wan_ip() + " 日志报警",exceptionContents):
        print "发送成功"
    else:
        print "发送失败"

 

参考:

  1. http://blog.csdn.net/daidaineteasy/article/details/48792425

linux : 内存监测

1.

I recommend combining the previous answers

watch -n 5 free -m

Note that Linux likes to use any extra memory to cache hard drive blocks. So you don’t want to look at just the free Mem. You want to look at the free column of the -/+ buffers/cache: row. This shows how much memory is available to applications. So I just ran free -m and got this:

             total       used       free     shared    buffers     cached
Mem:          3699       2896        802          0        247       1120
-/+ buffers/cache:       1528       2170
Swap:         1905         62       1843

I know that I’m using 1528 MB and have 2170 MB free.

Note: To stop this watch cycle you can just press Ctrl+C.

 

2.cat /proc/meminfo

$ cat /proc/meminfo
MemTotal: 23255916 kB
MemFree: 4042492 kB
MemAvailable: 19533036 kB
Buffers: 2116372 kB
Cached: 11157484 kB
SwapCached: 0 kB
Active: 10161308 kB
Inactive: 6311148 kB
Active(anon): 3203484 kB
Inactive(anon): 21316 kB
Active(file): 6957824 kB
Inactive(file): 6289832 kB
Unevictable: 4976 kB
Mlocked: 4976 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 40 kB
Writeback: 0 kB
AnonPages: 3203640 kB
Mapped: 199176 kB
Shmem: 22632 kB
Slab: 2423408 kB
SReclaimable: 2315020 kB
SUnreclaim: 108388 kB
KernelStack: 13120 kB
PageTables: 38708 kB

3. htop 的使用

http://saiwei.me/wp-admin/post.php?post=3718&action=edit

 

参考:

  1. http://askubuntu.com/questions/9642/how-can-i-monitor-the-memory-usage