code: public static Counter getCounter(TaskInputOutputContext context,
                                     String groupName, String counterName) {
      return (Counter) invoke(GET_COUNTER_METHOD, context, groupName, counterName);
    }
docs: Invoke getCounter() on TaskInputOutputContext. Works with both
  Hadoop 1 and 2.