將資料傳送到BigQuery
BigQuery是Google所提供儲存大資料並可以直接使用SQL來查詢的服務,BigQuery勘稱是目前大資料分析與儲存的最佳平台... Fluentd上當然有BigQuery儲存的Plugin...
設定檔
搭配syslog篇所提到的syslog input,在BigQuery的Schema中我們可以定義syslog的欄位包含:pri,time,host,ident,pid,message等。一般我會在standard output中鮮觀察source input的結果,再將欄位設定到BigQuery output中...
<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 bigquery
method insert # default
auth_method private_key # default
email [email protected] #service account
private_key_path /data/mykey.p12 #service account p12 key
project your-project-id #project id
dataset bq_test #dataset name
auto_create_table true
table syslog_%Y_%m_%d
flush_interval 1 # flush as frequent as possible
buffer_chunk_records_limit 300 # default rate limit for users is 100
buffer_queue_limit 1024 # 1MB * 1024 -> 1GB!
num_threads 16
time_format %s
time_field time
field_string pri,time,host,ident,pid,message
</store>
</match>
在BigQuery的plugin中,另外有一些參數可以提供一些進階的設定:
- dataset: 設定BigQuery dataset的名稱,其中dataset必須先create
- table: 設定表格的名稱,在設定中可以使用%Y, %m, %d來代表年、月、日
- flush_interval: 資料送到BigQuery的區間,該區間過於頻繁可能會導致效能不彰,設定過大則可能會造成資料不夠即時,需要自行評估
- auto_create_table: 是否在table不存在時候,自動建立table
- buffer_chunk_records_limit: 設定buffer的筆數,筆數超過後則會提前flush buffer,將資料送進BigQuery
- buffer_queue_limit: 設定buffer大小,大小超過,也會提前flush buffer,將資料送進BigQuery
- num_threads: 啟動多少thread來進行傳送
預先設定
在啟用BigQuery傳送前,必須先進行一些設定與申請:
- Google Cloud專案申請:請到https://console.developers.google.com/project申請Google Cloud專案。專案建立完成後,需要啟用Billing方可以使用BigQuery服務。
- BigQuery啟用:在專案啟用後,需要到API & Auth > APIs將BigQuery API開啟,讓service account可以使用該API
- 建立service account:至專案頁面,從API & Auth > Credentials的頁面,即可申請service account。設定檔案中使用到的service account以及p12檔案,即是由此頁面產生。