How to Apply scribe to actual services

Source: Internet
Author: User

Scribe is an open-source log collection system on Facebook. I have written a blog post about scribe, mainly about the compilation and installation methods of each dependent package of scribe and the configuration methods of the scribe service. Today, we will learn how to apply scribe to actual services.

Before learning, you need to know how to correctly install and configure the scribe service. If you still can't, please move to another blog 《ScribeInstallation and configuration methodsThe URL is http://cyr520.blog.51cto.com/714067/1209485.

To make scribe play a role in your business, we need to use thrift to generate a header file after installing the scribe service, and then reference the generated header file to your program. In this way, we have the scribe client. With the client, it is easy to collect any data.

Thrift supports many languages, including as3, C ++, C #, java, python, php, perl, and ruby.

The following uses php as an example to describe the following operations:

1. Find two files in the source package, fb303.thrift and scribe. thift, and put them in the same directory.

mkdir -p /data/tmpcd /data/tmp/cp /data/software/thrift-0.4.0/contrib/fb303/if/fb303.thrift /data/tmp/cp /data/software /scribe-2.1/if/scribe.thrift /data/tmp/

2. Modify the path that contains fb303 in scribe. thrift to the current path.

vim scribe.thrift

650) this. width = 650; "style =" background-image: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right-:; padding-left: 0px; padding-right: 0px; padding-top: 0px; "title =" clip_image002 "border =" 0 "alt =" clip_image002 "src =" http://www.bkjia.com/uploads/allimg/131228/0052533134-0.jpg "width =" 558 "height =" 461 "/>

3. Use thrift to generate the php interface file. The generated directory name is gen-php.

/usr/local/thrift/bin/thrift -r --gen php scribe.thrift

650) this. width = 650; "style =" background-image: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right-:; padding-left: 0px; padding-right: 0px; padding-top: 0px; "title =" clip_image004 "border =" 0 "alt =" clip_image004 "src =" http://www.bkjia.com/uploads/allimg/131228/0052531415-1.jpg "width =" 558 "height =" 81 "/>

4. Change the generated gen-php to an interesting name and copy several necessary directories.

mkdir includesmv gen-php includes/packagescp /data/software/thrift-0.4.0/lib/php/src/Thrift.php /data/tmp/includes/cp /data/software/thrift-0.4.0/lib/php/src/autoload.php /data/tmp/includes/cp -r /data/software/thrift-0.4.0/lib/php/src/protocol /data/tmp/includes/cp -r /data/software/thrift-0.4.0/lib/php/src/transport /data/tmp/includes/

The entire directory structure is as follows:

650) this. width = 650; "style =" background-image: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right-:; padding-left: 0px; padding-right: 0px; padding-top: 0px; "title =" clip_image006 "border =" 0 "alt =" clip_image006 "src =" http://www.bkjia.com/uploads/allimg/131228/0052532120-2.jpg "width =" 316 "height =" 397 "/>

5. Compile a php client test program.

vim php_client_test.php
<?php$GLOBALS['THRIFT_ROOT'] = './includes';include_once $GLOBALS['THRIFT_ROOT'] . '/packages/scribe/scribe.php';include_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';include_once $GLOBALS['THRIFT_ROOT'] . '/transport/TFramedTransport.php';include_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';$msg1['category'] = 'TEST';$msg1['message'] = "Test Message.";$entry1 = new LogEntry($msg1);$messages = array($entry1);$socket = new TSocket('localhost', 1463, true);$transport = new TFramedTransport($socket);$protocol = new TBinaryProtocol($transport, false, false);$scribe_client = new scribeClient($protocol, $protocol);$transport->open();$scribe_client->Log($messages);$transport->close();?>

6. Run the test script.

php php_client_test.php

7. Verify the program execution result.

650) this. width = 650; "style =" background-image: none; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-right-:; padding-left: 0px; padding-right: 0px; padding-top: 0px; "title =" clip_image008 "border =" 0 "alt =" clip_image008 "src =" http://www.bkjia.com/uploads/allimg/131228/0052533E0-3.jpg "width =" 496 "height =" 120 "/>

Here, our experiment is complete. If you have any questions, please join me.

This article from the "small Cui's growth path" blog, please be sure to keep this source http://cyr520.blog.51cto.com/714067/1265181

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.