Last active
October 21, 2015 22:46
-
-
Save irvingpop/679e9ce3eaeda2602f6b to your computer and use it in GitHub Desktop.
Chef server metrics with escript!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/opscode/embedded/bin/escript | |
-define(SELF, '[email protected]'). | |
-define(BIFROST, '[email protected]'). | |
-define(BIFROST_COOKIE, 'oc_bifrost'). | |
-define(ERCHEF, '[email protected]'). | |
-define(ERCHEF_COOKIE, 'erchef'). | |
get_waiting(Node, Cookie) -> | |
erlang:set_cookie(node(), Cookie), | |
case net_adm:ping(Node) of | |
pong -> | |
rpc:call(Node, mochiweb_socket_server, get, [webmachine_mochiweb, waiting_acceptors]); | |
Error -> | |
io:format("Cannot connect to ~p: ~p", [Node, Error]), | |
Error | |
end. | |
get_active(Node, Cookie) -> | |
erlang:set_cookie(node(), Cookie), | |
case net_adm:ping(Node) of | |
pong -> | |
rpc:call(Node, mochiweb_socket_server, get, [webmachine_mochiweb, active_sockets]); | |
Error -> | |
io:format("Cannot connect to ~p: ~p", [Node, Error]), | |
Error | |
end. | |
get_folsom(Node, Cookie, Metric) -> | |
erlang:set_cookie(node(), Cookie), | |
case net_adm:ping(Node) of | |
pong -> | |
lists:last(rpc:call(Node, folsom_metrics, get_metric_value, [Metric])); | |
Error -> | |
io:format("Cannot connect to ~p: ~p", [Node, Error]), | |
Error | |
end. | |
get_stats() -> | |
ErchefWaitingCount = get_waiting(?ERCHEF, ?ERCHEF_COOKIE), | |
BifrostWaitingCount = get_waiting(?BIFROST, ?BIFROST_COOKIE), | |
ErchefActiveCount = get_active(?ERCHEF, ?ERCHEF_COOKIE), | |
BifrostActiveCount = get_active(?BIFROST, ?BIFROST_COOKIE), | |
ErchefDbPoolInUse = get_folsom(?ERCHEF, ?ERCHEF_COOKIE, <<"pooler.sqerl.in_use_count">>), | |
ErchefDbPoolFree = get_folsom(?ERCHEF, ?ERCHEF_COOKIE, <<"pooler.sqerl.free_count">>), | |
ErchefDepsolverPoolInUse = get_folsom(?ERCHEF, ?ERCHEF_COOKIE, <<"pooler.chef_depsolver.in_use_count">>), | |
ErchefDepsolverPoolFree = get_folsom(?ERCHEF, ?ERCHEF_COOKIE, <<"pooler.chef_depsolver.free_count">>), | |
ErchefAuthzPoolInUse = get_folsom(?ERCHEF, ?ERCHEF_COOKIE, <<"pooler.oc_chef_authz_http.in_use_count">>), | |
ErchefAuthzPoolFree = get_folsom(?ERCHEF, ?ERCHEF_COOKIE, <<"pooler.oc_chef_authz_http.free_count">>), | |
%% TODO: bifrost doesn't have folsom (yet) | |
%% BifrostDbPoolInUse = get_folsom(?BIFROST, ?BIFROST_COOKIE, <<"pooler.sqerl.in_use_count">>), | |
%% BifrostDbPoolFree = get_folsom(?BIFROST, ?BIFROST_COOKIE, <<"pooler.sqerl.free_count">>), | |
io:format("~p erchef: mochiweb_waiting_acceptors=~p, mochiweb_active_sockets=~p, dbpool_inuse=~p, dbpool_free=~p, authzpool_inuse=~p, authzpool_free=~p, depsolverpool_inuse=~p, depsolverpool_free=~p~n", | |
[calendar:now_to_local_time(now()), ErchefWaitingCount, ErchefActiveCount, ErchefDbPoolInUse, ErchefDbPoolFree, ErchefAuthzPoolInUse, ErchefAuthzPoolFree, ErchefDepsolverPoolInUse, ErchefDepsolverPoolFree]), | |
io:format("~p bifrost: mochiweb_waiting_acceptors=~p, mochiweb_active_sockets=~p~n", | |
[calendar:now_to_local_time(now()), BifrostWaitingCount, BifrostActiveCount]), | |
%% loop | |
timer:sleep(1000), | |
get_stats(). | |
main(_Args) -> | |
net_kernel:start([?SELF, longnames]), | |
get_stats(). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@ip-ub-frontend1:~# ./pooler.escript | |
{{2015,10,21},{22,38,34}} erchef: mochiweb_waiting_acceptors=16, mochiweb_active_sockets=0, dbpool_inuse=1, dbpool_free=29, authzpool_inuse=1, authzpool_free=99, depsolverpool_inuse=1, depsolverpool_free=4 | |
{{2015,10,21},{22,38,34}} bifrost: mochiweb_waiting_acceptors=16, mochiweb_active_sockets=7 | |
{{2015,10,21},{22,38,35}} erchef: mochiweb_waiting_acceptors=16, mochiweb_active_sockets=0, dbpool_inuse=1, dbpool_free=29, authzpool_inuse=1, authzpool_free=99, depsolverpool_inuse=1, depsolverpool_free=4 | |
{{2015,10,21},{22,38,35}} bifrost: mochiweb_waiting_acceptors=16, mochiweb_active_sockets=7 | |
{{2015,10,21},{22,38,36}} erchef: mochiweb_waiting_acceptors=16, mochiweb_active_sockets=0, dbpool_inuse=1, dbpool_free=29, authzpool_inuse=1, authzpool_free=99, depsolverpool_inuse=1, depsolverpool_free=4 | |
{{2015,10,21},{22,38,36}} bifrost: mochiweb_waiting_acceptors=16, mochiweb_active_sockets=7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment