Giter VIP home page Giter VIP logo

katja's Introduction

Katja

A simple Riemann client written in Erlang.

Build Status Coverage Status

Status

This is alpha software. Things might still change in ways that break everything.

Configuration

% Defaults
[
  {katja, [
    {host, "127.0.0.1"},
    {port, 5555},
    {transport, detect},
    {pool, []},
    {defaults, []}
  ]}
].

host: Host Riemann is running on

port: Port Riemann is listening on

transport: The message transport that should be used (supported: detect, udp, tcp)

pool: List of processes that should not be started (and supervised) by Katja (supported: katja_reader, katja_writer)

defaults: Property list with default values for events and states (supported: host, tags, ttl)

Examples

Sending an event

Event = [{service, "katja demo"}, {metric, 9000.1}],
ok = katja:send_event(Event).

An event in Katja is just a property list. A list of all possible properties can be found in the katja module.

You can send an event asynchronously using katja:send_event_async/{1,2,3}:

Event = [{service, "katja demo"}, {metric, 9000.1}],
ok = katja:send_event_async(Event).

This will return immediately and you will not know if the call has succeeded.

Sending a state

State = [{service, "katja demo"}, {state, "testing"}],
ok = katja:send_state(State).

Just like events, a state is a property list. The properties can once again be found in the katja module.

Just like for events, you can use katja:send_state_async/{1,2,3} to send states in a non-blocking way.

Sending multiple entities

Event = [{service, "katja demo"}, {metric, 9000.1}],
State = [{service, "katja demo"}, {state, "testing"}],
ok = katja:send_entities([{events, [Event, Event]}, {states, [State, State]}]).

katja:send_entities/1 takes a property list with two possible properties: events should be set to a list of events and states should be set to a list of states.

Both properties are optional, so katja:send_entities/1 can be used to only send multiple events or states.

Event = [{service, "katja demo"}, {metric, 9000.1}],
State = [{service, "katja demo"}, {state, "testing"}],
ok = katja:send_events([Event]),
ok = katja:send_states([State]).

katja:send_events/1 and katja:send_states/1 are also available to send multiple events or states. Both of them delegate to katja:send_entities/1 internally.

Sending entities asynchronously is also possible. All of the methods mentioned above have matching _async/{1,2,3} counterparts.

Querying

{ok, Events} = katja:query("service = \"katja demo\"").

A query returns a list of events. Events are in the format that you specify when sending data to Riemann.

Instead of a string you can also use a katja:event() and the katja:query_event/1 method to send queries to Riemann.

{ok, Events} = katja:query_event([{service, "katja demo"}]).

Katja will convert the event to a query string and query Riemann based on the generated string.

You can use katja:query_async/{1,2} and katja:query_event_async/{1,2} to send queries asynchronously. The results will be sent to the inbox of the calling process.

Ref = katja:query_async("service = \"katja demo\""),
receive
  {Ref, {ok, Events}} ->
    % ...
end.

Pooling

All the methods mentioned above optionally take a katja:process() as their first argument, enabling Katja to easily work with existing process pool implementations. katja:process() is either a pid() or one of the two following atoms: katja_writer, katja_reader.

The atom() cases usually don't have to be used directly, since katja:send_event/1, katja:send_state/1, katja:query/1 etc. default to setting the correct value.

Additionally you can also "turn off" the katja_writer and katja_reader processes that are automatically started and supervised by adding their names to the pool configuration option.

Forcing a transport

You can force a message to be send via TCP or UDP. By default, the transport is chosen based on the size of a message: UDP is used for messages up to 16Kb in size, everything larger than that uses TCP. Querying Riemann always uses TCP.

Event = [{service, "katja demo"}, {metric, 9000.1}],
ok = katja:send_event(katja_writer, tcp, Event).

The first argument to katja:send_event/3, katja:send_events/3, katja:send_state/3, katja:send_states/3 and katja:send_entities/3 is a katja:process(). If you're using one of these methods and don't use a process pool, it has to be set to katja_writer.

You can set the transport configuration option to tcp or udp to always use that transport for sending data to Riemann.

Resources

Related Projects

  • Katja VM Stats - Easily send information about the Erlang VM to Riemann

License

ISC.

Copyright (c) 2014-2016, Daniel Kempkens <[email protected]>
Copyright The katja-beam Contributors

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

katja's People

Contributors

ichernetsky avatar joaohf avatar nifoc avatar puzza007 avatar robashton avatar srijan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

katja's Issues

Add pooling support

It should be possible to easily integrate Katja with existing pooling solutions like Poolboy or Pooler.

Since I want to keep Katja as lightweight as possible (dependency-wise), Katja will not take care of managing pools in any way (including pool membership). All Katja will do in regards to supporting pooling is:

  1. Provide a way to not start/supervise the katja_metrics and katja_queries processes
  2. Add APIs that do not depend on katja_metrics and katja_queries being registered processes

1. is basically already implemented in the development branch. The supervisor will look at the pool application setting and not add a process to its children if it's present in the poollist.

For 2. it will come down to adding APIs that take a PID (of a katja_metrics or katja_queries process) as their first argument.

Katja silently drops one event when riemann server is restarted.

