Publishing an app service is nothing more than creating a microflow and exposing it through the app service interface.
To count the number of users create a Java action that does the following (input: none, output: Integer/Long):
To return all concurrent users (i.e. users currently logged in to the application)
// BEGIN USER CODE
return Core.getConcurrentUserCount(true);
// END USER CODE
To return all concurrent named users (i.e. named users (so excluding anonymous users) currently logged in to the application):
// BEGIN USER CODE
return Core.getConcurrentUserCount(false);
// END USER CODE
To return all named users (whether they are logged in or not, so basically a count of all System.User objects):
// BEGIN USER CODE
return Core.getNamedUserCount();
// END USER CODE