跳到主要內容

發表文章

目前顯示的是 6月, 2015的文章

Google Cloud Monitor integrate with Custom Metrics

最近在玩Google Cloud Monitor API的Custom Metric,簡單的說就是可以客制輸入到Monitor系統的數據,讓我們可以客製化監控的功能... 為了讓這一些更簡單,我寫了個簡單的工具來當作指令以輔助Custom Metric輸入資料,有了Custom Metric的資料,未來整合Cloud Monitor的圖表跟告警功能就更無往不利了! Installation 在安裝的部分,需要先有node.js環境,然後就可以安裝gcmetrics指令: npm install gcmetrics -g Auth 認證部分,需要先有Google project,並且申請service account,再透過下面指令來進行認證: gcmetric -t auth -s 288173501788-9fh14iojjmehakjtgkhoubdiaguppn1h@developer.gserviceaccount.com \ -k $HOME/.gcpkeys/mitac-cp300-taipei101/mitac-cp300-taipei101-8c0662095ef9.pem \ -p mitac-cp300-taipei101 Create a metric 接下來可以建立一個lightweight metric,來準備收資料... gcmetric -t init -n mymetric -i firstid -d "test first id" Insert data to metric 傳資料的部分,可以透過:  gcmetric -t simple -n mymetric -d [value] 來指定數值傳入Cloud Monitor,既然有了command,那寫個簡單的bash script就可以一直持續的塞資料唷! while [ true ] ; do gcmetric -t simple -n mymetric -d `free | grep Mem | awk '{print $3}'`; sleep 3 ; done 最後透過Cloud Monitor的自訂Dashboard功能,可以輕易的定義自己的圖表唷~ 之後,圖表、告警就都可以在上面直接設定了ㄛ! 專案已經發佈在: h

Google Cloud Monitor Customer Metrics

Google Cloud Monitor在結合 StackDriver 之後,提供了一個強大且彈性的Cloud Monitor API,並且允許客制監控,Google稱為 Customer Metrics ... 透過Cloud Monitor API可以以RESTful方式輸入Customer Metrics,然後在StackDriver內取用來作為圖表以及監控的資料來源... 在Customer Metrics在實作上分成Lightweight custom metric與Labeled custom metric兩種,分別在資料內容上有些許的差別: Lightweight custom metric以數值+時間為主,資料內容大致如下: $3,918.33 on March 20. $4,107.68 on March 21. $3,798.00 on March 22. 而Labeled custom metric以數值+時間+描述為主,資料內容大致如下: $23,213.97 at the "Columbus" store on January 10. $26,087.44 at the "Magellan" store on January 10. $19,650.00 at the "Columbus" store on January 11. 因此只要能夠抽取需要監控的數值與當下的時間,就可以開始監控 :D 下面是針對Customer Metrics的Lightweight customer metric來做資料輸入的片段Node.js程式: var request = require('request'); var auth = require('google-api-utility')   , request = auth.request   , util = require('util')   , project = 'your-project-id'; auth.init({   scope: ' https://www.googleapis.com/auth/monitoring ',   client_

Fluentd exec output測試

由於Google Cloud Logging是透過fluentd實作,加上fluentd介接BigQuery也非常簡單... 有這個機會跟fluentd多親近一下... :D 在玩了fluentd一陣子後,雖然他提供了不少的input, output, filter plugin,但是總是有一些無法滿足的地方 加上fluentd是ruby friendly的系統...@@,沒學過ruby總是難以在上面發揮...@@ 看了一陣子,終於下手測試output exec plugin...  期待可以藉由他來用第三方程式語言去介接其他output plugin所未提供的服務... 下面是一段將syslog source輸入,然後output到node.js程式的範例config <source>   type syslog   protocol_type udp   port 514   bind 0.0.0.0   tag system </source> <source>   type syslog   protocol_type tcp   port 514   bind 0.0.0.0   tag system </source> <match **>   type copy   <store>     type stdout     output_type json   </store>   <store>     type exec     command /opt/node/bin/node /home/simonsu/data/test.js     format json     time_format %Y-%m-%d %H:%M:%S     flush_interval 5s     buffer_path    /tmp   </store> </match> 然後其中"/home/simonsu/data/test.js"則是我們預計要執行的node.js程式 在exec中,以node.js會在指令列接收到類似:/tmp.20150611.q5183cc42694434d7.log的字串 該字串是buffer

從藏在GKE後面的秘密網站偷看Docker...

Google Container Engine(GKE)在推出後,讓許多Docker運作的麻煩輕鬆了不少... 最近發現了在Master Node隱藏的Kubernetes管理平台... 在GKE平台建立後,使用者可以透過Master Node的Public IP ( https://master-node-ip-address/static/app/#/dashboard/ ) 連線到這個管理平台,雖然平台的功能還很陽春,但是卻已經偷偷告知未來在K8S上的一些操作將會更加簡單... Cluster群的狀態: 透過表單可以知道大致上Pods, Replication Controller, Services... 都可以透過介面來查看他的狀態... 透過上面的圖片,不難想像在一個密你的Datacenter中建置自己服務的情境... 而除了這些,這次的Web Console升版,也開始讓使用者看到GCP project based repository有增加一些用心,雖然只是簡單的幾個畫面,但相信不久就會出現許多docker hub相關的功能(吧... 期待!) 如果對GKE還不慎了解,可以從Kubernetes (K8S)開始,其中K8S平台所提供的幾個重點元件包含: - Pods: Container執行的一個群集,可以運作於一台或是Cluster起來的數台主機上,允許內部定義Volumes來共用某個空間... 而Pods中運作的Container也會受到K8S node agent的監控,任何掛掉的狀況,會被自動重啟回復。 - Replication Controller: 可以操控同一個Pod設定中的Container擴增,並可以在Container fail時候重新啟動Container。 - Services: Service為K8S中一個群集的抽象層,透過label selector為一個動態Pods提供一個抽象的結合,而Service則負責提供該集合對外的IP與DNS名稱等存取端口。 註:上面解釋局部翻譯於: https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/overview.md 透過這些設定,在K8S上,目前可以看到幾個優點: - Nodes可以整合,對於使用者