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

A way to convert the systemUpTime to seconds #22

Closed
JDA88 opened this issue Jun 1, 2023 · 13 comments
Closed

A way to convert the systemUpTime to seconds #22

JDA88 opened this issue Jun 1, 2023 · 13 comments
Assignees

Comments

@JDA88
Copy link

JDA88 commented Jun 1, 2023

Is your feature request related to a problem? Please describe.
We are trying to retrieve the property topSystem.attributes.systemUpTime which works (as a label) but unfortunately we didn’t find a way to convert the format (ie. 210:20:16:20.000) to a correct value (seconds)

Describe the solution you'd like
Ideally we would want a metric like this :
aci_node_uptime_duration_seconds{aci="GVA_DC_FABRIC",nodeid="1",podid="1"} 4320000
with the value been the number of second since last reboot

Describe alternatives you've considered
Unfortunately I don’t see any other alternative as we didn’t find another property which would store the value in a raw format.
From what I understand if a calculation does not already exist it would require a custom one, correct ?

@thenodon
Copy link
Member

thenodon commented Jun 1, 2023

Can you send me the complete configuration for the query including the config query type you are doing. The time format looks really strange 210:20:16:20.000. What are the different values?

@JDA88
Copy link
Author

JDA88 commented Jun 1, 2023

Configuration look like this (ignore the wrong naming it was a dirty test):

    queries:
      - node_health:
        class_name: topSystem
        query_parameter: "?rsp-subtree-include=health"
        metrics:
          -
            value_name: topSystem.children.@reverse.0.healthInst.attributes.cur
            value_calculation: "value / 100"
        labels:
          - property_name: topSystem.attributes.dn
            regex: "^topology/pod-(?P<podid>[1-9][0-9]*)/node-(?P<nodeid>[1-9][0-9]*)/sys"
          - property_name: topSystem.attributes.state
            regex: "^(?P<state>.*)"
          - property_name: topSystem.attributes.oobMgmtAddr
            regex: "^(?P<oobMgmtAddr>.*)"
          - property_name: topSystem.attributes.name
            regex: "^(?P<name>.*)"
          - property_name: topSystem.attributes.role
            regex: "^(?P<role>.*)"
          - property_name: topSystem.attributes.systemUpTime 
            regex: "^(?P<uptime>.*)"   

uptime goes to a label because the value is incompatible with a value.
The Cisco API documentation have example with this value: https://www.cisco.com/c/en/us/td/docs/switches/datacenter/aci/apic/sw/1-x/api/rest/b_APIC_RESTful_API_User_Guide/additional_examples.html

You also have a description in the Nexus documentation: https://pubhub.devnetcloud.com/media/dme-docs-9-3-5/docs/System/top:System/

systemUpTime scalar:Time The time (in seconds) since the system was booted. TIME FORMAT: %H:%M:%S 54:05:07:26.000

So the format is probably D:H:M:S in ACI...

@thenodon
Copy link
Member

thenodon commented Jun 1, 2023

@JDA88 thanks for the feedback. That was a horrible time format, why not just use seconds. Maybe a feature request to Cisco. Do you know if this time format is used only in this object or if its a common time "type" in ACI universe?

@JDA88
Copy link
Author

JDA88 commented Jun 1, 2023

I kind of agree with the format been horrible for an API. They should at least expose it in both formats.

The scalar:Time is used by Cisco in different places (searching for it in google return some match like frequency for jobs etc.) but I have no idea if there is other useful scenario for the ACI exporter.
It's not that difficult to parse and convert to seconds, but I can’t do it at the prometheus level, it must be done at the exporter level.
You mention a feature request to Cisco? Do you have any idea of how to do this?

@thenodon
Copy link
Member

thenodon commented Jun 3, 2023

@JDA88 I think its easier to fix it in the exporter than to ask for a change request from ACI. I also think this is functionality can be valuable for other use cases. I did not want to create some new specific transformation for this specific format, but instead build on the functionality that already exists related to value_regex_transformation and value_calculation. So instead of limit the functionality to a single value we can now have a configuration like this:

