著者アーカイブ


レプリケーションの設定をしているDBがいつの間にかバイナリログによってディスク容量の空きが無くなっていた・・・
想像以上に早くディスク容量を消費する・・・
以下、バイナリログの削除方法と自動削除の設定方法。

http://wiki.bit-hive.com/tomizoo/pg/MySQL%20%A5%D0%A5%A4%A5%CA%A5%EA%A5%ED%A5%B0%A4%CE%BA%EF%BD%FC

Comments [mysql] MySQLのバイナリログ削除 はコメントを受け付けていません



appengineのアプリケーションログをチェックして、ERRORレベルのログがあった場合、管理者にメールで通知するプログラムを作ってみました。
Servletで作ってcronで実行します。


public class LogWatchServlet extends HttpServlet {
    
    private final static Log log = LogFactory.getLog(LogWatchServlet.class);
    
    private final static long duration = 20 * 60 * 1000; // 20min
    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        TimeZone.setDefault(TimeZone.getTimeZone("GMT+9:00"));
        
        LogQuery query = LogQuery.Builder
            .withDefaults()
            .minLogLevel(LogLevel.ERROR)
            .majorVersionIds(Arrays.asList(new String[]{SystemProperty.applicationVersion.get().split("\\.")[0]}))
            .includeAppLogs(true)
            .startTimeMillis(System.currentTimeMillis() - duration);
        
        log.debug("log watch version: " + SystemProperty.applicationVersion.get());
        
        // ログ取得
        String lastOffset = null;
        List<RequestLogs> logs = new ArrayList<RequestLogs>();
        do {
            if (lastOffset != null) {
                query.offset(lastOffset);
            }
            int count = 0;
            for (RequestLogs record : LogServiceFactory.getLogService().fetch(query)) {
                logs.add(record);
                lastOffset = record.getOffset();
                count++;
            }
            if (count == 0) {
                break;
            }
        } while(true);
        
        // ログがあったらメール送信
        if (! logs.isEmpty()) {
            List<String> logbuffer = new ArrayList<String>();
            int i=0;
            for (RequestLogs record: logs) {
                logbuffer.add(format.format(new Date(record.getEndTimeUsec()/1000)) + " " + record.getResource());
                for (AppLogLine line: record.getAppLogLines()) {
                    if (line.getLogLevel().compareTo(LogLevel.ERROR) >= 0) {
                        logbuffer.add(" " + line.getLogMessage());
                    }
                }
                if (i > 50) {
                    break;
                }
                i++;
            }
            logbuffer.add("\n\n全" + logs.size() + "件");
            
            // メール送信
            MailService mailService = MailServiceFactory.getMailService();
            String sender = "admin@" + AppConst.appId() + ".appspotmail.com";
            String subject = "[" + AppConst.appId() + "] applicaton log notification";
            MailService.Message message = new MailService.Message(sender, null, subject, StringUtils.join(logbuffer, "\n"));
            mailService.sendToAdmins(message);
        }
        
        return;
    }
    
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        doGet(request, response);
    }

}


Comments [appengine] アプリケーションログをチェックしてメールで通知する はコメントを受け付けていません


これでいいのかしら。。


    public static Key allocateId(AsyncDatastoreService ds, String kind)
            throws NullPointerException {
        if (ds == null) {
            throw new NullPointerException("The ds parameter must not be null.");
        }
        if (kind == null) {
            throw new NullPointerException(
                "The kind parameter must not be null.");
        }
        String ns = NamespaceManager.get();
        if (ns == null) {
        	ns = "";
        }
        String cacheKey = "!"+ns+":"+kind;
        Iterator<Key> keys = keysCache.get(cacheKey);
        if (keys != null && keys.hasNext()) {
            return keys.next();
        }
        keys =
            FutureUtil
                .getQuietly(allocateIdsAsync(ds, kind, KEY_CACHE_SIZE))
                .iterator();
        keysCache.put(cacheKey, keys);
        return keys.next();
    }

Comments [appengine][slim3] DatastoreUtil#allocateIdがNamespaceに対応するように修正 はコメントを受け付けていません


listプロパティにInMemoryInCriterionを適用するとエラーになるので修正。
これでいいのかしら。。


   public boolean accept(Object model) {
        Object v = convertValueForDatastore(attributeMeta.getValue(model));
        for (Object o : value) {
        	if (v instanceof Collection<?>) {
        		for (Object v2: (Collection<?>)v) {
                    if (compareValue(v2, o) == 0) {
                        return true;
                    }
        		}
        	} else {
        		if (compareValue(v, o) == 0) {
        			return true;
        		}
        	}
        }
        return false;
    }

Comments [appengine][slim3]InMemoryInCriterionがlistプロパティでも動作するように修正 はコメントを受け付けていません


忘れがちなのでメモ。


cd appengine-java-sdk-xxx\bin
appcfg.cmd vacuum_indexes c:\path\to\eclipse\project\war

Comments [appengine]不要なインデックスを削除するコマンド はコメントを受け付けていません