CMAK icon indicating copy to clipboard operation
CMAK copied to clipboard

how to do you call the kafka manager api to get topic summary

Open vigneshsenapathy opened this issue 9 years ago • 12 comments

I have been trying to call the api and get a summary for a topic but i get it in the form of HTML file instead of a json or anything. Is there anyway I can call the api to get like offsets

vigneshsenapathy avatar Feb 16 '17 21:02 vigneshsenapathy

Here are the API routes:

GET /api/status/:c/brokers controllers.api.KafkaStateCheck.brokers(c:String) GET /api/status/:c/topics controllers.api.KafkaStateCheck.topics(c:String) GET /api/status/:c/topicIdentities controllers.api.KafkaStateCheck.topicIdentities(c:String) GET /api/status/clusters controllers.api.KafkaStateCheck.clusters GET /api/status/:c/:t/underReplicatedPartitions controllers.api.KafkaStateCheck.underReplicatedPartitions(c:String,t:String) GET /api/status/:c/:t/unavailablePartitions controllers.api.KafkaStateCheck.unavailablePartitions(c:String,t:String) GET /api/status/:cluster/:consumer/:topic/topicSummary controllers.api.KafkaStateCheck.topicSummaryAction(cluster:String, consumer:String, topic:String, consumerType:String) GET /api/status/:cluster/:consumer/groupSummary controllers.api.KafkaStateCheck.groupSummaryAction(cluster:String, consumer:String, consumerType:String) GET /api/status/:cluster/consumersSummary controllers.api.KafkaStateCheck.consumersSummaryAction(cluster:String)

patelh avatar Feb 23 '17 06:02 patelh

So i hit the endpoint but i get like a html page back. Is there any where i can get it in like json format with no html tags and all

vigneshsenapathy avatar Feb 23 '17 14:02 vigneshsenapathy

Show me what you are doing. Provide some debug information. Maybe try it with curl and show me the results.

patelh avatar Feb 23 '17 20:02 patelh

self write Controller:

  def getTopicDetail(clustername:String, topic:String) = Action.async { request =>
    val futureErrorOrTopicIdentity = kafkaManager.getTopicIdentity(clustername, topic)
    val futureErrorOrConsumerList = kafkaManager.getConsumersForTopic(clustername, topic)

    futureErrorOrTopicIdentity.zip(futureErrorOrConsumerList).map {
      case (errorOrTopicIdentity, errorOrConsumerList) =>
        var result:String = ""
        var errorMsg:String = ""
        
        var topicInfo:TopicIdentity = null
        var consumers:ConsumerListExtended = null
        errorOrTopicIdentity match {
          case -\/(e) => errorMsg = e.msg 
          case \/-(t) => topicInfo = t
        }

        if (errorMsg != "") {
          result = "{\"errcode\":\"Failed\",\"errmsg\":\"" + errorMsg + "\"}"
        } else {
          result = "{\"errcode\":\"OK\",\"errmsg\":\"\", \"result\":{"
          result += "\"replications\":" + topicInfo.replicationFactor + ","
          result += "\"partitons\":" + topicInfo.partitions + ","
          result += "\"sum_offset\":" + topicInfo.summedTopicOffsets + ","
          result += "\"brokers\": ["

          for (i <- 0 until topicInfo.partitionsByBroker.size) {
            if (i != 0) {
              result += ","
            }

            result += "{"
            result += "\"id\":" + topicInfo.partitionsByBroker(i).id + ","

            result += "\"partitions\":\"" 
            for (j <- 0 until topicInfo.partitionsByBroker(i).partitions.size) {
              if (j != 0) {
                result += ","
              }
              result += topicInfo.partitionsByBroker(i).partitions(j)
            }
            result += "\""
            
            result += "}"
          }
          result += "],"

          var k = 0
          result += "\"consumer_groups\":{"
          errorOrConsumerList.foreach (consumerList =>
              for ((c:String, ct: ConsumerType) <- consumerList) {
                if (k != 0) {
                  result += ","
                }
                k += 1
                result += "\"" + c + "\":" + "\"" + ct + "\""
              })
          result += "}"

          result += "}"
          result += "}"
        }

        Ok(result)
    }
  }

DavidLiuXh avatar Feb 28 '17 01:02 DavidLiuXh

@patelh : below is the command i am running

curl -H "Content-type: application/json" -H "Accept: application/json" "http://abc.xyz.com:8080/api/status/vv/consumersSummary/sfs/ZK/topicSummary" (i have change the host and other things)

   <p id="detail">
        For request 'GET /api/status/vv/consumersSummary/sfs/ZK/topicSummary'
    </p>

can u give me an example of how to get topic summary and what parameters i need to pass. as I am not able to get it to work

vigneshsenapathy avatar Feb 28 '17 02:02 vigneshsenapathy

@patelh : i am trying to get topic summary using GET /api/status/:cluster/:consumer/:topic/topicSummary controllers.api.KafkaStateCheck.topicSummaryAction(cluster:String, consumer:String, topic:String, consumerType:String)

vigneshsenapathy avatar Feb 28 '17 02:02 vigneshsenapathy

How to call this API thru browser or curl? This is not showing any data:

curl -H "Content-type: application/json" -H "Accept: application/json" "http://xxx:8088/api/status/KafkaCluster/test_consumer/test_topic/consumer_type/topicSummary"

Browser returns Action not found response..

but this one is showing the data: http://xxx:8088/api/status/KafkaCluster/consumersSummary

I have kafka-manager-1.3.3-3.1..

sairamvla avatar Jun 15 '17 23:06 sairamvla

I have the same issue with the latest master (currently commit de5a2fad6c3cb28fa37e79eab1def2609a8c4fff)

curl http://mykafkamanager/api/status/mycluster/myconsumergroup/mytopic/ZK/topicSummary returns

...
 <body>
        <h1>Action not found</h1>

        <p id="detail">
            For request 'GET /api/status/mykafkamanager/myconsumergroup/mytopic/ZK/topicSummary'
        </p>

    </body>
...

While curl http://mykafkamanager/api/status/mycluster/consumersSummary yields a json response containing an entry for myconsumergroup

...
{
    "name" : "myconsumergroup",
    "type" : "ZK",
    "topics" : [ "mytopic" ]
  }
...

aheitzmann avatar Aug 17 '17 20:08 aheitzmann

http://kafkamanager/api/status/cluster/consumer_id/topic/topicSummary?consumerType=consumerType

sairamvla avatar Aug 17 '17 20:08 sairamvla

That works @sairamvla - Thank you!

For my edification, how does the defined route in conf/routes work with that URI - i.e. what makes consumerType a query param while the others are path params? GET /api/status/:cluster/:consumer/:topic/:consumerType/topicSummary controllers.api.KafkaStateCheck.topicSummaryAction(cluster:String, consumer:String, topic:String, consumerType:String) (https://github.com/yahoo/kafka-manager/blob/master/conf/routes)

aheitzmann avatar Aug 17 '17 21:08 aheitzmann

The same issue for me when I check km health via: curl -s http://127.0.0.1:9000/api/health return as follow told that Action not found:

...
    <body>
        <h1>Action not found</h1>

        <p id="detail">
            For request 'GET /api/health'
        </p>

    </body>
...

kelein avatar May 24 '18 07:05 kelein

How can I information on who has logged on to the Kafka Manager Ui? We need to track the people who are using the kafka manager ui What we need to turn to accomplish this?

sxganapa avatar Dec 08 '20 23:12 sxganapa