class_queries:
  issue22:
    class_name: topSystem
    query_parameter: "?rsp-subtree-include=health"
    metrics:
      - name: uptime
        #value_name: topSystem.children.@reverse.0.healthInst.attributes.cur
        value_name: topSystem.attributes.systemUpTime
        value_regex_transformation: "([0-9].*):([0-2][0-9]):([0-6][0-9]):([0-6][0-9])\\..*"
        value_calculation: "value1 * 86400 + value2 * 3600 + value3 * 60 + value4"
    labels:
      - property_name: topSystem.attributes.dn
        regex: "^topology/pod-(?P<podid>[1-9][0-9]*)/node-(?P<nodeid>[1-9][0-9]*)/sys"
      - property_name: topSystem.attributes.state
        regex: "^(?P<state>.*)"
      - property_name: topSystem.attributes.oobMgmtAddr
        regex: "^(?P<oobMgmtAddr>.*)"
      - property_name: topSystem.attributes.name
        regex: "^(?P<name>.*)"
      - property_name: topSystem.attributes.role
        regex: "^(?P<role>.*)"
      - property_name: topSystem.attributes.systemUpTime
        regex: "^(?P<uptime>.*)"

In the value_regex_transformation we have a regex that extract 4 values and in the value_calculation the values can be referenced as value1 to value4. The index will be according to the order they are matched in the regex.
If we just have one value, the existing way of reference the value using just value in the value_calculation will still work.
If there are errors in the regex or in the value_calculation, lets say try to reference value34 and it does not exist the aci-exporter will log that with information so its easy to find in the configuration file.
So with the above we now get the output:

curl -s 'http://localhost:9643/probe?target=cisco_sandbox&queries=issue22'
# HELP issue22 
# TYPE issue22 
aci_issue22{aci="ACI Fabric1",fabric="cisco_sandbox",name="leaf-1",nodeid="101",oobMgmtAddr="192.168.100.101",podid="1",role="leaf",state="in-service",uptime="07:19:59:33.000"} 676773
aci_issue22{aci="ACI Fabric1",fabric="cisco_sandbox",name="leaf-2",nodeid="102",oobMgmtAddr="192.168.100.102",podid="1",role="leaf",state="in-service",uptime="07:19:59:33.000"} 676773
aci_issue22{aci="ACI Fabric1",fabric="cisco_sandbox",name="spine-1",nodeid="201",oobMgmtAddr="192.0.2.5",podid="1",role="spine",state="in-service",uptime="07:19:59:33.000"} 676773
aci_issue22{aci="ACI Fabric1",fabric="cisco_sandbox",name="apic1",nodeid="1",oobMgmtAddr="192.168.100.10",podid="1",role="controller",state="in-service",uptime="07:19:59:35.000"} 676775
# HELP scrape_duration_seconds The duration, in seconds, of the last scrape of the fabric
# TYPE scrape_duration_seconds gauge
aci_scrape_duration_seconds{aci="ACI Fabric1",fabric="cisco_sandbox"} 3.109194926

@thenodon thenodon self-assigned this Jun 3, 2023
thenodon added a commit that referenced this issue Jun 3, 2023
@thenodon
Copy link
Member

thenodon commented Jun 3, 2023

@JDA88 you can test the branch issue_22 to test the new feature. Please read the README.md and give feedback if anything is unclear.

@thenodon
Copy link
Member

thenodon commented Jun 4, 2023

With the above commit it's now possible to use named regex groups like this:

value_regex_transformation: "(?P<days>[0-9].*):(?P<hours>[[0-2][0-9]):(?P<minutes>[[0-6][0-9]):(?P<seconds>[[0-6][0-9])\\..*"
value_calculation: "days * 86400 + hours * 3600 + minutes * 60 + seconds"

@JDA88
Copy link
Author

JDA88 commented Jun 5, 2023

Thank you very much for this. I'll let you know when we get the opportunity to test this!

@thenodon
Copy link
Member

thenodon commented Jun 5, 2023

@JDA88 just so you know with latest commit on this branch golang is updated to 1.20

@thenodon
Copy link
Member

thenodon commented Jun 6, 2023

@JDA88 would really like your feedback from your test on this before merging :)

@JDA88
Copy link
Author

JDA88 commented Jun 6, 2023

would really like your feedback from your test on this before merging :)

I'll do my best but our team are very busy this week and we won't probably be able to test before at the very least next week

@thenodon
Copy link
Member

thenodon commented Jun 6, 2023

@JDA88 I understand. I think I merge with master and continue on the other issues you made. Can create a beta for testing instead.

@thenodon thenodon mentioned this issue Jun 6, 2023
@thenodon
Copy link
Member

thenodon commented Jun 6, 2023

Merged in #27

@thenodon thenodon closed this as completed Jun 6, 2023
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