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

Engine: Implement Awk mapping #343

Open
NassimBtk opened this issue Jul 25, 2024 · 4 comments
Open

Engine: Implement Awk mapping #343

NassimBtk opened this issue Jul 25, 2024 · 4 comments
Assignees
Labels
awk enhancement New feature or request java

Comments

@NassimBtk
Copy link
Member

NassimBtk commented Jul 25, 2024

Required connector model

  memory:
    keys: [id] # key to identify the monitor instance
    simple:
      sources:
        source1: 
        ... 
        source2:
        ... 
      mapping:
        type: awk # csv, single, jsonArray, jsonObject, awk, keyValueMap
        sources:
        - ${source::source1}
        - ${source::source2}
        # Manifests the mapping of the metrics for the documentation (Optional)
        metrics:
        - system.memory.usage{system.memory.state="free"}
        - system.memory.limit
        script: |
            /^Mem:/ { print "system.memory.usage{system.memory.state=\"free\", id=\"$3\"}:" $2 }
            /^Total online memory:/ { print "system.memory.limit{id=\"$3\"}:" $4 }

The monitor identified should be managed using the keys field and the attributes defined in the metric outputs (Output of the awk script).

@bertysentry
Copy link
Member

Instead of print() statements in the AWK script, we could provide a dedicated function through the Jawk extension mechanism (as we did for HTTP requests, SNMP, etc.):

void pushMetric(String name, AssocArray attributes, Double value) { /* push metric to telemetry manager */ }

This way, there is no need to parse the output of the AWK script and handle syntax errors.

@bertysentry
Copy link
Member

Also, please note that we can't provide multiple sources to AWK (because they are not input files, but just stdin). So the YAML should be with source: <source ref> and not sources: [ array of source refs ].

@bertysentry
Copy link
Member

I'm thinking: if we implement this pushMetric() function for AWK scripts, there is no need to have a dedicated mapping: awk.

Instead we could call the pushMetric() function directly in an AWK source, or even in an AWK compute step.

The YAML then becomes:

  memory:
    keys: [id] # key to identify the monitor instance
    simple:
      sources:
        source1: 
          # run command
          compute:
          - type: awk
            script: |
              /^Mem:/ {
                attrs["id"] = $3
                attrs["system.memory.state"] = "free"
                pushMetric("system.memory.usage", attrs, $4);
              }
      mapping:
        type: none # yes, none! This mapping section becomes totally optional!
        # Manifests the mapping of the metrics for the documentation (Optional)
        metrics:
        - system.memory.usage{system.memory.state="free"}
        - system.memory.limit

@NassimBtk
Copy link
Member Author

I'm currently considering this proposal: MetricsHub manages attributes both at the monitor level and at the metric level itself. We know that before metrics are pushed, monitor attributes and metric attributes are merged, with everything applied to the metric. If we consider the current MetricsHub model, perhaps we should update the extension to define createMonitor(attr). Given that Otel is experimenting with prototypes for Resource entities, it seems we might be on the right track by creating monitors within our internal model.

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

No branches or pull requests

3 participants