Giter VIP home page Giter VIP logo

fluent-plugin-clickhouse's Introduction

What is this?

It's a output plugin for Fluentd, that sends data into Yandex ClickHouse database. By now it supports buffered output (I still don't know how) and handling few exceptions.

How to use it?

I'm not a ruby programmer who knows how to write gems, so just put out_clickhouse.rb to /etc/td-agent/plugin.
There's example td-agent.conf:

<source>
    @type http
    port 8888
</source>
<match inp>
    @type clickhouse
    host 127.0.0.1
    port 8123
    table FLUENT
    datetime_name DateTime # name for internal fluentd datetime field
    fields DateTime,tag,Num # in this order values will be inserted in CH
</match>

Before launching td-agent, create table into ClickHouse:
CREATE TABLE FLUENT ( Date Date MATERIALIZED toDate(DateTime), DateTime DateTime, Str String, Num Int32) ENGINE = MergeTree(Date, Date, DateTime, 8192)
Start td-agent and send a few events to fluentd:

curl -X POST -d 'json={"Num":1}' http://localhost:8888/inp
curl -X POST -d 'json={"Num":2}' http://localhost:8888/inp
curl -X POST -d 'json={"Num":3}' http://localhost:8888/inp

After a few seconds, when buffer flushes, in ClickHouse you could see this:

┌───────Date─┬────────────DateTime─┬─Str─┬─Num─┐  
│ 2017-11-06 │ 2017-11-06 14:42:03 │ inp │   1 │  
│ 2017-11-06 │ 2017-11-06 14:42:06 │ inp │   2 │  
│ 2017-11-06 │ 2017-11-06 14:42:09 │ inp │   3 │  
└────────────┴─────────────────────┴─────┴─────┘  

Wow, it doesn't even support HTTP auth

Yes, and besides auth, there's still a work to do:

  • SSL
  • Timezones that doesn't suck
  • GZIP. ClickHouse supports compressing, so why not?
  • and more

fluent-plugin-clickhouse's People

Contributors

kam1sh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

fluent-plugin-clickhouse's Issues

How to change time_format from time_iso8601 in fluentd and send to clickhouse?

hello!

There is nginx.conf

....
http {
....
    log_format  main  '"$remote_addr" "$time_iso8601"';
    access_log  /var/log/nginx/access.log  main;
.....
}

Logs access.log

"127.0.0.1" "2019-12-28T10:53:20+00:00"
"127.0.0.1" "2019-12-28T10:53:20+00:00"

There is fluent (td-agent)

td-agent.conf
<source>
  @type tail
  path /var/log/nginx/access.log
  pos_file /tmp/nginx-access-log.pos
  tag nginx
  format /"(?<remote_addr>[0-9,\.]*)" "(?<time_iso8601>[^ ]*)"/
  time_format %Y-%m-%dT%H:%M:%S.%NZ
</source>


<filter foo.bar>
  @type record_transformer
  enable_ruby
  <record>
    time_iso8601 ${Time.strptime(record['time_iso8601'], '%Y-%m-%d %H:%M:%S').iso8601}
  </record>
</filter>

<match nginx>
    @type clickhousejson
    host 127.0.0.1
    port 8123
    database fluent
    table fluent
    datetime_name time_iso8601
</match>

In clickhouse I created a database and a table.

create database fluent;

CREATE TABLE fluent.fluent (Date Date MATERIALIZED toDate(DateTime), remoteip String, DateTime DateTime) ENGINE = MergeTree(Date, DateTime, 8192);

Logs are sent to clickhouse.

│          │ 0000-00-00 00:00:00 │

How to change time_format from time_iso8601 to %Y-%m-%d %H:%M:%S in fluentd (td-agent) and send to clickhouse?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.