usage.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. .. _monitor_kafka_usage:
  2. Usage of Monitoring Kafka extension
  3. ==========================================
  4. To try out there is a ``docker-compose.yml`` file in the ``test/resources`` directory.
  5. This will start up a Kafka broker and a schema registry instance.
  6. To start it up you need docker and docker-compose installed then run::
  7. # start kafka
  8. cd src/community/monitor-kafka/src/test/resources
  9. docker-compose up -d
  10. This will start up the Kafka broker and the schema registry.
  11. Once Kafka is running start geoserver with monitor and monitor-kafka extension from ``src/web/app``::
  12. mvn jetty:run -P monitor,monitor-kafka
  13. This will initialize the data directory in ``src/web/app/src/main/webapp/data`` and start up geoserver.
  14. Stop the geoserver again.
  15. With this you will get the default monitor config installed automatically in ``src/web/app/src/main/webapp/data/monitoring/``. Edit it to use the Kafka storage.
  16. Then you need to configure the ``monitor-kafka`` extension for it with::
  17. storage=kafka
  18. kafka.bootstrap.servers=localhost:9092
  19. kafka.schema.registry.url=http://localhost:8081
  20. Create your topic with::
  21. docker exec -ti broker kafka-topics --bootstrap-server localhost:9092 --create --topic geoserver-monitor --partitions 1 --replication-factor 1 --if-not-exists
  22. Start geoserver again with::
  23. mvn jetty:run -P monitor,monitor-kafka
  24. Check that the monitoring extension is actually enabled by looking for the following log line::
  25. INFO [geoserver.monitor] - Kafka connection established and topic geoserver-monitor exists
  26. Head over to http://localhost:8080/geoserver and hit some map, so you get some data into the topic.
  27. If you want to consume the data you need a consumer which has the right Deserializer configured (``io.confluent.kafka.serializers.KafkaAvroDeserializer``).
  28. The easiest way to do this is to enter the schema registry container with::
  29. docker exec -ti schema-registry bash
  30. # from within the container run:
  31. kafka-avro-console-consumer \
  32. --bootstrap-server broker:29092 \
  33. --topic geoserver-monitor \
  34. --from-beginning
  35. # or directly from the host machine so you can pipe it into jq or a file...
  36. docker exec -ti schema-registry kafka-avro-console-consumer \
  37. --bootstrap-server broker:29092 \
  38. --topic geoserver-monitor \
  39. --from-beginning | tee >(grep -E "^{" | jq) | grep -vE "^{"
  40. Then you will see messages like this:
  41. .. code-block:: json
  42. {
  43. "id": 2,
  44. "status": "FINISHED",
  45. "category": "OWS",
  46. "path": "/tiger/wms",
  47. "queryString": "SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&STYLES&LAYERS=tiger:giant_polygon&exceptions=application/vnd.ogc.se_inimage&SRS=EPSG:4326&WIDTH=768&HEIGHT=384&BBOX=3.7958354296875,-40.4131489453125,71.2627583203125,-6.6962260546875",
  48. "body": "",
  49. "bodyContentLength": 0,
  50. "bodyContentType": "",
  51. "httpMethod": "GET",
  52. "startTime": 1697172148809,
  53. "endTime": 1697172148902,
  54. "totalTime": 93,
  55. "remoteAddress": "[0:0:0:0:0:0:0:1]",
  56. "remoteHost": "0:0:0:0:0:0:0:1",
  57. "host": "localhost",
  58. "internalHost": "client",
  59. "remoteUser": "anonymous",
  60. "remoteUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
  61. "remoteCountry": "",
  62. "remoteCity": "",
  63. "remoteLat": 0.0,
  64. "remoteLon": 0.0,
  65. "service": "WMS",
  66. "operation": "GetMap",
  67. "owsVersion": "1.1.1",
  68. "subOperation": "",
  69. "resources": [
  70. "tiger:giant_polygon"
  71. ],
  72. "responseLength": 6594,
  73. "responseContentType": "image/png",
  74. "errorMessage": "",
  75. "responseStatus": 0,
  76. "httpReferer": "",
  77. "coordinateReferenceSystem": "EPSG:WGS 84",
  78. "minx": 3.7958354296875,
  79. "miny": -40.4131489453125,
  80. "maxx": 71.2627583203125,
  81. "maxy": -6.6962260546875,
  82. "cacheResult": "",
  83. "missReason": "",
  84. "resourceProcessingTimes": [],
  85. "labelingProcessingTime": 0
  86. }
  87. {
  88. "id": 3,
  89. "status": "FINISHED",
  90. "category": "OWS",
  91. "path": "/tiger/wms",
  92. "queryString": "SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image/png&TRANSPARENT=true&QUERY_LAYERS=tiger:giant_polygon&STYLES&LAYERS=tiger:giant_polygon&exceptions=application/vnd.ogc.se_inimage&INFO_FORMAT=text/html&FEATURE_COUNT=50&X=50&Y=50&SRS=EPSG:4326&WIDTH=101&HEIGHT=101&BBOX=39.23891004908502,-32.22561743843973,48.11586317408502,-23.348664313439727",
  93. "body": "",
  94. "bodyContentLength": 0,
  95. "bodyContentType": "",
  96. "httpMethod": "GET",
  97. "startTime": 1697172178181,
  98. "endTime": 1697172178213,
  99. "totalTime": 32,
  100. "remoteAddress": "[0:0:0:0:0:0:0:1]",
  101. "remoteHost": "",
  102. "host": "localhost",
  103. "internalHost": "client",
  104. "remoteUser": "anonymous",
  105. "remoteUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
  106. "remoteCountry": "",
  107. "remoteCity": "",
  108. "remoteLat": 0.0,
  109. "remoteLon": 0.0,
  110. "service": "WMS",
  111. "operation": "GetFeatureInfo",
  112. "owsVersion": "1.1.1",
  113. "subOperation": "",
  114. "resources": [
  115. "giant_polygon"
  116. ],
  117. "responseLength": 803,
  118. "responseContentType": "text/html;charset=utf-8",
  119. "errorMessage": "",
  120. "responseStatus": 0,
  121. "httpReferer": "",
  122. "coordinateReferenceSystem": "EPSG:WGS 84",
  123. "minx": 43.63344129908502,
  124. "miny": -27.743195563439727,
  125. "maxx": 43.63344129908502,
  126. "maxy": -27.743195563439727,
  127. "cacheResult": "",
  128. "missReason": "",
  129. "resourceProcessingTimes": [],
  130. "labelingProcessingTime": 0
  131. }