title: Test Azure IotHub metrics collector in the simulator iot edge device
body: <h2>Problem</h2>
  <p>Azure IotHub metrics collector for Iot edge devices a very interesting feature that I am trying to implement and especially the option 2 that goes through IotMessage, so publishing a Device to Cloud message with the metrics data. So, I read the official documentation about the subject, and I got stuck at the very beginning in the architecture.</p>
  <h2>Context</h2>
  <p>In an existing IotHub, I already have some edge modules, so I added the <code>metrics-collector</code> module, and set up the routing as suggested in the documentation. The module starts correctly but can't fetch logs from <code>edgeHub</code> nor from <code>edgeAgent</code> (which is normal because <code>edgehubdev</code> doesn't start an <code>edgeAgent</code> module). Also, when exposing the 9600 port to a local port I was able to retrieve the metrics in my host machine in the localhost:9600/metrics endpoint, so I though I could set it up in the <code>MetricsEndpointsCSV</code> property but that doesn't help.</p>
  <h2>Question</h2>
  <p>How do you guys manage to test and end-to-end metrics retrieval through the simular (locally) ?
  PS: I know that there are still some missing architecture blocks that I need to create ( event hub + function apps ), but the metrics messages are not yet arriving to iot hub.</p>
  <h2>logs from edgeHubDev</h2>
  <pre><code>metricsCollector       | [2021-11-08 14:47:03.044 INF] Starting periodic operation Scrape and Upload Metrics...
  metricsCollector       | [2021-11-08 14:47:03.045 INF] Scraping endpoint http://127.0.0.1:9600/metrics
  metricsCollector       | [2021-11-08 14:47:03.046 ERR] Error scraping endpoint http://127.0.0.1:9600/metrics - System.Net.Http.HttpRequestException: Connection refused
  metricsCollector       |  ---&gt; System.Net.Sockets.SocketException (111): Connection refused
  metricsCollector       |    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
  metricsCollector       |    --- End of inner exception stack trace ---
  metricsCollector       |    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
  metricsCollector       |    at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
  metricsCollector       |    at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  metricsCollector       |    at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  metricsCollector       |    at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
  metricsCollector       |    at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
  metricsCollector       |    at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
  metricsCollector       |    at Microsoft.Azure.Devices.Edge.Azure.Monitor.MetricsScraper.ScrapeEndpoint(String endpoint, CancellationToken cancellationToken) in /mnt/vss/_work/1/s/edge-modules/azure-monitor/src/MetricsScraper.cs:line 72
  </code></pre>
  <p><strong>EDIT
  Fun Fact: It works in azure not in my machine =D</strong></p>
  <h2>References</h2>
  <p>Documentation: <a href="https://docs.microsoft.com/en-gb/azure/iot-edge/how-to-collect-and-transport-metrics?view=iotedge-2020-11&amp;tabs=iothub#next-steps" rel="nofollow noreferrer">https://docs.microsoft.com/en-gb/azure/iot-edge/how-to-collect-and-transport-metrics?view=iotedge-2020-11&amp;tabs=iothub#next-steps</a></p>
  <p>Azure sample: <a href="https://github.com/Azure-Samples/iotedge-logging-and-monitoring-solution" rel="nofollow noreferrer">https://github.com/Azure-Samples/iotedge-logging-and-monitoring-solution</a></p>