以åã®èšäºã§ã¯ãç£èŠãåéãããã³
ã¹ãã¬ãŒãžã¡ããªãã¯ïŒããšãã°ã ãã¡ããšãã¡ããã芧ãã ãã ïŒã ä»æ¥ã¯åã³ãã®ãããã¯ã«æ»ããçãããéåžžã«èå³æ·±ãããŒã«ã§ãããªãŒãã³ã«ã€ããŠã話ããããšæããŸãã
ä»ã®ç£èŠã·ã¹ãã ãšæ¯èŒããŠãè€éããå¢ããŠãããšããç¹åŸŽãããã
åæã«-ã¯ããã«é«ãæè»æ§ãšãã©ãŒã«ããã¬ã©ã³ã¹ã ã€ã³ã¿ãŒãããã§ã¯ããªãŒãã³ããäžçã§æãæè»ãªç£èŠã·ã¹ãã ããšåŒã°ããåºçç©ãèŠãŠããŸããã ãªãŒãã³ã¯ãè€éã§è€éãªé«è² è·ã·ã¹ãã ã«é¢ãããªã¢ã«ã¿ã€ã æ å ±ã®åéã«é©ããŠããŸãã
å³å¯ã«èšãã°ããªãŒãã³ã®å³å¯ãªæå³ã§ã®ç£èŠã·ã¹ãã ã¯ããã§ã¯ãããŸããã ã€ãã³ãããã»ããµãšåŒã¶æ¹ãæ£ããã§ãããã
ãã¹ãããã³ã¢ããªã±ãŒã·ã§ã³ããã€ãã³ãã«é¢ããæ å ±ãåéããã€ãã³ããã¹ããªãŒã ã«çµåããŠãããã«åŠçãŸãã¯ä¿åããããã«ä»ã®ã¢ããªã±ãŒã·ã§ã³ã«æž¡ããŸãã ãªãŒãã³ã¯ãã€ãã³ãã®ã¹ããŒã¿ã¹ãç£èŠããŸããããã«ããããã§ãã¯ãäœæããéç¥ãéä¿¡ã§ããŸãã
Riemannã¯Eclipseã©ã€ã»ã³ã¹ã®äžã§ç¡æã§é åžãããŠããŸã ã ã³ãŒãã®å€§éšåã¯ã Aphyrãšããä»®åã§ç¥ãããKyle Kingsburyã«ãã£ãŠæžãããŸãã ïŒã¡ãªã¿ã«ã圌ã®ããã°ãèªãããšããå§ãããŸããèå³æ·±ãè³æããããããŸãïŒã
ãªã¢ã«ã¿ã€ã ã®ã€ãã³ãåŠç
æè¿èŠ³æž¬ãããŠããã¡ããªãã¯ã®ç£èŠãåéãä¿åãåæã®åé¡ã«å¯Ÿããé¢å¿ã®é«ãŸãã¯ãéåžžã«èª¬æãã€ãããããã®ã§ããã³ã³ãã¥ãŒã¿ãŒã·ã¹ãã ã¯ããè€éã«ãªããè² è·ãå¢å€§ããŠããŸãã è² è·ã®é«ãã·ã¹ãã ã®å Žåããªã¢ã«ã¿ã€ã ã§ã€ãã³ããç£èŠããæ©èœã¯ç¹ã«éèŠã§ãã å®éããªãŒãã³ã¯ãã®åé¡ã解決ããããã«äœæãããŸããã
ãªã¢ã«ã¿ã€ã ã«è¿ãäœå¶ã§ã€ãã³ããåŠçãããšããèãæ¹ã¯æ°ãããã®ã§ã¯ãããŸãããã€ãã³ããå®è£ ããæåã®è©Šã¿ã¯1980幎代åŸåã«è¡ãããŸããã äŸãšããŠã¯ãããããã¢ã¯ãã£ãããŒã¿ããŒã¹ã·ã¹ãã ïŒã¢ã¯ãã£ãããŒã¿ããŒã¹ã·ã¹ãã ïŒããããŸããããã¯ãããŒã¿ããŒã¹ã«å ¥ã£ãŠããããŒã¿ãç¹å®ã®æ¡ä»¶ã»ããã«å¯Ÿå¿ããå Žåãç¹å®ã®åœä»€ã»ãããå®è¡ããŸãã
1990幎代ã«ããã§ã«ãªã¢ã«ã¿ã€ã ã§çä¿¡ããŒã¿ãåŠçã§ããããŒã¿ã¹ããªãŒã 管çã·ã¹ãã ïŒ Data Stream Management Systems ïŒãããã³è€åã€ãã³ãåŠçã·ã¹ãã ïŒ Complex Event Processing ãç¥ããŠCEPïŒãç»å ŽããŸããã ãã®ãããªã·ã¹ãã ã¯ãå€éšããŒã¿ãšåã蟌ãŸããå éšããžãã¯ã«åºã¥ããŠã€ãã³ããæ€åºããããç¹å®ã®åææäœãå®è¡ããŸãïŒããšãã°ãäžå®æéã®ã€ãã³ãæ°ãã«ãŠã³ãããŸãïŒã
è€éãªã€ãã³ããåŠçããããã®ææ°ã®ããŒã«ã®äŸã¯ãç¹ã«Storm ïŒ ãã·ã¢èªã®ããã«é¢ããèšäºãåç §ïŒãšEsperã«åœ¹ç«ã¡ãŸãã ã¹ãã¬ãŒãžã䜿çšããªãããŒã¿åŠçã«çŠç¹ãåœãŠãŠããŸãã ãªãŒãã³ã¯åãã¯ã©ã¹ã®è£œåã§ãã åãStormãšã¯å¯Ÿç §çã«ãã¯ããã«åçŽã§è«ççã§ããã€ãã³ãåŠçã®ããžãã¯å šäœã¯ã1ã€ã®æ§æãã¡ã€ã«ã§ã®ã¿èšè¿°ã§ããŸãã
å€ãã®ã·ã¹ãã 管çè ãå®å家ã¯ãã®æ©èœã«é©ããããå¯èœæ§ããããŸããæ§æãã¡ã€ã«ã¯åºæ¬çã«Clojureèšèªã®ã³ãŒãã§ãããRiemannã«ãã£ãŠèšè¿°ãããŠããŸãã
Clojureã¯ãæ©èœçïŒããæ£ç¢ºã«ã¯Lispã«äŒŒãïŒããã°ã©ãã³ã°èšèªãæããŸãã ããããå¿é ããå¿ èŠã¯ãããŸããããã®ç¬åµæ§ã®ããã«ãClojureã¯äžèŠããã»ã©è€éã§ã¯ãããŸããã ãã®æ©èœããã詳现ã«æ€èšããŠãã ããã
Clojureã«ã€ããŠ
Clojureã¯ãLISPã«åºã¥ããé¢æ°åèšèªã§ãã Clojureã§èšè¿°ãããããã°ã©ã ã¯ãJVMãã©ãããã©ãŒã ã§å®è¡ãããŸãã ãã®èšèªã®æåã®ããŒãžã§ã³ã¯2007幎ã«ç»å ŽããŸããã ããæè¿ããããŸã§ã®ææ°ããŒãžã§ã³ããªãªãŒã¹ãããŸãã-1.8.0ã
Clojureã¯ãFacebookãSpotifyãSoundCloudãAmazonãªã©ã®äŒæ¥ã®ãããžã§ã¯ãã§äœ¿çšãããŠããŸãïŒå®å šãªãªã¹ãã«ã€ããŠã¯ã å ¬åŒWebãµã€ããåç §ããŠãã ããïŒã
JVMçšã®ä»ã®LISPå®è£ ïŒããšãã°ãABCLãŸãã¯KawaïŒãšã¯ç°ãªããClojureã¯Common LispãŸãã¯Schemeã®ããããšãå®å šã«äºææ§ããããŸãããããããã®èšèªããå€ããåããŸããã Clojureã«ã¯ãä»ã®ææ°ã®LISPæ¹èšã«ã¯ãªããããŒã¿ã®äžå€æ§ã競åã³ãŒãã®å®è¡ãªã©ãããã€ãã®æ¡åŒµæ©èœããããŸãã
Clojureã¯ããšããšJVMã§åäœããããã«èšèšãããŠããããããã®ãã©ãããã©ãŒã ã«ååšããå€ãã®ã©ã€ãã©ãªã§åäœããŸãã Javaãšã®çžäºäœçšã¯åæ¹åã«å®è£ ãããŠããŸãã Javaçšã«èšè¿°ãããã³ãŒããåŒã³åºãããšãã§ããŸãã ãŸããJavaããã³ä»ã®JVMããŒã¹ã®ããã°ã©ãã³ã°èšèªïŒScalaãªã©ïŒããã®åŒã³åºãã«äœ¿çšå¯èœãªã¯ã©ã¹ãå®è£ ããããšãã§ããŸãã Clojureãšãã®æ©èœã®è©³çŽ°ã«ã€ããŠã¯ã ãã®èšäºãšRiemannã®å ¬åŒWebãµã€ããåç §ããŠãã ãã ã ãŸããClojureã®å¥ã®çããéåžžã«æçãªçŽ¹ä»ã«æ £ããããšããå§ãããŸãã
ã€ã³ã¹ããŒã«ãšæåã®éå§
ãªãŒãã³ã䜿çšããã«ã¯ããŸãå¿ èŠãªãã®ããã¹ãŠã€ã³ã¹ããŒã«ããå¿ èŠããããŸã
äŸåé¢ä¿ïŒJavaããã³RubyïŒè¿œå ã®ã³ã³ããŒãã³ããããã€ãèšè¿°ãããŠããŸããããã«ã€ããŠã¯åŸã§èª¬æããŸãïŒïŒ
$ sudo apt-get -y install default-jre ruby-dev build-essential
次ã«ãææ°ããŒãžã§ã³ã®ãªãŒãã³ãããŠã³ããŒãããŠã€ã³ã¹ããŒã«ããŸãã
$ wget https://aphyr.com/riemann/riemann-0.2.10_all.deb $ dpkg -i riemann-0.2.10_all.deb
次ã«ãå®è¡ããŸãïŒ
$ sudo service riemann start
æ¬æ Œçãªäœæ¥ãè¡ãã«ã¯ãRubyã§èšè¿°ãããã³ã³ããŒãã³ããåéããã³ã¡ããªãã¯çšã«ã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã
$ gem install riemann-client riemann-tools
以äžã§ãã ãªãŒãã³ãšã®äœæ¥ãéå§ããæºåããã¹ãŠæŽããŸããã å®è·µçãªéšåã«ç§»ãåã«ãå°ããªçè«çäœè«ãè¡ããæãéèŠãªæŠå¿µã§ããã€ãã³ãããããŒãã€ã³ããã¯ã¹ã®æå³ãæ確ã«ããŸãã
ã€ãã³ããã¹ã¬ãããããã³ã€ã³ããã¯ã¹
ãªãŒãã³ã®åºæ¬æŠå¿µã¯ã€ãã³ãã§ãã ã€ãã³ããåŠçãã«ãŠã³ããåéããä»ã®ããã°ã©ã ã«ãšã¯ã¹ããŒãã§ããŸãã ã€ãã³ãã¯æ¬¡ã®ããã«ãªããŸãã
{:host riemann, :service riemann streams rate, :state ok, :description nil, :metric 0.0, :tags [riemann], :time 355740372471/250, :ttl 20}
æå®ãããã€ãã³ãã¯ã次ã®ãã£ãŒã«ãã§æ§æãããŸãã
- ïŒhost-ãã¹ãå;
- ïŒservice-ç£èŠå¯Ÿè±¡ãµãŒãã¹ã®ååã
- ïŒstate-ã€ãã³ãã®ç¶æ ïŒokãèŠåãã¯ãªãã£ã«ã«ïŒ;
- ïŒã¿ã°-ã€ãã³ãã©ãã«ã
- ïŒtime-Unixã¿ã€ã ã¹ã¿ã³ã圢åŒã®ã€ãã³ãã®æéã
- ïŒdescription-ä»»æã®åœ¢åŒã®ã€ãã³ãã®èª¬æã
- ïŒã¡ããªãã¯-ã€ãã³ãã«é¢é£ä»ããããã¡ããªãã¯ã
- ïŒttl-ã€ãã³ãé¢é£ã®æéïŒç§åäœïŒã
äžéšã®ã€ãã³ãã«ã¯ãäœæäžãŸãã¯ã€ãã³ãåŠçäžã«è¿œå ã§ããã«ã¹ã¿ã ãã£ãŒã«ãããããŸãïŒããšãã°ãè¿œå ã®ã¡ããªãã¯ãæã€ãã£ãŒã«ãïŒã
ãã¹ãŠã®ã€ãã³ãã¯ã¹ã¬ããã«çµåãããŸãã ã¹ããªãŒã ã¯ãã€ãã³ããéä¿¡ã§ããæ©èœã§ãã
äœæã§ããã¹ã¬ããã®æ°ã«å¶éã¯ãããŸããã ã€ãã³ãã¯ã¹ããªãŒã ãééããŸãããã¹ããªãŒã ã«ã¯ä¿åãããŸããã ãã ããéåžžã«é »ç¹ã«ã€ãã³ãã®ã¹ããŒã¿ã¹ãç£èŠããå¿ èŠããããŸããããšãã°ãé¢é£æ§ã倱ããããã©ãããªã©ã§ãã ãã®ããã«ãã€ã³ããã¯ã¹ã䜿çšãããŸã-ç£èŠå¯Ÿè±¡ã€ãã³ãã®ç¶æ ã®ããŒãã«ã ã€ã³ããã¯ã¹ã§ã¯ãã€ãã³ãã¯ãã¹ãããšããã³ãµãŒãã¹ããšã«ã°ã«ãŒãå¥ã«ãœãŒããããŸãã次ã«äŸã瀺ããŸãã
:host www, :service apache connections, :state nil, :description nil, :metric 100.0, :tags [www], :time 466741572492, :ttl 20
ããã¯ãApacheæ¥ç¶ãµãŒãã¹ã®ãã¹ãwwwã§çºçããã€ãã³ãã§ãã ã€ã³ããã¯ã¹ã«ã¯ãåžžã«ææ°ã®ã€ãã³ããåžžã«ä¿åãããŸãã ã€ã³ããã¯ã¹ã«ã¯ãã¹ããªãŒã ããã¢ã¯ã»ã¹ããããšããå€éšãµãŒãã¹ããã¢ã¯ã»ã¹ããããšãã§ããŸãã
åã€ãã³ãã«TTLïŒæå¹æéïŒãã£ãŒã«ããå«ãŸããããšã¯æ¢ã«ç¢ºèªããŸããã TTLã¯ãã€ãã³ããé¢é£ããæéã§ãã äžèšã®äŸã§ã¯ãã€ãã³ãã®TTLã¯20ç§ã§ãã ã€ã³ããã¯ã¹ã«ã¯ãhost wwwããã³service apache connectionsãšãããã©ã¡ãŒã¿ãŒãæã€ãã¹ãŠã®ã€ãã³ããå«ãŸããŸãã 20ç§ä»¥å ã«ãã®ãããªã€ãã³ããçºçããªãå Žåãç¶æ ãã£ãŒã«ãã®å€ãæéåãã«ãªã£ãæ°ããã€ãã³ããäœæãããŸãã ãã®åŸãã¹ããªãŒã ã«è¿œå ãããŸãã
æ§æ
çè«ããå®è·µã«ç§»ãããªãŒãã³ã®æ§æã«åãããããŸãããã æ§æ/etc/riemann/riemann.configãéããŸãã Clojureããã°ã©ã ã§ãããããã©ã«ãã§ã¯æ¬¡ã®ããã«ãªããŸãã
; -*- mode: clojure; -*- ; vim: filetype=clojure (logging/init {:file "/var/log/riemann/riemann.log"}) ; Listen on the local interface over TCP (5555), UDP (5555), and websockets ; (5556) (let [host "127.0.0.1"] (tcp-server {:host host}) (udp-server {:host host}) (ws-server {:host host})) ; Expire old events from the index every 5 seconds. (periodically-expire 5) (let [index (index)] ; Inbound events will be passed to these streams: (streams (default :ttl 60 ; Index all events immediately. index ; Log expired events. (expired (fn [event] (info "expired" event))))))
ãã®ãã¡ã€ã«ã¯ããã€ãã®ã»ã¯ã·ã§ã³ã«åãããŠããŸãã åã»ã¯ã·ã§ã³ã¯ãClojureã§æ £äŸãšãªã£ãŠããããã«ãã»ãã³ãã³ïŒ;ïŒã§ç€ºãããã³ã¡ã³ãã§å§ãŸããŸãã
æåã®ã»ã¯ã·ã§ã³ã¯ããã°ãæžã蟌ãŸãããã¡ã€ã«ã瀺ããŸãã 次ã«ãã€ã³ã¿ãŒãã§ãŒã¹ãå«ãã»ã¯ã·ã§ã³ããããŸãã ãªãŒãã³ã¯éåžžãTCPãUDPãããã³Webãœã±ããã€ã³ã¿ãŒãã§ã€ã¹ããªãã¹ã³ããŸãã ããã©ã«ãã§ã¯ããããã¯ãã¹ãŠããŒã«ã«ãã¹ãïŒ127.0.0.1ïŒã«ãã€ã³ããããŠããŸãã
次ã®ã»ã¯ã·ã§ã³ã«ã¯ãã€ãã³ããšã€ã³ããã¯ã¹ã®èšå®ãå«ãŸããŠããŸãã
(periodically-expire 5) (let [index (index)] ; Inbound events will be passed to these streams: (streams (default :ttl 60 ; Index all events immediately. index
æåã®é¢æ°ïŒperiodically-expireïŒã¯ãæéåãã«ãªã£ããã¹ãŠã®ã€ãã³ããã€ã³ããã¯ã¹ããåé€ããã¹ããŒã¿ã¹ã«æéåããå²ãåœãŠãŸãã ã€ãã³ãã¯ãªãŒãã³ã°ã¯5ç§ããšã«éå§ãããŸãã
ããã©ã«ãã§ã¯ããªãŒãã³ã¯ãã£ãŒã«ãïŒserviceããã³ïŒhostãæéåãã€ãã³ãã«ã³ããŒããŸãã ä»ã®ãã£ãŒã«ããã³ããŒã§ããŸãã ãããè¡ãã«ã¯ãå®æçã«æéåãã«ãªãé¢æ°ã§key-keysãªãã·ã§ã³ã䜿çšããŸãã ãããã£ãŠãããšãã°ããã¹ãåãšãµãŒãã¹åã ãã§ãªããã¿ã°ãä¿åããããã«æ瀺ã§ããŸãã
(periodically-expire 5 {:keep-keys [:host :service :tags]})
以äžã¯ãindexãšããååã®ã·ã³ãã«ãå®çŸ©ããæ§æã§ãã ãã®æåã®å€ã¯ã€ã³ããã¯ã¹ã§ãã ããã¯ãã€ãã³ããã€ã³ããã¯ã¹ã«éä¿¡ããé¢æ°ã§ãã ã€ãã³ããã€ã³ããã¯ã¹ããã¿ã€ãã³ã°ããªãŒãã³ã«äŒããããã«äœ¿çšãããŸãã
ã¹ããªãŒã æ©èœã䜿çšããŠãã¹ããªãŒã ã«ã€ããŠèª¬æããŸãã åã¹ã¬ããã¯ãã€ãã³ããåŒæ°ãšããŠåãåãé¢æ°ã§ãã streamsé¢æ°ã¯ãRiemannã«æ¬¡ã®ããã«äŒããŸãããæ°ããã€ãã³ããè¿œå ããããšãã«åŒã³åºãå¿ èŠãããé¢æ°ã®ãªã¹ãã以äžã«ç€ºããŸããã ãã®é¢æ°å ã§ãã€ãã³ãã®TTLã60ç§ã«èšå®ããŸãã ãããè¡ãããã«ãã€ãã³ããããã£ãŒã«ããååŸããããã©ã«ãå€ãèšå®ã§ããããã©ã«ãé¢æ°ã䜿çšããŸããã TTLãæããªãã€ãã³ãã¯æéåãã¹ããŒã¿ã¹ãåãåããŸãã
次ã«ãããã©ã«ãã®æ§æãã·ã³ãã«ã€ã³ããã¯ã¹ãåŒã³åºããŸãã ããã¯ããã¹ãŠã®çä¿¡ã€ãã³ããèªåçã«ã€ã³ããã¯ã¹ã«è¿œå ãããããšãæå³ããŸãã
æåŸã®ã»ã¯ã·ã§ã³ã«ã¯ãã¹ããŒã¿ã¹ãæéåãã®ã€ãã³ããèšé²ããæ瀺ãå«ãŸããŠããŸãã
; Log expired events. (expired (fn [event] (info "expired" event))))))
æ§æãã¡ã€ã«ã«ããã€ãã®å€æŽãå ããŸãã ãããã¯ãŒã¯ã€ã³ã¿ãŒãã§ãŒã¹ã®ã»ã¯ã·ã§ã³ã§ã127.0.0.1ã0.0.0.0ã«çœ®ãæããŠãRiemannãä»»æã®ãã¹ãããã€ãã³ããåä¿¡ã§ããããã«ããŸãã
ãã¡ã€ã«ã®æåŸã«ã次ãè¿œå ããŸãã
;print events to the log (streams prn #(info %))
ããã¯ãã€ãã³ãããã°ãšæšæºåºåã«æžã蟌ãprné¢æ°ã§ãã ãã®åŸãå€æŽãä¿åããŠãªãŒãã³ãåèµ·åããŸãã
è€æ°ã®ãµãŒããŒã®äœæ¥ãç£èŠããå¿ èŠãããç¶æ³ã§ã¯ãå ±éã®æ§æãã¡ã€ã«ã§ã¯ãªãããµãŒããŒãŸãã¯ãµãŒããŒã®ã°ã«ãŒãããšã«åå¥ã®ãã¡ã€ã«ãå«ããã£ã¬ã¯ããªå šäœãäœæã§ããŸãïŒ ãã®èšäºã®æšå¥šäºé ãåç § ïŒã
æ§æãã¡ã€ã«ãæžã蟌ãããã®è©³çŽ°ãªæé ã«ã€ããŠã¯ã ãã¡ããã芧ãã ãã ã
ãªãŒãã³ãžã®ããŒã¿éä¿¡
ããã§ã¯ããªãŒãã³ã«ããŒã¿ãéä¿¡ããŠã¿ãŸãããã ããã«ã¯riemann-healthã¯ã©ã€ã¢ã³ãã䜿çšããŸããããã¯ãæ¢ã«ã€ã³ã¹ããŒã«ããriemann-toolsããã±ãŒãžã®äžéšã§ãã ã¿ãŒããã«ã®ãã1ã€ã®ã¿ããéããŠå®è¡ããŸãã
$ riemann-health
ãã®ã³ãã³ãã¯ããã¹ãã®ç¶æ ã«é¢ããRiemannããŒã¿ïŒCPUè² è·ã䜿çšãããŠãããã£ã¹ã¯å®¹éã䜿çšãããŠããã¡ã¢ãªéïŒãéä¿¡ããŸãã
ãªãŒãã³ã¯ã€ãã³ãã®åãå ¥ããéå§ããŸãã ãããã®ã€ãã³ãã«é¢ããæ å ±ã¯ããã¡ã€ã«/var/log/riemann/riemann.logã«æžã蟌ãŸããŸãã 次ã®åœ¢åŒã§è¡šç€ºãããŸãã
#riemann.codec.Event{:host "cs25706", :service "disk /", :state "ok", :description "8% used", :metric 0.08, :tags nil, :time 1456470139, :ttl 10.0} INFO [2016-02-26 10:02:19,571] defaultEventExecutorGroup-2-1 - riemann.config - #riemann.codec.Event{:host cs25706, :service disk /, :state ok, :description 8% used, :metric 0.08, :tags nil, :time 1456470139, :ttl 10.0} #riemann.codec.Event{:host "cs25706", :service "load", :state "ok", :description "1-minute load average/core is 0.02", :metric 0.02, :tags nil, :time 1456470139, :ttl 10.0}
Riemann-healthã¯ãriemann-toolsããã±ãŒãžã®ãŠãŒãã£ãªãã£ã®1ã€ã«ãããŸããã ã¡ããªãã¯ãåéããããã®ããªãå€æ°ã®ãŠãŒãã£ãªãã£ãå«ãŸããŠããŸãïŒriemann-netïŒãããã¯ãŒã¯ã€ã³ã¿ãŒãã§ã€ã¹ã®ç£èŠçšïŒãriemann-diskstatsïŒI / Oãµãã·ã¹ãã ã®ç£èŠçšïŒãriemann-procïŒLinuxã§ã®ããã»ã¹ã®ç£èŠçšïŒãªã©ã ãŠãŒãã£ãªãã£ã®å®å šãªãªã¹ãã¯ããã«ãããŸã ã
æåã®ãã§ãã¯ãäœæãã
ãã®ãããRiemannãã€ã³ã¹ããŒã«ããå®è¡ãããŠããŸãã ã§ã¯ãæåã®ãã§ãã¯ãäœæããŠã¿ãŸãããã æ§æãã¡ã€ã«ãéãã次ã®è¡ãè¿œå ããŸãã
(let [index (index)] (streams (default :ttl 60 index ;#(info %) (where (and (service "disk /") (> metric 0.10)) #(info "Disk space on / is over 10%!" %))
é¢æ°ïŒ#infoïŒã®åã«ã¯ã³ã¡ã³ãèšå·-ã»ãã³ãã³ïŒ;ïŒãä»ããŠããŸãã ããã¯ããªãŒãã³ããã¹ãŠã®ã€ãã³ããèšé²ããã®ãé²ãããã§ãã 次ã«ãWhereã¹ããªãŒã ã«ã€ããŠèª¬æããŸãã ç¹å®ã®åºæºã«äžèŽããã€ãã³ããããã«è©²åœããŸãã ãã®äŸã§ã¯ã次ã®2ã€ã®åºæºããããŸãã
- ãã£ãŒã«ãïŒãµãŒãã¹ã¯ãã£ã¹ã¯/ã«èšå®ããå¿ èŠããããŸãã
- ãã£ãŒã«ãå€ïŒã¡ããªãã¯ã¯0.10ãŸãã¯10ïŒ ãã倧ããå¿ èŠããããŸãã
ãã®åŸããããã¯ãããã«åŠçããããã«åã¹ããªãŒã ã«è»¢éãããŸãã ãã®å Žåããã®ãããªã€ãã³ãã«é¢ããæ å ±ã¯ããã¡ã€ã«/var/log/riemann/riemann.logã«èšé²ãããŸãã
ãã£ã«ã¿ãªã³ã°ïŒã¯ã€ãã¯ãªãã¡ã¬ã³ã¹
ã€ãã³ãããã£ã«ã¿ãªã³ã°ããªããšããªãŒãã³ãšã®æ¬æ Œçãªä»äºã¯äžå¯èœã§ãããããããã€ãã®èšèãå¥ã ã«èšã䟡å€ããããŸãã
æ£èŠè¡šçŸã䜿çšããŠã€ãã³ãããã£ã«ã¿ãªã³ã°ããããšããå§ããŸãããã whereã¹ããªãŒã ã®èª¬æã®æ¬¡ã®äŸãèããŠã¿ãŸãããã
where (service #â^nginxâ))
Clojureã§ã¯ãæ£èŠè¡šçŸã¯ïŒèšå·ã§ç€ºãããäºéåŒçšç¬Šã§å²ãŸããŠããŸãã ãã®äŸã§ã¯ãïŒãµãŒãã¹ãã£ãŒã«ãã«nginxãšããååã®åŒãwhereã¹ããªãŒã ã«å ¥ããŸãã
ã¹ããªãŒã ãè«çæŒç®åã䜿çšããŠçµåã§ããå Žæã®ã€ãã³ãïŒ
(where (and (tagged "www") (state "ok")))
ãã®äŸã§ã¯ãwwwãã£ãŒã«ããšstateãã£ãŒã«ãã®å€ãokã®ã€ãã³ãã¯whereã¹ããªãŒã ã«åé¡ãããŸãã ã¿ã°ä»ãã¹ããªãŒã ããã®ã€ãã³ããšçµåããŸãã
Taggedã¯ããã¹ãŠã®ã€ãã³ããæå®ãããã¿ã°ãšçµã¿åãããããã¹ãŠã¿ã°ä»ãé¢æ°ã®ççž®åã§ãã ã¿ã°ä»ãé¢æ°ããããŸããæå®ããã1ã€ä»¥äžã®ã¿ã°ã§ããŒã¯ãããã€ãã³ããã¹ããªãŒã ã«çµåããŸãã
(tagged-any ["www" "app1"] #(info %))
ãã®äŸã§ã¯ãwwwã¿ã°ãšapp1ã¿ã°ã§ã¿ã°ä»ããããã€ãã³ãã¯ã¿ã°ä»ãã¹ããªãŒã ã«åé¡ãããŸãã
ã€ãã³ãã«é¢é£ããŠã次ã®ãããªæ°åŠæŒç®ãå®è¡ã§ããŸãã
(where (and (tagged "www") (>= (* metric 10) 5)))
ãã®äŸã§ã¯ãã€ãã³ãã¯ã¿ã°wwwãæã€ã€ãã³ããçºçããŸãããã£ãŒã«ãã®å€ïŒã¡ããªãã¯ã«10ãæããå€ã¯5ãè¶ ããŸãã
åæ§ã®æ§æã䜿çšããŠãã¡ããªãã¯ãã£ãŒã«ãã®å€ãæå®ãããç¯å²å ã«ããã€ãã³ããéžæã§ããŸãã
(where (and (tagged "www") (< 5 metric 10)))
äžèšã®äŸã§ã¯ããã£ãŒã«ãïŒã¡ããªãã¯ã®å€ã5ã10ã®ç¯å²ã«ããwwwã¿ã°ãæã€ã€ãã³ãã¯ãwhereã¹ããªãŒã ã«åé¡ãããŸãã
éç¥ãèšå®ãã
ãªãŒãã³ã¯ãæå®ãããç£æ»æ¡ä»¶ãæºããå Žåã«éç¥ãéä¿¡ããå ŽåããããŸãã é»åã¡ãŒã«éç¥ãèšå®ããããšããå§ããŸãããã ãªãŒãã³ã¯ããã«ã¡ãŒã«æ©èœã䜿çšããŸãã
[
(def email (mailer {:from "riemann@example.com"})) (let [index (index)] ; Inbound events will be passed to these streams: (streams (default :ttl 60 ; Index all events immediately. index (changed-state {:init "ok"} (email "andrei@example.com")))))
Clojure- Postalã®ç¹å¥ãªã©ã€ãã©ãªã«åºã¥ããŠãéç¥ããªãŒãã³ã«éä¿¡ãããŸãã ããã©ã«ãã§ã¯ãããŒã«ã«ã¡ãŒã«ãµãŒããŒãé åžã«äœ¿çšãããŸãã
ãã¹ãŠã®ã¡ãã»ãŒãžã¯ãriemann @ example.comãªã©ã®ã¢ãã¬ã¹ããéä¿¡ãããŸãã
ããŒã«ã«ã¡ãŒã«ãµãŒããŒãã€ã³ã¹ããŒã«ãããŠããªãå ŽåãRiemannã¯æ¬¡ã®åœ¢åŒã®ãšã©ãŒã¡ãã»ãŒãžã衚瀺ããŸãã
riemann.email$mailer$make_stream threw java.lang.NullPointerException
äžèšã®ã³ãŒãäŸã§ã¯ãç¶æ ãå€æŽãããã·ã§ãŒãã«ããã䜿çšããããããªãŒãã³ã¯ã¹ããŒã¿ã¹ãå€æŽãããã€ãã³ãã远跡ããå¿ èŠãããããšã瀺ããŸããã initå€æ°ã®å€ã¯ãã€ãã³ãã®åæç¶æ ãäœã§ãããããªãŒãã³ã«äŒããŸãã ã¹ããŒã¿ã¹ãokãããã®ä»ã«å€æŽããããã¹ãŠã®ã€ãã³ãã¯ãé»åã¡ãŒã«æ©èœã«æž¡ãããŸãã ãã®ãããªã€ãã³ãã«é¢ããæ å ±ã¯ãæå®ãããã¡ãŒã«ã¢ãã¬ã¹ã«éä¿¡ãããŸãã
éç¥ã®èšå®ã®è©³çŽ°ãªäŸã«ã€ããŠã¯ãRiemannã®éçºè ã®1人ã§ããJames Turnbullãåç §ããŠãã ããã
ã¡ããªãã¯ã®å¯èŠåïŒriemann-dash
Riemannã«ã¯ãã¡ããªãã¯ãèŠèŠåããã·ã³ãã«ãªããã·ã¥ããŒããäœæããããã®ç¬èªã®ããŒã«riemann-dashããããŸãã 次ã®ããã«ã€ã³ã¹ããŒã«ã§ããŸãã
$ git clone git://github.com/aphyr/riemann-dash.git $ cd riemann-dash $ bundle
ãªãŒãã³ããã·ã¥ã¯æ¬¡ã®ã³ãã³ãã§å§ãŸããŸãïŒ
$ riemann-dash
riemann-dashããŒã ããŒãžã¯ããã©ãŠã¶ã®ã¢ãã¬ã¹[server ip-address]ïŒ4567ã§å©çšã§ããŸãã
çãäžã®é»ããªãŒãã³ç¢æã«ç§»åããŠãCtrlããŒïŒMacã®å Žåã¯cmdïŒãæŒããŠã¯ãªãã¯ããŸãã ãã£ãã·ã§ã³ã¯ã°ã¬ãŒè¡šç€ºãããŸãã ãã®åŸãEããŒãæŒããŠç·šéãéå§ããŸãã
ã¿ã€ãã«ã®ããããããŠã³ã¡ãã¥ãŒã§ãã°ãªããé ç®ãéžæããã¯ãšãªãã£ãŒã«ãã«trueãå ¥åããŸãã
å¿ èŠãªèšå®ãèšå®ãããã[é©çš]ãã¿ã³ãã¯ãªãã¯ããŸãã
ããã·ã¥ããŒãã¯ãèŠãç®ã䟿å©ã§ããããŸããããéåžžã«èŠèŠçã§ãã ãã ããRiemannã䜿çšãããšããµãŒãããŒãã£ã®èŠèŠåããŒã«ãç¹ã«GraphiteãšGrafanaã䜿çšã§ãããšããäžäŸ¿ãã¯çžæ®ºãããŸããèå³ã®ããèªè ã¯ãã€ã³ã¿ãŒãããã§é¢é£åºçç©ãç°¡åã«èŠã€ããããšãã§ããŸãã ãŸããRiemann + InfluxDB + Grafanaãã³ãã«ã®ã»ããã¢ããæé ã«ã€ããŠã¯ã次ã®ã»ã¯ã·ã§ã³ã§èª¬æããŸãã
InfluxDBãžã®ããŒã¿ã®éä¿¡
ãªãŒãã³ã®ééããªãå©ç¹ã¯ããã®å¹ åºãçµ±åæ©èœã§ãã ããã䜿çšããŠåéãããã¡ããªãã¯ã¯ããµãŒãããŒãã£ã®ã¹ãã¢ã«éä¿¡ã§ããŸãã 以äžã§ã¯ãRiemannãInfluxDBãšçµ±åãã Grafanaã䜿çšããŠããŒã¿ã®èŠèŠåãã«ã¹ã¿ãã€ãºããæ¹æ³ã瀺ããŸãã
InfluxDBãã€ã³ã¹ããŒã«ããŸãã
$ wget https://s3.amazonaws.com/influxdb/influxdb_0.9.6.1_amd64.deb $ sudo dpkg -i influxdb_0.9.6.1_amd64.deb
InfluxDBã®æ§æã«ã€ããŠã®è©³çŽ°ã¯ã å ¬åŒããã¥ã¡ã³ããšä»¥åã®èšäºã®ãããããã芧ãã ãã ã
ã€ã³ã¹ããŒã«ãå®äºãããã次ã®ã³ãã³ããå®è¡ããŸãã
$ sudo /etc/init.d/influxdb start
次ã«ããªãŒãã³ããã®ããŒã¿ãä¿åããããŒã¿ããŒã¹ãäœæããŸãã
$ sudo influx >CREATE DATABASE riemann
ãã®ããŒã¿ããŒã¹ã®ãŠãŒã¶ãŒãäœæãããã¹ã¯ãŒããèšå®ããŠã¿ãŸãããã
>CREATE USER riemann WITH PASSWORD ' riemann' >GRANT ALL ON riemann TO riemann
ããã§ãInfluxDBã®ã€ã³ã¹ããŒã«ãšåºæ¬èšå®ãå®äºããŸããã 次ã«ãå¿ èŠãªèšå®ãRiemannæ§æãã¡ã€ã«ã«ç»é²ããå¿ èŠããããŸãïŒã³ãŒãã¯ããããååŸãã ããããã«å€æŽãããŠããŸãïŒã
; -*- mode: clojure; -*- ; vim: filetype=clojure ; capacitor, InfluxDB (require 'capacitor.core) (require 'capacitor.async) (require 'clojure.core.async) (defn make-async-influxdb-client [opts] (let [client (capacitor.core/make-client opts) events-in (capacitor.async/make-chan) resp-out (capacitor.async/make-chan)] (capacitor.async/run! events-in resp-out client 100 10000) (fn [series payload] (let [p (merge payload { :series series :time (* 1000 (:time payload)) ;; s â ms })] (clojure.core.async/put! events-in p))))) (def influx (make-async-influxdb-client { :host "localhost" :port 8086 :username "riemann" :password " riemann" :db "riemann" })) (logging/init {:file "/var/log/riemann/riemann.log"}) (let [host "0.0.0.0"] (tcp-server {:host host}) (udp-server {:host host}) (ws-server {:host host})) (periodically-expire 60) (let [index (index)] (streams index (fn [event] (let [series (format "%s.%s" (:host event) (:service event))] (influx series { :time (:time event) :value (:metric event) })))))
å€æŽãä¿åãããªãŒãã³ãåèµ·åããŸãã
ãã®åŸãGrafanaãã€ã³ã¹ããŒã«ããŸãã
$ wget https://grafanarel.s3.amazonaws.com/builds/grafana_2.6.0_amd64.deb $ sudo dpkg -i grafana_2.6.0_amd64.deb
Grafanaã®èšå®æ¹æ³ã«ã€ããŠã¯è©³çŽ°ãªèª¬æãè¡ããŸãããç¹å¥ãªå¿ èŠã¯ãããŸããã察å¿ããåºçç©ã¯ã€ã³ã¿ãŒãããã§ç°¡åã«èŠã€ããããšãã§ããŸãã
Grafanaã®ããŒã ããŒãžã¯ãhttpïŒ// [ãµãŒããŒIP]ïŒ3000ã®ãã©ãŠã¶ãŒã§å©çšã§ããŸãã 次ã«ãæ°ããããŒã¿ãœãŒã¹ïŒInfluxDBïŒãè¿œå ããããã·ã¥ããŒããäœæããã ãã§ãã
ãããã«
ãã®èšäºã§ã¯ããªãŒãã³ã®æ©èœã®æŠèŠãç°¡åã«èª¬æããŸããã 次ã®ãããã¯ã«ã€ããŠèª¬æããŸããã
- Clojureèšèªæ©èœ
- ãªãŒãã³ã®ã€ã³ã¹ããŒã«ãšåæèšå®ã
- æ§æãã¡ã€ã«ã®æ§é ãšãã®æ§æã®æ©èœã
- ãã§ãã¯ã®äœæã
- éç¥èšå®;
- ãªãŒãã³ããã·ã¥ã䜿çšããã¡ããªãã¯ã®èŠèŠå
- InfluxDBãšã®ãªãŒãã³çµ±åããã³Grafanaã䜿çšããã¡ããªãã¯ã®èŠèŠå
éèŠãªè©³çŽ°ãèŠèœãšããŠãããšæãããå Žåã¯ããé£çµ¡ãã ãããã¬ãã¥ãŒãè£è¶³ããŸãã ãŸããå®éã«ãªãŒãã³ã䜿çšããŠããå Žåã¯ãã³ã¡ã³ãã§çµéšãå ±æããŠãã ããã
äœããã®çç±ã§ããã«ã³ã¡ã³ããæ®ããªãå Žåã¯ã åœç€Ÿã®äŒæ¥ããã°ãžããããã