Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

113 lines (97 sloc) 3.881 kb
%% -------------------------------------------------------------------
%%
%% riaknostic - automated diagnostic tools for Riak
%%
%% Copyright (c) 2011 Basho Technologies, Inc. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------
%% @doc Diagnostic that checks the sysctl settings and offers conservative
%% recommendations
-module(riaknostic_check_sysctl).
-behaviour(riaknostic_check).
-export([description/0,
valid/0,
check/0,
format/1]).
-define(LINUX_PARAMS, [
{"vm.swappiness", 0, gte},
{"net.core.wmem_default", 8388608, lte},
{"net.core.rmem_default", 8388608, lte},
{"net.core.wmem_max", 8388608, lte},
{"net.core.rmem_max", 8388608, lte},
{"net.core.netdev_max_backlog", 10000, lte},
{"net.core.somaxconn", 4000, lte},
{"net.ipv4.tcp_max_syn_backlog", 40000, lte},
{"net.ipv4.tcp_fin_timeout", 15, gte},
{"net.ipv4.tcp_tw_reuse", 1, eq}
]).
-define(OPENBSD_PARAMS, [
{"kern.somaxconn", 4000, lte}
]).
-spec description() -> string().
description() ->
"Check sysctl tuning parameters".
-spec valid() -> boolean().
valid() ->
riaknostic_node:can_connect().
-spec check() -> [{lager:log_level(), term()}].
check() ->
Params = case os:type() of
{unix, linux} -> ?LINUX_PARAMS;
{unix, openbsd} -> ?OPENBSD_PARAMS;
{unix, darwin} -> [];
{unix, freebsd} -> [];
{unix, sunos} -> [];
_ -> []
end,
Recs = check_params(Params),
Recs.
check_params(List) ->
check_params(List, []).
check_params([], Acc) ->
Acc;
check_params([H|T], Acc) ->
{Param, Val, Direction } = H,
Output = riaknostic_util:run_command("sysctl -n " ++ Param),
Actual = list_to_integer(Output -- "\n"),
Good = case Direction of
gte -> Actual =< Val;
lte -> Actual >= Val;
eq -> Actual == Val
end,
Note = case Good of
true -> {info, {good, Param, Actual, Val, Direction}};
false -> {critical, {bad, Param, Actual, Val, Direction}}
end,
check_params(T, Acc ++ [Note]).
-spec format(term()) -> {io:format(), [term()]}.
format({good, Param, Actual, Val, Direction}) ->
{"~s is ~p ~s ~p", [Param, Actual, direction_to_word(Direction), Val]};
format({bad, Param, Actual, Val, Direction}) ->
{"~s is ~p, should be ~s~p", [Param, Actual, direction_to_word2(Direction), Val]}.
direction_to_word(Direction) ->
case Direction of
gte -> "greater than or equal to";
lte -> "lesser than or equal to";
eq -> "equal to"
end.
direction_to_word2(Direction) ->
case Direction of
gte -> "no more than ";
lte -> "at least ";
eq -> ""
end.
Jump to Line
Something went wrong with that request. Please try again.