<commit_before>%% -------------------------------------------------------------------
%%
%% Copyright (c) 2013 Basho Technologies, Inc.  All Rights Reserved.
%%
%%   This Source Code Form is subject to the terms of the Mozilla Public
%%   License, v. 2.0. If a copy of the MPL was not distributed with this
%%   file, You can obtain one at http://mozilla.org/MPL/2.0/.
%%
%% -------------------------------------------------------------------

%% @todo Add wildcards.
%% @doc Custom reporting probe for riak
%%
%% The riak reporter implements a custom, ascii line based 
%% protocol to manage subscriptions and report metrics.
%%
%% For security and performance reasons, the protocol runs over unix
%% sockets.  The protocol is divided into two different parts.  The
%% riak reporter server accepts incoming calls on a configurable, well
%% known unix socket, where metrics collectors who wants metric data
%% can connect and manage their subscriptions.
%%
%% When a subscription is setup by a metrics collector, the collector
%% will specify a reporting (unix) socket that the subscribed-to
%% metric should be delivered to. The riak reporter will, at given
%% intervals, deliver the updated metrics to the socket and its
%% collector. Subscriptions for several different metrics can be
%% reported to the same socket by having several suscription commands
%% refer to the same unix socket file path.
%% 
%% The riak reporter will setup a client connection to a metrics
%% collector when the first subscription referring to it is
%% received. The connection to the collector will be terminated when
%% the last subscription referring to it is cancelled with an
%% unsubscribed command.
%%
%% == Protocol Characteristics ==
%%
%% + Line Based<br/>Each command in the protocol is transmitted as a
%%        newline-terminated ($10) line.
%%
%% + Field Based<br/>Each command line in the protocol is separated into
%%        space-separated fields.
%% 
%% + Escape Characters<br/>A newline can be a part of a field payload
%%        if it is escaped with a backslash (`\n').<br/>A space can be
%%        a part of a field payload if it is escaped with a backslash
%%        (`\ ').<br/>A backslash can be a part of a field payload if
%%        it is escaped with a backslash (`\\').
%%
%% -= Riak Reporter Server Protocol -=
%% The server protocol is used to list, subscribe to, and unsubscribe from
%% metrics and data points.
%% The following commands are supported.
%%
%% === subscribe ===
%%
%% The subscribe command sets up the periodic delivery of the given
%% metric and data point to a unix unix socket and its serving metrics
%% collector. The delivery will continue until either the server
%% listening to `[socket]' shuts down, or a corresponding
%% `unsubscribe' command is received.
%%
%% If this is the first `subscribe' call that refers to `[socket]',
%% the riak reporter will setup a client connection to it that will
%% remain up until either the socket server shuts down, or 
%% the last metric referring to `[socket]' is unsubscribed from
%% through an `unsubscribe' command.
%%
%% The same metric / data point pair can be subscribed to multiple times
%% with different `[socket]' paths.
%%
%% ==== Request Format ====
%% <pre>subscribe [hostid] [metric]/[datapoint] [interval] [socket]</pre>
%%
%%+ `[hostid]'<br/> Specifies the hostid that should be used when reporting this metric
%%    This allows for multiple riak reporters to send metric data to
%%    to a single server, thus allowing the server to distinguish between
%%    different reporters through their individual host ids.
%%
%%+ `[metric]'<br/>Identifies the metric that is to be sampled and delivered.
%%    Each element in the atom list is separated by a slash (`/').
%%    Thus `[db, cache, hits]' is identified as 'db/cache/hits'.
%% 
%%+ `[datapoint]'<br/>Identifies the data point within the metric 
%%    that is to be sampled and delivered.
%%
%%+ `[interval]'<br/>Specifies the interval, in milliseconds, that should
%%    elapse between each metric/data point delivery.
%%   
%% + `[socket]'<br/>Specifies the unix socket file path that
%%    the given metric/data point should be delivered to.
%%
%% ==== Reply Format ====
%% 
%% Each subscibe command will trigger a one line reply being sent
%% back to the client.
%%
%% <pre>[result] [text]</pre>
%%
%% + `[result]'<br/>Result code integer. See below for details.
%%
%% + `[text]'<br/>Descriptive text.
%%
%%
%% The possible `[result]' codes are as follows:
%%
%% + `0' - Success<br/>The subscription has been setup successfully.
%%
%% + `1' - Syntax error<br/>The format of the command was not recognized.
%%
%% + `2' - No such metric<br/>`[metric]' could not be found among the metrics in the
%%   exometer system.
%%
%% + `3' - No such data point<br/>`[data point]' could not be found among the metrics in the
%%   exometer system.
%%
%% + `4' - Invalid socket<br/>`[socket]' could not be accessed or connected to.
%%
%% === unsubscribe ===
%%
%% The unsubscribe command cancels the periodic delivery of the given
%% metric and data point to a metrics collector over a unix
%% socket. The metric / data point has previously been setup with a
%% `subscribe' command.
%%
%% If the given metric / data point is the last pair that refers to
%% the socket file path provided to a `subscribe' command, the riak
%% reporter will disconnect a client connection for that socket.
%%
%% ==== Request Format ====
%%
%% <pre>unsubscribe [metric]/[datapoint]</pre>
%%
%%
%% + `[metric]'<br/>Identifies the metric that is to be unsubscribed from.
%%    The given metric must have been provided to a previous `subscribe' 
%%    command.
%% 
%% + `[datapoint]'<br/>Identifies the datapoint that is to be unsubscribed from.
%%    The given data point must have been provided to a previous `subscribe' 
%%    command.
%%
%% ==== Reply Format ====
%% 
%% Each subscibe command will trigger a one line reply being sent
%% back to the client.
%%
%% <pre>[result] [text]</pre>
%%
%% + `[result]'<br/>Result code integer. See below for details.
%%
%% + `[text]'<br/>Descriptive text.
%%
%% The possible `[result]' codes are as follows:
%%
%% + `0' - Success<br/>The subscription has been cancelled.
%%
%% + `1' - Syntax error<br/>The format of the command was not recognized.
%%
%% + `2' - No such metric <br/>`[metric]' could not be found among the subscribed-to
%%   metrics in the exometer system.
%%
%% + `3' - No such data point<br/>`[data point]' could not be found among the subscribed-to
%%   data points in the exometer system.
%% 
%% === list ===
%%
%% The list command will return a list of metrics and data points
%% available for subscription.
%%
%% ==== Request Format ====
%% <pre>list [metric]</pre>
%%
%% + `[metric]'<br/>Identifies the metric that is to be listed. If the metric
%%    only specifies the beginning of a path, all metrics whose 
%%    path prefix-matches `[metric]' will be listed.
%%
%% ==== Reply Format ====
%% 
%% Each list command will trigger a reply of one or more lines
%% being sent back to the client.
%%
%% <pre>[metric1] [datapoint1] [datapoint2] ...
%%      [metric2] [datapoint1] [datapoint2] ...
%%      ...
%%      [metricN] [datapoint1] [datapoint2] ...
%%      (empty newline)</pre>
%%
%% If there are no matching metrics, the reply will consist of
%% a single empty newline.
%%
%% Each line describes a matching metric and its data points.
%%
%% + `[metricN]'<br/>The name of the metric, in the `x/y/z' format.
%%
%% + `[datapointN]'<br/>One or more data points supported by the given metric.
%%
%% A combined metric and a supported data point can be sent as arguments
%% to a `subscribe' command.
%%
%% = Riak Reporter Client Protocol = This protocol is used by the riak
%% reporter to deliver metrics data to a metrics collector thorugh
%% unix sockets specified by a `subscribe' command sent to the
%% reporter using the {@section Riak Reporter Server Protocol}.
%%
%% The riak reporter will establish a client connection to a socket,
%% and its collector, the first time the socket file path is
%% referenced by a subscribe command. The connection will be
%% disconnected when the last metrics referencing the socket file path
%% is unsubscribed from by the metrics collector.
%% 
%% The socket will also be disconnected from, and all its referencing
%% subscriptions will be cancelled, if the metrics collector closes
%% the socket on its end.
%%
%% <b>Please note</b> Data is only transmitted from the riak reporter to the
%%       metrics collector. No replies or other information are sent
%%       from the collector to the riak reporter.
%%
%% === report ===
%%
%% The report command sends a single metric / data point value
%% to a metrics collector. The 
%%
%% ==== Request Format ====
%% <pre>report [hostid] [timestamp] [metric]/[datapoint] [value]</pre>
%%
%% @todo Add wildcards.
%% + `[hostid]'<br/>Specifies the host id provided to the `subscription' command
%%    that generated this report.
%%
%% + `[timestamp]'<br/>Specifies the time stamp, in milliseconds since 1970-01-01 00:00:00.000
%% 
%% + `[metric]'<br/>The name of the metric reported, in the `x/y/z' format.
%%
%% + `[datapoint]'<br/>The data point under the given metric reported..
%%
%% + `[value]'<br/>The value of the metric / data point.
%%
%% ==== Reply Format ====
%% 
%% No reply is sent in response to a `report' command.
%% @end

-module(exometer_report_riak).<commit_msg>Let formatting hell commence<commit_after>%% -------------------------------------------------------------------
%%
%% Copyright (c) 2013 <NAME>, Inc.  All Rights Reserved.
%%
%%   This Source Code Form is subject to the terms of the Mozilla Public
%%   License, v. 2.0. If a copy of the MPL was not distributed with this
%%   file, You can obtain one at http://mozilla.org/MPL/2.0/.
%%
%% -------------------------------------------------------------------

%% @doc Custom reporting probe for riak
%%
%% <b>TODO: Add wildcards</b>
%% The riak reporter implements a custom, ascii line based 
%% protocol to manage subscriptions and report metrics.
%%
%% For security and performance reasons, the protocol runs over unix
%% sockets.  The protocol is divided into two different parts.  The
%% riak reporter server accepts incoming calls on a configurable, well
%% known unix socket, where metrics collectors who wants metric data
%% can connect and manage their subscriptions.
%%
%% When a subscription is setup by a metrics collector, the collector
%% will specify a reporting (unix) socket that the subscribed-to
%% metric should be delivered to. The riak reporter will, at given
%% intervals, deliver the updated metrics to the socket and its
%% collector. Subscriptions for several different metrics can be
%% reported to the same socket by having several suscription commands
%% refer to the same unix socket file path.
%% 
%% The riak reporter will setup a client connection to a metrics
%% collector when the first subscription referring to it is
%% received. The connection to the collector will be terminated when
%% the last subscription referring to it is cancelled with an
%% unsubscribed command.
%%
%% == Protocol Characteristics ==
%%
%% + Line Based<br/>Each command in the protocol is transmitted as a
%%        newline-terminated ($10) line.
%%
%% + Field Based<br/>Each command line in the protocol is separated into
%%        space-separated fields.
%% 
%% + Escape Characters<br/>A newline can be a part of a field payload
%%        if it is escaped with a backslash (`\n').<br/>A space can be
%%        a part of a field payload if it is escaped with a backslash
%%        (`\ ').<br/>A backslash can be a part of a field payload if
%%        it is escaped with a backslash (`\\').
%%
%% -= Riak Reporter Server Protocol -=
%% The server protocol is used to list, subscribe to, and unsubscribe from
%% metrics and data points.
%% The following commands are supported.
%%
%% === subscribe ===
%%
%% The subscribe command sets up the periodic delivery of the given
%% metric and data point to a unix unix socket and its serving metrics
%% collector. The delivery will continue until either the server
%% listening to `[socket]' shuts down, or a corresponding
%% `unsubscribe' command is received.
%%
%% If this is the first `subscribe' call that refers to `[socket]',
%% the riak reporter will setup a client connection to it that will
%% remain up until either the socket server shuts down, or 
%% the last metric referring to `[socket]' is unsubscribed from
%% through an `unsubscribe' command.
%%
%% The same metric / data point pair can be subscribed to multiple times
%% with different `[socket]' paths.
%%
%% ==== Request Format ====
%% <pre>subscribe [hostid] [metric]/[datapoint] [interval] [socket]</pre>
%%
%%+ `[hostid]'<br/> Specifies the hostid that should be used when reporting this metric
%%    This allows for multiple riak reporters to send metric data to
%%    to a single server, thus allowing the server to distinguish between
%%    different reporters through their individual host ids.
%%
%%+ `[metric]'<br/>Identifies the metric that is to be sampled and delivered.
%%    Each element in the atom list is separated by a slash (`/').
%%    Thus `[db, cache, hits]' is identified as 'db/cache/hits'.
%% 
%%+ `[datapoint]'<br/>Identifies the data point within the metric 
%%    that is to be sampled and delivered.
%%
%%+ `[interval]'<br/>Specifies the interval, in milliseconds, that should
%%    elapse between each metric/data point delivery.
%%   
%% + `[socket]'<br/>Specifies the unix socket file path that
%%    the given metric/data point should be delivered to.
%%
%% ==== Reply Format ====
%% 
%% Each subscibe command will trigger a one line reply being sent
%% back to the client.
%%
%% <pre>[result] [text]</pre>
%%
%% + `[result]'<br/>Result code integer. See below for details.
%%
%% + `[text]'<br/>Descriptive text.
%%
%%
%% The possible `[result]' codes are as follows:
%%
%% + `0' - Success<br/>The subscription has been setup successfully.
%%
%% + `1' - Syntax error<br/>The format of the command was not recognized.
%%
%% + `2' - No such metric<br/>`[metric]' could not be found among the metrics in the
%%   exometer system.
%%
%% + `3' - No such data point<br/>`[data point]' could not be found among the metrics in the
%%   exometer system.
%%
%% + `4' - Invalid socket<br/>`[socket]' could not be accessed or connected to.
%%
%% === unsubscribe ===
%%
%% The unsubscribe command cancels the periodic delivery of the given
%% metric and data point to a metrics collector over a unix
%% socket. The metric / data point has previously been setup with a
%% `subscribe' command.
%%
%% If the given metric / data point is the last pair that refers to
%% the socket file path provided to a `subscribe' command, the riak
%% reporter will disconnect a client connection for that socket.
%%
%% ==== Request Format ====
%%
%% <pre>unsubscribe [metric]/[datapoint]</pre>
%%
%%
%% + `[metric]'<br/>Identifies the metric that is to be unsubscribed from.
%%    The given metric must have been provided to a previous `subscribe' 
%%    command.
%% 
%% + `[datapoint]'<br/>Identifies the datapoint that is to be unsubscribed from.
%%    The given data point must have been provided to a previous `subscribe' 
%%    command.
%%
%% ==== Reply Format ====
%% 
%% Each subscibe command will trigger a one line reply being sent
%% back to the client.
%%
%% <pre>[result] [text]</pre>
%%
%% + `[result]'<br/>Result code integer. See below for details.
%%
%% + `[text]'<br/>Descriptive text.
%%
%% The possible `[result]' codes are as follows:
%%
%% + `0' - Success<br/>The subscription has been cancelled.
%%
%% + `1' - Syntax error<br/>The format of the command was not recognized.
%%
%% + `2' - No such metric <br/>`[metric]' could not be found among the subscribed-to
%%   metrics in the exometer system.
%%
%% + `3' - No such data point<br/>`[data point]' could not be found among the subscribed-to
%%   data points in the exometer system.
%% 
%% === list ===
%%
%% The list command will return a list of metrics and data points
%% available for subscription.
%%
%% ==== Request Format ====
%% <pre>list [metric]</pre>
%%
%% + `[metric]'<br/>Identifies the metric that is to be listed. If the metric
%%    only specifies the beginning of a path, all metrics whose 
%%    path prefix matches `[metric]' will be listed.
%%
%% ==== Reply Format ====
%% 
%% Each list command will trigger a reply of one or more lines
%% being sent back to the client.
%%
%% <pre>[metric1] [datapoint1] [datapoint2] ...
%%      [metric2] [datapoint1] [datapoint2] ...
%%      ...
%%      [metricN] [datapoint1] [datapoint2] ...
%%      (empty newline)</pre>
%%
%% If there are no matching metrics, the reply will consist of
%% a single empty newline.
%%
%% Each line describes a matching metric and its data points.
%%
%% + `[metricN]'<br/>The name of the metric, in the `x/y/z' format.
%%
%% + `[datapointN]'<br/>One or more data points supported by the given metric.
%%
%% A combined metric and a supported data point can be sent as arguments
%% to a `subscribe' command.
%%
%% = Riak Reporter Client Protocol = This protocol is used by the riak
%% reporter to deliver metrics data to a metrics collector thorugh
%% unix sockets specified by a `subscribe' command sent to the
%% reporter using the {@section Riak Reporter Server Protocol}.
%%
%% The riak reporter will establish a client connection to a socket,
%% and its collector, the first time the socket file path is
%% referenced by a subscribe command. The connection will be
%% disconnected when the last metrics referencing the socket file path
%% is unsubscribed from by the metrics collector.
%% 
%% The socket will also be disconnected from, and all its referencing
%% subscriptions will be cancelled, if the metrics collector closes
%% the socket on its end.
%%
%% <b>Please note</b> Data is only transmitted from the riak reporter to the
%%       metrics collector. No replies or other information are sent
%%       from the collector to the riak reporter.
%%
%% === report ===
%%
%% The report command sends a single metric / data point value
%% to a metrics collector. The 
%%
%% ==== Request Format ====
%% <pre>report [hostid] [timestamp] [metric]/[datapoint] [value]</pre>
%%
%% + `[hostid]'<br/>Specifies the host id provided to the `subscription' command
%%    that generated this report.
%%
%% + `[timestamp]'<br/>Specifies the time stamp, in milliseconds since 1970-01-01 00:00:00.000
%% 
%% + `[metric]'<br/>The name of the metric reported, in the `x/y/z' format.
%%
%% + `[datapoint]'<br/>The data point under the given metric reported..
%%
%% + `[value]'<br/>The value of the metric / data point.
%%
%% ==== Reply Format ====
%% 
%% No reply is sent in response to a `report' command.
%% @end

-module(exometer_report_riak).
{'fraction_non_alphanumeric': 0.14072189537287327, 'fraction_numerical': 0.004664228547198813, 'mean_word_length': 3.6842105263157894, 'pattern_counts': {'":': 0, '<': 104, '<?xml version=': 0, '>': 104, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3802318', 'n_tokens_mistral': 5363, 'n_tokens_neox': 5133, 'n_words': 2433}