| 301 |
ashish |
1 |
## Copyright (c) 2007-2008 Facebook
|
|
|
2 |
##
|
|
|
3 |
## Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
4 |
## you may not use this file except in compliance with the License.
|
|
|
5 |
## You may obtain a copy of the License at
|
|
|
6 |
##
|
|
|
7 |
## http://www.apache.org/licenses/LICENSE-2.0
|
|
|
8 |
##
|
|
|
9 |
## Unless required by applicable law or agreed to in writing, software
|
|
|
10 |
## distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
11 |
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
12 |
## See the License for the specific language governing permissions and
|
|
|
13 |
## limitations under the License.
|
|
|
14 |
##
|
|
|
15 |
## See accompanying file LICENSE or visit the Scribe site at:
|
|
|
16 |
## http://developers.facebook.com/scribe/
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
# This file contains a couple of simple examples of how to configure and use
|
|
|
20 |
# Scribe.
|
|
|
21 |
#
|
|
|
22 |
# Example code in this directory:
|
|
|
23 |
# scribe_cat: a simple example of a client that can send messages to Scribe
|
|
|
24 |
# scribe_ctrl: a script that manages a running Scribe instance (requires root)
|
|
|
25 |
# example1.conf: sample configuration file for running Example 1
|
|
|
26 |
# example2.conf: sample configuration file for running Example 2
|
|
|
27 |
|
|
|
28 |
#
|
|
|
29 |
# EXAMPLE 1
|
|
|
30 |
#
|
|
|
31 |
|
|
|
32 |
# This is a simple example that shows how to configure and send messages to
|
|
|
33 |
# Scribe.
|
|
|
34 |
|
|
|
35 |
#Create a directory to log messages:
|
|
|
36 |
mkdir /tmp/scribetest
|
|
|
37 |
|
|
|
38 |
#Start scribe using the configuration in example1.conf:
|
|
|
39 |
src/scribed examples/example1.conf
|
|
|
40 |
|
|
|
41 |
#From another terminal, use scribe_cat to send a message to scribe:
|
|
|
42 |
echo "hello world" | ./scribe_cat test
|
|
|
43 |
|
|
|
44 |
#If the previous command failed, make sure you did a 'make install' from the
|
|
|
45 |
#root scribe directory and that $PYTHONPATH is set correctly(see README.BUILD)
|
|
|
46 |
|
|
|
47 |
#Verify that the message got logged:
|
|
|
48 |
cat /tmp/scribetest/test/test_current
|
|
|
49 |
|
|
|
50 |
#Check the status of scribe (requires root):
|
|
|
51 |
./scribe_ctrl status
|
|
|
52 |
|
|
|
53 |
#Check scribe's counters (you should see 1 message 'received good'):
|
|
|
54 |
./scribe_ctrl counters
|
|
|
55 |
|
|
|
56 |
#Shutdown scribe:
|
|
|
57 |
./scribe_ctrl stop
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
#
|
|
|
61 |
# Example 2
|
|
|
62 |
#
|
|
|
63 |
|
|
|
64 |
# This example shows you how to log messages between multiple Scribe instances.
|
|
|
65 |
# In this example, we will run each Scribe server on a different port to simulate
|
|
|
66 |
# running Scribe on multiple machines.
|
|
|
67 |
|
|
|
68 |
'client' 'central'
|
|
|
69 |
---------------------------- --------------------
|
|
|
70 |
| Port 1464 | | Port 1463 |
|
|
|
71 |
| ---------------- | | ---------------- |
|
|
|
72 |
| -> | scribe server |--|--->| | scribe server | |
|
|
|
73 |
| ---------------- | | ---------------- |
|
|
|
74 |
| | | | | | |
|
|
|
75 |
| temp file | | | temp file |
|
|
|
76 |
|--------------------------- |-------------------
|
|
|
77 |
|
|
|
|
78 |
-------------------
|
|
|
79 |
| /tmp/scribetest/ |
|
|
|
80 |
-------------------
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
#Create a directory for the second scribe instance:
|
|
|
84 |
mkdir /tmp/scribetest2
|
|
|
85 |
|
|
|
86 |
#Start up the 'central' instance of Scribe on port 1463 to write messages to disk
|
|
|
87 |
#(See example2central.conf):
|
|
|
88 |
src/scribed examples/example2central.conf
|
|
|
89 |
|
|
|
90 |
#Start up the 'client' instance of Scribe on port 1464 to forward messages to
|
|
|
91 |
#the 'central' Scribe server (See example2client.conf):
|
|
|
92 |
src/scribed examples/example2client.conf
|
|
|
93 |
|
|
|
94 |
#Use scribe_cat to send some messages to the 'client' Scribe instance:
|
|
|
95 |
echo "test message" | ./scribe_cat -h localhost:1464 test2
|
|
|
96 |
|
|
|
97 |
echo "this message will be ignored" | ./scribe_cat -h localhost:1464 ignore_me
|
|
|
98 |
|
|
|
99 |
echo "123:this message will be bucketed" | ./scribe_cat -h localhost:1464 bucket_me
|
|
|
100 |
|
|
|
101 |
#The first message will be logged similar to example 1.
|
|
|
102 |
#The second message will not get logged.
|
|
|
103 |
#The third message will be bucketized into 1 of 5 buckets
|
|
|
104 |
#(See example2central.conf)
|
|
|
105 |
|
|
|
106 |
#Verify that the first message got logged:
|
|
|
107 |
cat /tmp/scribetest/test2/test2_current
|
|
|
108 |
|
|
|
109 |
#Verify that the third message got logged into a subdirectory:
|
|
|
110 |
cat /tmp/scribetest/bucket*/bucket_me_current
|
|
|
111 |
|
|
|
112 |
#Check the status and counters of both instances:
|
|
|
113 |
./scribe_ctrl status 1463
|
|
|
114 |
./scribe_ctrl status 1464
|
|
|
115 |
./scribe_ctrl counters 1463
|
|
|
116 |
./scribe_ctrl counters 1464
|
|
|
117 |
|
|
|
118 |
#Shutdown both servers:
|
|
|
119 |
./scribe_ctrl stop 1463
|
|
|
120 |
./scribe_ctrl stop 1464
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
#
|
|
|
124 |
# Example 3
|
|
|
125 |
#
|
|
|
126 |
|
|
|
127 |
# Test Scribe buffering
|
|
|
128 |
|
|
|
129 |
#Startup the two Scribe instances used in Example 2.
|
|
|
130 |
#Start the 'central' server first:
|
|
|
131 |
src/scribed examples/example2central.conf
|
|
|
132 |
|
|
|
133 |
#Then start the 'client':
|
|
|
134 |
src/scribed examples/example2client.conf
|
|
|
135 |
|
|
|
136 |
#Log a message to the 'client' Scribe instance:
|
|
|
137 |
echo "test message 1" | ./scribe_cat -h localhost:1464 test3
|
|
|
138 |
|
|
|
139 |
#Verify that the message got logged:
|
|
|
140 |
cat /tmp/scribetest/test3/test3_current
|
|
|
141 |
|
|
|
142 |
#Stop the 'central' Scribe instance:
|
|
|
143 |
./scribe_ctrl stop 1463
|
|
|
144 |
|
|
|
145 |
#Attempting to check the status of this server will return failure since it not running:
|
|
|
146 |
./scribe_ctrl status 1463
|
|
|
147 |
|
|
|
148 |
#Try to Log another message:
|
|
|
149 |
echo "test message 2" | ./scribe_cat -h localhost:1464 test3
|
|
|
150 |
|
|
|
151 |
#This message will be buffered by the 'client' since it cannot be forwarded to
|
|
|
152 |
#the 'central' server. Scribe will keep retrying until it is able to send.
|
|
|
153 |
|
|
|
154 |
#After a couple seconds, the status of the 'client' will be set to a warning message:
|
|
|
155 |
./scribe_ctrl status 1464
|
|
|
156 |
|
|
|
157 |
#Try to Log yet another message(which will also get buffered):
|
|
|
158 |
echo "test message 3" | ./scribe_cat -h localhost:1464 test3
|
|
|
159 |
|
|
|
160 |
#Restart the 'central' instance:
|
|
|
161 |
src/scribed examples/example2central.conf
|
|
|
162 |
|
|
|
163 |
#Wait for both Scribe instance's statuses to change to ALIVE:
|
|
|
164 |
./scribe_ctrl status 1463
|
|
|
165 |
./scribe_ctrl status 1464
|
|
|
166 |
|
|
|
167 |
#Verify that all 3 messages have now been received by the 'central' server:
|
|
|
168 |
cat /tmp/scribetest/test3/test3_current
|
|
|
169 |
|
|
|
170 |
#Shutdown:
|
|
|
171 |
./scribe_ctrl stop 1463
|
|
|
172 |
./scribe_ctrl stop 1464
|