bindings/erlang: Added copyright and license header.
[collectd.git] / bindings / erlang / cexample.erl
1 % collectd - bindings/erlang/cexample.erl
2 % Copyright (C) 2009  Florian octo Forster
3
4 % This program is free software; you can redistribute it and/or modify it
5 % under the terms of the GNU General Public License as published by the
6 % Free Software Foundation; only version 2 of the License is applicable.
7
8 % This program is distributed in the hope that it will be useful, but
9 % WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 % General Public License for more details.
12
13 % You should have received a copy of the GNU General Public License along
14 % with this program; if not, write to the Free Software Foundation, Inc.,
15 % 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
16
17 % Authors:
18 %   Florian octo Forster <octo at verplant.org>
19
20 -module(cexample).
21 -export([my_init/0]).
22
23 -include("collectd.hrl").
24
25 dispatch_reductions ({Total, _}) ->
26         collectd:dispatch_values (#value_list{host="localhost", plugin="erlang",
27                         type="counter", type_instance="reductions",
28                         values=[Total]}).
29
30 dispatch_memory ({Type, Size}) ->
31         collectd:dispatch_values (#value_list{host="localhost", plugin="erlang",
32                         type="memory", type_instance=atom_to_list (Type),
33                         values=[Size]}).
34
35 my_read() ->
36         dispatch_reductions (statistics (reductions)),
37         lists:foreach (fun dispatch_memory/1, erlang:memory()),
38         success.
39
40 my_init() ->
41         collectd:register_read (fun my_read/0).