2015年2月14日 星期六

2015年2月8日 星期日

Collcted Plugin Development and Compiling (AREAWELL AW-2111A Plugin)

下載 collectd 原始碼
$ wget https://github.com/collectd/collectd/archive/collectd-5.4.1.tar.gz
$ tar zxf collectd-5.4.1.tar.gz

下載 Collectd AREAWELL AW-2111A plugin
$ git clone https://github.com/a0726h77/cloudPower-collectd-plugin.git

將 AW-2111A plugin 複製到 Collectd 原始碼資料夾
$ cp -r cloudPower-collectd-plugin/* collectd-collectd-5.4.1/src/

修改編譯設定,加入 plugin
$ cd collectd-collectd-5.4.1/
$ vi configure.ac
....
AC_PLUGIN([cloudpower], [yes], [cloudpower statistics])
....
$ vi src/Makefile.am
....
if BUILD_PLUGIN_CLOUDPOWER
pkglib_LTLIBRARIES += cloudpower.la
cloudpower_la_SOURCES = cloudpower.c
cloudpower_la_LDFLAGS = -module -avoid-version
cloudpower_la_LIBADD = -L. -lcloudPowerManagerTool
collectd_LDADD += "-dlopen" cloudpower.la
collectd_DEPENDENCIES += cloudpower.la
endif
....
$ vi src/types.db
....
electric        value:GAUGE:U:U
....

* Makefile.am 裏需指定模組對 libcloudPowerManagerTool.a 使用靜態連結

安裝相依套件
# apt-get install build-essential automake bison flex autoconf pkg-config libtool libgcrypt20-dev libltdl-dev libglib2.0-dev lib32z1-dev gcc-4.9-multilib

編譯 & 安裝
$ ./build.sh
$ ./configure CFLAGS="-m32" --prefix=/opt/collectd
CFLAGS="-m32"  編譯 collectd 成 32 位元執行檔,因爲官方給的
libcloudPowerManagerTool.a 只有 32 位元版本
--prefix  指定安裝路徑
$ make
# make all install

載入模組
# vi /opt/etc/collectd.conf
....
LoadPlugin cloudpower
....
<Plugin cloudpower>
        <Node "1F">
                Host "192.168.x.x"
        </Node>
</Plugin>
....

執行
# /opt/collectd-5.4.1/sbin/collectd -C /opt/collectd-5.4.1/etc/collectd.conf -f




References :
First steps - collectd Wiki
Plugin architecture - collectd Wiki
AREAWELL NETWORKS

Compile Collectd plugin with static link library

* 可參考 iptables plugin 的設定


$ cp libfact.a src/
$ vi src/Makefile.am
if BUILD_PLUGIN_MYPLUGIN
....
myplugin_la_LIBADD = -L. -lfact
....
endif
$ make




References :
Plugin:IPTables - collectd Wiki

Compile 32 bit Collectd on 64 bit system


$ ./build.sh
$ ./configure CFLAGS="-m32"
$ make

plugin_dispatch_values: Dataset not found check your types.db!

add your custome plugin type define to TypesDB

# vi /usr/share/collectd/types.db




References :
Question on apple_sensors plugin - Monitoring Collectd
[collectd] Thought about exec and types.db
types.db(5) – collectd – The system statistics collection daemon

2015年2月7日 星期六

WARNING: Neither `libtoolize' nor `glibtoolize' have been found! "apt-get"

# apt-get install libtool

Compile Collectd from source

$ git clone https://github.com/collectd/collectd.git
$ cd collectd
$ ./build.sh
$ ./configure
$ make
# make all install 


Error :
$ ./build.sh
WARNING: `lex' not found!
Please make sure that `lex' is installed and is in one of the
directories listed in the PATH environment variable.
WARNING: `yacc' not found!
Please make sure that `yacc' is installed and is in one of the
directories listed in the PATH environment variable.
Solution :
# apt-get install byacc flex
# apt-get install bison


Error :
$ ./build.sh
configure.ac:1909: warning: macro 'AM_PATH_LIBGCRYPT' not found in library
Solution :
# apt-get install libgcrypt20-dev





References :

Development Information – collectd – The system statistics collection daemon
First steps - collectd Wiki

how to install Lex and Yacc in Ubuntu? - Stack Overflow 
[collectd] Compile git clone
使用collectd与visage收集kvm虚拟机性能实时图形 - - 博客频道 - CSDN.NET

Golang compile 32 bit binary on 64 bit system

$ GOARCH=386 go build


* not support for cgo



References :
windows - Compile 32 bit binary on 64 bit system - Stack Overflow

Golang use C library

  • cgo can compile C code
  • cgo can not compile C++ code (see Swig for that)
  • cgo supports both dynamic and static linking of compiled C code
  • by default, cgo will dynamically link (more on this later)
  • cgo does not support relative lookups of C files
  • #cgo pkg-config
Example :
$ vi test.go

package main

import "fmt"

// #cgo CFLAGS: -I.
// #cgo LDFLAGS: -L. -lgb 
// #include 
import "C"

func main() {
    fmt.Printf("Invoking c library...\n")
    fmt.Println("Done ", C.x(10) )
}
$ go build test.go 




References :
How do you statically link a c library in go using cgo? - Stack Overflow
A little trick to statically link C to Golang with cgo
Going Go Programming: Using C Dynamic Libraries In Go Programs

Linux turn off LCD monitor

Turn off
$ DISPLAY=:0 xset dpms force off

Turn on
$ DISPLAY=:0 xset dpms force on




References :
Simple command to turn off the monitor ~ Linux and Life

Converting Markdown to reStructuredText

安裝 pandoc 
# apt-get install pandoc
 
轉換
$ pandoc --from=markdown --to=rst --output=README.rst README.md




References :
Converting Markdown to reStructuredText | Bradley Froehle

2015年2月6日 星期五

X Windows 旋轉

旋轉 180 度
$ xrandr -o inverted
or
$ xrandr --output LVDS1 --rotate inverted



恢復正常
$ xrandr -o normal
or
$ xrandr --output LVDS1 --rotate normal

Sphinx 使用

安裝
# pip install sphinx

or

# apt-get install python-sphinx

安裝樣板
# pip install sphinx_rtd_theme

設定引導
$ sphinx-quickstart

執行完 sphinx-quickstart 會產生 Makefile 與 conf.py 檔

產生靜態 html 文件
$ make html




References :
Documenting Your Project Using Sphinx — an_example_pypi_project v0.0.5 documentation

gcc 編譯使用靜態函式庫 (.a)

產生動態函式庫
$ gcc -c fact.c -o fact.o

產生靜態函式庫
$ ar rcs libfact.a fact.o


使用靜態函式庫
$ tree
.
├── fact.h
├── libfact.a
├── main.c 
$ gcc -static main.c -L. -lfact -o main




References :
segfault.in » How to create static libraries with gcc?

在 64 位元系統上編譯 32 位元程式

安裝 32 位元函式庫
# apt-get install ia32-libs-dev
# apt-get install lib32z1-dev
gcc 模擬 32 位元


$ gcc -m32 -o output32 hello.c




References :
linux - /usr/bin/ld: skipping incompatible foo.so when searching for foo - Stack Overflow
HowTo Compile a 32-bit Application Using gcc On the 64-bit Linux Version - nixCraft

2015年2月5日 星期四

AREAWELL Cloud Wi-Fi Outlet AW-2111A

Library 與 Android & iOS APP下載
AREAWELL NETWORKS

按下遠端/本地切換鈕
R/L 燈亮時爲遠端模式,燈暗時爲本地模式 (可自行開發軟體)

1052/tcp  filtered ddt
1107/tcp  filtered isoipsigport-2
1455/tcp  filtered esl-lm
1721/tcp  filtered caicci
2021/tcp  filtered servexec
2222/tcp  filtered EtherNet/IP-1
5087/tcp  filtered unknown
6001/tcp  filtered X11:1
7800/tcp  filtered asr
8652/tcp  filtered unknown
20005/tcp filtered btx
32777/tcp filtered sometimes-rpc17
54328/tcp filtered unknown

2015年2月4日 星期三

[error]: Permission denied - /var/log/httpd/access_log

# vi /etc/init.d/td-agent
DAEMON_ARGS=${DAEMON_ARGS---user td-agent}
TD_AGENT_ARGS="${TD_AGENT_ARGS-/usr/sbin/td-agent --group td-agent --log /var/log/td-agent/td-agent.log}"

改成

DAEMON_ARGS=${DAEMON_ARGS---user root}
TD_AGENT_ARGS="${TD_AGENT_ARGS-/usr/sbin/td-agent --user root --group td-agent --log /var/log/td-agent/td-agent.log}"




References :
職場でよく耳にするfluentdを試してみました - Qiita

td-agent debug log

# cat /var/log/td-agent/td-agent.log
 
 
 
 
References :
職場でよく耳にするfluentdを試してみました - Qiita

Disable IPv6

CentOS
# echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6




References :
curl force IPv4 – disable IPv6 in curl and PHP - UK Business Directory

Can't find libcurl or curl/curl.h

Debian / Ubuntu :
# apt-get install libcurl4-gnutls-dev

CentOS :
# yum install libcurl-devel.i686