Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map json prop as labels #74

Open
v0l opened this issue Nov 11, 2021 · 3 comments
Open

Map json prop as labels #74

v0l opened this issue Nov 11, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@v0l
Copy link

v0l commented Nov 11, 2021

Hi,

It would be nice to be able to map some properties as labels to help identify devices which publish to a single topic.

I have a use case with rtl_433 which is collecting weather station data into a single topic at rtl_433/{hostname}/events

Here is an example json:

{
   "time":"2021-11-11 14:18:45",
   "model":"Fineoffset-WHx080",
   "subtype":0,
   "id":196,
   "battery_ok":1,
   "temperature_C":13.1,
   "humidity":90,
   "wind_dir_deg":135,
   "wind_avg_km_h":1.224,
   "wind_max_km_h":3.672,
   "rain_mm":58.5,
   "mic":"CRC"
}

It would be useful to be able to map id or model to labels to help identify the device event.

- prom_name: temperature
  mqtt_name: temperature_C
  type: gauge
  labels:
  - model
  - id
  - subtype
@hikhvar
Copy link
Owner

hikhvar commented Nov 11, 2021

I can relate to that use case. I welcome a PR adding this functionality. If I have enough spare time, I may implement it myself, but I can not give any time estimates on that.

@v0l
Copy link
Author

v0l commented Nov 11, 2021

I don't have much experience with Go but I can try to give it a shot if I get a chance..

@ProtossGP32
Copy link

Hi all! Great work with this exporter, I'm looking for several options to export MQTT JSON objects to Prometheus and this is promising. This feature would be a deal breaker for us indeed!

My use case is regarding frame inference results from DLStreamer pipeline server. Each inference pipeline published into its own topic, easily configurable on pipeline execution; an example of an output payload for a topic named /pipeline_server/object_classification/person_vehicle_bike/$NAME_OF_PIPELINE would be like the following one:

{
  "objects": [
    {
      "detection": {
        "bounding_box": {
          "x_max": 0.18579910695552826,
          "x_min": 0.16391132771968842,
          "y_max": 0.7926501631736755,
          "y_min": 0.6738967299461365
        },
        "confidence": 0.6267059445381165,
        "label": "person",
        "label_id": 1
      },
      "h": 86,
      "region_id": 526533,
      "roi_type": "person",
      "w": 28,
      "x": 210,
      "y": 485
    },
    {
      "detection": {
        "bounding_box": {
          "x_max": 0.16837865114212036,
          "x_min": 0.08635252714157104,
          "y_max": 0.8236457109451294,
          "y_min": 0.7092335224151611
        },
        "confidence": 0.9996802806854248,
        "label": "vehicle",
        "label_id": 2
      },
      "h": 82,
      "region_id": 526534,
      "roi_type": "vehicle",
      "w": 105,
      "x": 111,
      "y": 511
    },
    {
      "detection": {
        "bounding_box": {
          "x_max": 0.31999629735946655,
          "x_min": 0.22663737833499908,
          "y_max": 0.7987639904022217,
          "y_min": 0.6771434545516968
        },
        "confidence": 0.9921255707740784,
        "label": "vehicle",
        "label_id": 2
      },
      "h": 88,
      "region_id": 526535,
      "roi_type": "vehicle",
      "w": 119,
      "x": 290,
      "y": 488
    }
  ],
  "resolution": {
    "height": 720,
    "width": 1280
  },
  "timestamp": 217375761000
}

Where:

  • Labels like the pipeline type and the pipeline name can be extracted from the topic
  • objects is an array of JSON objects detected in that particular frame
  • resolution is the processed frame resolution
  • timestamp is the elapsed time in nanoseconds since the beginning of the pipeline execution
  • Each detection object has interesting labels to keep, such as label, label_id and roi_type
  • Regarding metrics, things like confidence for each detection and computed total_detections_per_frame would be nice to have

Simplifying the use-case as much as possible, I'd say that a good starting point would be to be able to label the pipeline name, the pipeline type and retrieve as metrics both the timestamp (not as real timestamp but as elapsed_time_since_start) and num_of_detections (being the output of len(objects). Later on I'd iterate on extracting each detection information as well if possible.

Each inference model pipeline outputs a different JSON payload, but for the time being I'm using this as an example of what would be our needs in terms of extracting metrics and labels from it.

I'd gladly collaborate with a PR if you can guide me on the best way to approach this and can weight the complexity of implementing this (it might be too much in a single PR). Bear with me as Go is not a programming language I'm familiar with.

Let me know your thoughts on this use case scenario, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants