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

Scrape timestamp metrics as value #12

Closed
minefuto opened this issue Dec 28, 2021 · 7 comments
Closed

Scrape timestamp metrics as value #12

minefuto opened this issue Dec 28, 2021 · 7 comments

Comments

@minefuto
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I want to scrape timestamp metrics as value(not label) from ACI such as modTs.

{
   "totalCount":"1",
   "imdata":[
      {
         "infraWiNode":{
            "attributes":{
               -snip-
               "modTs":"2020-04-18T05:24:07.722+00:00",

Describe the solution you'd like
I think aci-exporter need to translate from "2020-04-18T05:24:07.722+00:00" to unixtime.

Do you have any plans to add the above function?
Or is it already implemented?

@thenodon
Copy link
Member

Hi @minefuto,
Can you provide the aci config, so I can se the query you are running.
When it comes to recalculate the value there is currently options as value_transform and value_calculation.
A value transform some string value to a float.

value_transform:
          'unknown': 0
          'down': 1
          'up': 2
          'link-up': 3

A value_calculation can make some simple calculations of the value. This example divide the value (value-string is a placeholder for the value) with 100.
value_calculation: "value / 100"

aci-exporter use https://github.com/Knetic/govaluate to execute the expression like "value / 100". In govaluate it is possible to create addtional "functions" that can be called, see https://github.com/Knetic/govaluate#functions. So it might be possible to create some additional functions for your use case.

@minefuto
Copy link
Contributor Author

Thanks @thenodon,
I think Knetic/govaluate only supported to transform from string to Time type.
Not supported from string to unixtime(float).

I want to detect link flap of ACI.
config.yaml

class_queries:
  interface_info:
    class_name: interface_info
    metrics:
      - name: lastLinkStChg
        value_name: ethpmPhysIf.attributes.lastLinkStChg
        type: gauge
    labels:
      - property_name: ethpmPhysIf.attributes.dn
        regex: "^topology/pod-(?P<podid>[1-9][0-9]*)/node-(?P<nodeid>[1-9][0-9]*)/sys/phys-\\[(?P<interface>[^\\]]+)\\]/"

prometheus-rules.yml

groups:
- name: alert
  rules:
  - alert: "interface flap"
    expr: changes(aci_lastLinkStChg[5m]) > 0
    for: 1m

But lastLinkStChg cannot scraped because it is string such as 2020-04-18T05:24:07.722+00:00.
So aci-exporter should get lastLinkStChg as a unixtime(float).

example:
minefuto@0691f56

@thenodon
Copy link
Member

I understand your use case and it make sense to understand flapping. I still think it could be done with https://github.com/Knetic/govaluate#functions.
We could implement a govaluate function like date_to_unixtime(.....) and in your aci config have

class_queries:
  interface_info:
    class_name: interface_info
    metrics:
      - name: lastLinkStChg
        value_name: ethpmPhysIf.attributes.lastLinkStChg
        type: gauge
        value_calculation: "date_to_unixtime(value, "rfc_3339")
    labels:
      - property_name: ethpmPhysIf.attributes.dn
        regex: "^topology/pod-(?P<podid>[1-9][0-9]*)/node-(?P<nodeid>[1-9][0-9]*)/sys/phys-\\[(?P<interface>[^\\]]+)\\]/"

The functions needs to be part of the parsing so a refactor of func valueReCalculation(...) needs to be done. I would be preferable that the govaluate function could be "loaded" at start up (reflection) to support custom function in additions to standard functions provided by aci-exporter.
This is just my thought and I have not done any testing. Would be great to know if there are a general request for this functionality.

@minefuto
Copy link
Contributor Author

Thanks, I understand your idea.
It looks like a good.

thenodon added a commit that referenced this issue Jan 7, 2022
… to a timestamp.

This is done in the aci-api toFloat function. Additional automated conversations could be added.
The following config can be used to test:
class_queries:
  interface_lastlink_st_chg_to_date:
    class_name: ethpmPhysIf
    metrics:
      - name: lastLinkStChg
        value_name: ethpmPhysIf.attributes.lastLinkStChg
        type: counter
    labels:
      # The field in the json used to parse the labels from
      - property_name: ethpmPhysIf.attributes.dn
        # The regex where the string enclosed in the P<xyz> is the label name
        regex: "^topology/pod-(?P<podid>[1-9][0-9]*)/node-(?P<nodeid>[1-9][0-9]*)/sys/phys-\\[(?P<interface>[^\\]]+)\\]/"
@thenodon
Copy link
Member

thenodon commented Jan 7, 2022

@minefuto please checkout branch issue_12 and test the fix. aci-export will now automatically convert date in rfc3339 format to a float. Hopefully all dates are in that format.
Use the config like:

class_queries:
  interface_lastlink_st_chg_to_date:
    class_name: ethpmPhysIf
    metrics:
      - name: lastLinkStChg
        value_name: ethpmPhysIf.attributes.lastLinkStChg
        type: counter
    labels:
      # The field in the json used to parse the labels from
      - property_name: ethpmPhysIf.attributes.dn
        # The regex where the string enclosed in the P<xyz> is the label name
        regex: "^topology/pod-(?P<podid>[1-9][0-9]*)/node-(?P<nodeid>[1-9][0-9]*)/sys/phys-\\[(?P<interface>[^\\]]+)\\]/"

@minefuto
Copy link
Contributor Author

I confirmed it solves this issue.

By the way, I found a problem in branch issue_12 that fails to go build.
I think It should be updated go.sum.

~/aci-exporter
❯ go version
go version go1.17.2 darwin/amd64

~/aci-exporter
❯ git switch issue_12
Branch 'issue_12' set up to track remote branch 'issue_12' from 'origin'.
Switched to a new branch 'issue_12'

~/aci-exporter
❯ go build
go: github.com/tidwall/gjson@v1.9.3: missing go.sum entry; to add it:
	go mod download github.com/tidwall/gjson
go: github.com/tidwall/gjson@v1.9.3: missing go.sum entry; to add it:
	go mod download github.com/tidwall/gjson

@thenodon
Copy link
Member

Thanks for the feedback and glad that it worked. Will fix the go.sum.
If you like to share your experience with aci-exporter, you can email me on ahaal@redbridge.se

@thenodon thenodon mentioned this issue Jan 14, 2022
thenodon added a commit that referenced this issue Jan 14, 2022
* [Issue #12] When metrics values is a rfc3339 date, it will be convert to a timestamp.
This is done in the aci-api toFloat function. Additional automated conversations could be added.
The following config can be used to test:
class_queries:
  interface_lastlink_st_chg_to_date:
    class_name: ethpmPhysIf
    metrics:
      - name: lastLinkStChg
        value_name: ethpmPhysIf.attributes.lastLinkStChg
        type: counter
    labels:
      # The field in the json used to parse the labels from
      - property_name: ethpmPhysIf.attributes.dn
        # The regex where the string enclosed in the P<xyz> is the label name
        regex: "^topology/pod-(?P<podid>[1-9][0-9]*)/node-(?P<nodeid>[1-9][0-9]*)/sys/phys-\\[(?P<interface>[^\\]]+)\\]/"

* Update dependency of github.com/tidwall/gjson to v1.9.3

* Update dependency of github.com/tidwall/gjson to v1.9.3

* Update "Metrics transformations" for the rfc 3339 transformation
@thenodon thenodon closed this as completed Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants