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

If node id data type is Boolean which type need to put #3

Open
dineshmerck opened this issue Feb 10, 2021 · 6 comments
Open

If node id data type is Boolean which type need to put #3

dineshmerck opened this issue Feb 10, 2021 · 6 comments

Comments

@dineshmerck
Copy link

@ahuret

In the metric, if node id have boolean datatype which one i need to put in type in config file.

type: gauge # MANDATORY metric type can be counter, gauge, Float, Double.

metrics:

  • name: PI001
    help: get metrics for machine current value
    nodeid: ns=4;s=|var|CODESYS Control Win V3 x64..CRS.Instances.CM.F_AnalogueSensorWired[2].Obj.Out_rCurrentValue
    labels:
    site: Paris
    type: Float
  • name: PLC
    help: get metrics for machine process
    nodeid: ns=4;s=|var|CODESYS Control Win V3 x64..CRS.Instances.CM.F_AnalogueSensorWired[0].DAPCriticalProcessHi.Inp_bDefect
    labels:
    site: Paris
    type: gauge

in the above metrics first node id is working.. but 2nd one is not working because it have Boolean datatype

Could you pls advise me on that.

@ahuret
Copy link
Collaborator

ahuret commented Feb 10, 2021

Hi @dineshmerck !
Currently it's not available using this exporter but it could/should.
I think we can consider booleans as prometheus gauges: false => 0 and true => 1.
I checked the code and it needs a small refactoring to handle this properly.
If you want, you can propose a merge request, I'd be happy to help you with that. What do you think ?

@dineshmerck
Copy link
Author

Currently it's not available using this exporter but it could/should.
I think we can consider booleans as prometheus gauges: false => 0 and true => 1.

i have changed to true also but still i can see the value is 0.

Think because of the datatype.

Correct me if i am wrong

@ahuret
Copy link
Collaborator

ahuret commented Feb 10, 2021

As I said, this is because bool type is not available/implemented in this exporter.

@dineshmerck
Copy link
Author

dineshmerck commented Feb 10, 2021 via email

@brunellegrossmann
Copy link
Collaborator

Hello dineshmerck,
We have currently no use for those specific datatype, if you want to use it you can propose a merge request that handles it
I recommend to have a look at this part of the code https://github.com/skilld-labs/telemetry-opcua-exporter/blob/master/collector/collector.go#L106 that is mainly the only line that considers the result to be a float64
I think that you can handle here the conversion from int/boolean to float64 here
For strings further changes should be done

@ahuret
Copy link
Collaborator

ahuret commented Feb 11, 2021

This line https://github.com/skilld-labs/telemetry-opcua-exporter/blob/master/collector/collector.go#L186 is the one that assume opc ua metric is a Float.
A good option would be to refer on r.Value.Type() to get the ua.TypeID
Then, switching on this type, we can transform types to value:

// for gauge
switch r.Value.Type() {
    case ua.TypeIDFloat:
      gaugeValue = r.Value.Float()
    case ua.TypeIDBoolean:
       if r.Value.Bool() {
         gaugeValue = 1
       } else {
          gaugeValue = 0
       }
    case ...
    default:
      gaugeValue = r.Value.Float()
}

What do you think ?

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

3 participants