When Riemann is restarted on the server side, then the first event sent using katja:send_event returns {error/closed}. Second time the send_event is successful. At the first call of katja:send_event after restart of riemann, line number 233 of katja_connection.erl is triggered because first ok is returned by gen_tcp:send at line 229. Then line 231, receive_reply_tcp returns {error,closed}.
When katja:send_event is called second time after Riemann restart, line number 229 straight away returns {error,closed} after which line number 235 is triggered. The tcp connection gets closed at line 238 and maybe_connect_and_send_tcp is called at line number 239. Therefore, second time the call gets successful. Connection failure needs to be handled right first time when {error,closed} is received as return from line 231's receive_reply_tcp.

Compile fails on OTP 19

Error message:

 ERLC   katja_sup.erl katja.erl katja_app.erl katja_writer.erl katja_connection.erl katja_reader.erl
compile: warnings being treated as errors
src/katja_writer.erl:189: random:uniform/0: the 'random' module is deprecated; use the 'rand' module instead
src/katja_writer.erl:193: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
src/katja_writer.erl:194: random:seed/1: the 'random' module is deprecated; use the 'rand' module instead
erlang.mk:232: recipe for target 'ebin/katja.app' failed
make: *** [ebin/katja.app] Error 1

provide a test/dev handler sink

instead of requiring riemann all the time, provide some sort of sink that either logs to a file, or drops data on the floor, this should be sufficient to allow telemetry testing of katja

Compilation Failure

===> Skipping meck (from {git,"git://github.com/basho/meck.git",
{tag,"0.8.2"}}) as an app of the same name has already been fetched
===> Compiling katja
===> Compiling _build/default/lib/katja/src/katja_writer.erl failed
_build/default/lib/katja/include/katja_types.hrl:11: can't find include file "katja_pb.hrl"

Please add this project to the erlang.mk package index

Hello!

I notice that you are using erlang.mk to build your project. That's great!

It only takes two minutes to add your project to the erlang.mk package index file! Why not do it? When your project is in the package index, you can control what version people use by default, and make it easier for people to find and use your project. Adding your project as dependency becomes as easy as adding DEPS = yourprojectname to the Makefile!

To add your project to the index file, simply follow the instructions in the erlang.mk README at https://github.com/ninenines/erlang.mk#contributing and submit a pull request! I hope to merge it soon!

I apologize for the generic message. :-)

Erlang R18 and Protobuffs

I'd do a pull request but I really don't know what version of PB you really want here.

Switching to 'develop' results in something that works, but compiling under R18 off the current tag yields in the following error

ERROR: compile failed while processing /host/deps/katja: {'EXIT',
    {{badmatch,
         {error,[],
             [{"src/katja_pb.erl",
               [{244,erl_lint,{exported_var,'FNum',{'case',226}}}]}]}},
     [{protobuffs_compile,output,4,
          [{file,"src/protobuffs_compile.erl"},{line,147}]},
      {rebar_protobuffs_compiler,compile_each,2,
          [{file,"src/rebar_protobuffs_compiler.erl"},{line,120}]},
      {rebar_core,run_modules,4,[{file,"src/rebar_core.erl"},{line,437}]},
      {rebar_core,execute,5,[{file,"src/rebar_core.erl"},{line,363}]},
      {rebar_core,process_dir1,6,[{file,"src/rebar_core.erl"},{line,227}]},
      {rebar_core,process_commands,2,[{file,"src/rebar_core.erl"},{line,90}]},
      {rebar,main,1,[{file,"src/rebar.erl"},{line,58}]},
      {escript,run,2,[{file,"escript.erl"},{line,757}]}]}}

Will look into this more if I do more on the project that depends on this (I'm just diving in for a UI fix this moment) - but for anybody else wandering by, this issue will probably help.

failed to send integer value

Hi
I am trying to send attribute list which has key value pair and value as integer but it is failing.

Working
katja:send_event_async([{service, "warehouse"}, {attribute, [{"war", "5"}]}]).

failing
katja:send_event_async([{service, "warehouse"}, {attribute, [{"war", 5}]}]).

[error] gen_server katja_writer terminated with reason: no function clause matching katja_writer:terminate({badarg,[{protobuffs,encode_internal,[2,5,string],[{file,"src/protobuffs.erl"},{line,167}]},{katja_pb,...},...]}, {connection_state,#Port<0.16909>,undefined,"192.168.3.45",5555,tcp}) line 169
11:54:55.196 [error] CRASH REPORT Process katja_writer with 0 neighbours exited with reason: no function clause matching katja_writer:terminate({badarg,[{protobuffs,encode_internal,[2,5,string],[{file,"src/protobuffs.erl"},{line,167}]},{katja_pb,...},...]}, {connection_state,#Port<0.16909>,undefined,"192.168.3.45",5555,tcp}) line 169 in gen_server:terminate/7 line 814
11:54:55.197 [error] Supervisor katja_sup had child undefined started with katja_writer:start_link(register) at <0.1533.0> exit with reason no function clause matching katja_writer:terminate({badarg,[{protobuffs,encode_internal,[2,5,string],[{file,"src/protobuffs.erl"},{line,167}]},{katja_pb,...},...]}, {connection_state,#Port<0.16909>,undefined,"192.168.3.45",5555,tcp}) line 169 in context child_terminated

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.