/src/riak_core_cinfo_core.erl

https://github.com/iw/riak_core · Erlang · 78 lines · 38 code · 11 blank · 29 comment · 3 complexity · 9fa2fc3734d1cea148dc5da0be9e6f09 MD5 · raw file

  1. %% -------------------------------------------------------------------
  2. %%
  3. %% Riak: A lightweight, decentralized key-value store.
  4. %%
  5. %% Copyright (c) 2007-2010 Basho Technologies, Inc. All Rights Reserved.
  6. %%
  7. %% This file is provided to you under the Apache License,
  8. %% Version 2.0 (the "License"); you may not use this file
  9. %% except in compliance with the License. You may obtain
  10. %% a copy of the License at
  11. %%
  12. %% http://www.apache.org/licenses/LICENSE-2.0
  13. %%
  14. %% Unless required by applicable law or agreed to in writing,
  15. %% software distributed under the License is distributed on an
  16. %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. %% KIND, either express or implied. See the License for the
  18. %% specific language governing permissions and limitations
  19. %% under the License.
  20. %%
  21. %% -------------------------------------------------------------------
  22. -module(riak_core_cinfo_core).
  23. -export([cluster_info_init/0, cluster_info_generator_funs/0]).
  24. %% @spec () -> term()
  25. %% @doc Required callback function for cluster_info: initialization.
  26. %%
  27. %% This function doesn't have to do anything.
  28. cluster_info_init() ->
  29. ok.
  30. %% @spec () -> list({string(), fun()})
  31. %% @doc Required callback function for cluster_info: return list of
  32. %% {NameForReport, FunOfArity_1} tuples to generate ASCII/UTF-8
  33. %% formatted reports.
  34. cluster_info_generator_funs() ->
  35. [
  36. {"Riak Core config files", fun config_files/1},
  37. {"Riak Core vnode modules", fun vnode_modules/1},
  38. {"Riak Core ring", fun get_my_ring/1},
  39. {"Riak Core latest ring file", fun latest_ringfile/1},
  40. {"Riak Core active partitions", fun active_partitions/1}
  41. ].
  42. vnode_modules(CPid) -> % CPid is the data collector's pid.
  43. cluster_info:format(CPid, "~p\n", [riak_core:vnode_modules()]).
  44. get_my_ring(CPid) ->
  45. {ok, Ring} = riak_core_ring_manager:get_my_ring(),
  46. cluster_info:format(CPid, "~p\n", [Ring]).
  47. latest_ringfile(CPid) ->
  48. {ok, Path} = riak_core_ring_manager:find_latest_ringfile(),
  49. {ok, Contents} = file:read_file(Path),
  50. cluster_info:format(CPid, "Latest ringfile: ~s\n", [Path]),
  51. cluster_info:format(CPid, "File contents:\n~p\n", [binary_to_term(Contents)]).
  52. active_partitions(CPid) ->
  53. Pids = [Pid || {_,Pid,_,_} <- supervisor:which_children(riak_core_vnode_sup)],
  54. Vnodes = [riak_core_vnode:get_mod_index(Pid) || Pid <- Pids],
  55. Partitions = lists:foldl(fun({_,P}, Ps) ->
  56. ordsets:add_element(P, Ps)
  57. end, ordsets:new(), Vnodes),
  58. cluster_info:format(CPid, "~p\n", [Partitions]).
  59. config_files(C) ->
  60. {ok, [[AppPath]]} = init:get_argument(config),
  61. EtcDir = filename:dirname(AppPath),
  62. VmPath = filename:join(EtcDir, "vm.args"),
  63. [begin
  64. cluster_info:format(C, "File: ~s\n", [os:cmd("ls -l " ++ File)]),
  65. {ok, FileBin} = file:read_file(File),
  66. cluster_info:format(C, "File contents:\n~s\n", [FileBin])
  67. end || File <- [AppPath, VmPath]].