8 Replies Latest reply on Dec 18, 2013 5:43 PM by Robert Ramírez Vique

    How to custom metric + property?

    Robert Ramírez Vique Newbie

      Hello every body!

       

      first of all, I am not sure this is the place where I should send this message, so if is not here the correct place, please correct me!

       

      I am trying to create a custom metric for mod_cluster. In fact what I want is to have a metric that can manage to send all the information about the metric to AWS CloudWatch so we can auto scale based on this, in order to use this service we need public and secret keys. This interceptor just need to bypass everything and store the final load number, so I would like to be able to change the metric used (business, heap or cpu) to adapt at any time our service depending on application behavior.

       

      I have two options

      • First one (not preferred) is to rewrite mod_cluster class DynamicLoadBalanceFactorProvider so I can handle any call here and send it back to AWS CloudWatch service, this will help because I can manage to have any metric with the same flexibility mod_cluster provide. The cons here will be that I have to add authentication tokens for the external service which I was thinking about using just JVM params because don't see where to set extra metrics, but this is an small cons; the other cons is that I have to reimplement mod_cluster ...which obviously is not a good solution.
      • The other solution is to use the tag custom-load-metric. This metric will contain the credentials and some other properties and some of this properties to be the other metrics. This metrics should be just string values and resolve the at my metric. Just started with a simple metric, is added and called but does not receive the property definition. I mean, I have:
        • standalone.xml:
                     <dynamic-load-provider history="10" decay="2">
                          <load-metric type="heap" weight="1" capacity="3725"/>
                          <load-metric type="busyness" weight="2" />
                          <load-metric type="cpu" weight="3" capacity="2" />
                              <custom-load-metric class="com.netquest.jboss.metric.MyCustomMetric">
                                      <property name="foo" value="accessKeyvalue" />
                                      <property name="accessKey" value="accessKeyvalue" />
                                      <property name="privateKey" value="privateKeyValue" />
                              </custom-load-metric>
                          </dynamic-load-provider>
      
        • My metric I have two attributes with public setters and getters:
        • private String accessKey = "empty";
          public String getAccessKey() { return accessKey;  }
          public void setAccessKey(String accessKey) { this.accessKey = accessKey; }
          
        • And on getLoad I printout the value which are always empty ...

       

      What do you think? There are other solutions or any documentation about how to implement it? About the property problem, did you have any idea why property are not being wired?

       

      thanks in advance, robert

        • 1. Re: How to custom metric + property?
          Jean-Frederic Clere Master

          the custom-load-metric are for that.

          • 2. Re: How to custom metric + property?
            Robert Ramírez Vique Newbie

            Helo Jean-Frederic,

             

            first of all thanks for your response. I think is not enough, maybe it could be but I should replicate most of mod_cluster job, or maybe I don't understanding it right.

             

            Maybe I missed something but my point was to be able to have a different "provider". I mean I want to be able to configure the provider with different metrics and change it on production, so I can simply change the way we decide that a server is loaded or not, as we can do now with the mod-cluster-config- But the point is that whatever is this load I want to capture this number and send it to CloudWatch (external service). I assume with a custom-load-metric I can add a different metric to be part of the global load (a % of it) of the server but not to be the global load.

            So my scenario will be that I have a configuration of load like "heap, bussyness, cpu" with equivalent weights and the resulting load number is also sent to the external service, and at any moment I want to be able to change the load-metric to have for example : "heap, cpu" or just "heap", and the resulting load number is still being sent to the CloudWatch service.

            Basically I would like to intercept the load number sent to mod_cluster from jboss.

             

            I think with custom-load-metric maybe I can somehow inject the standard metric beans and then calculate in the same way DynamicLoadBalanceFactorProvider does even though this will be replication of mod_cluster's code. And also I am not sure how the <property> on a custom metric works and don't have seen any documentation. And with this configuration I cannot change the metric configuration without restart because they are bean already loaded.

             

            cheers, robert

            • 3. Re: Re: How to custom metric + property?
              Paul Ferraro Master

              &lt;property name="..."&gt;...&lt;/property&gt; defines a java bean property - for your LoadMetric class should have an appropriate setter method.

               

              In your case, I would expect that you'd want to override each metric, e.g.


              public class MyAverageLoadMetric extends AverageLoadMetric {
                public double getLoad(Engine engine) {
                  double load = super.getLoad(engine);
                  // Send load to cloud watch
                  return load;
                }
              }
              

               

              Currently, I don't think you can change the load metric configuration at runtime without triggering a redeploy of your application.  Technically, this really ought not interrupt service to your application, but it is certainly more invasive than it needs to be.

               

              [MODCLUSTER-379] Add ability to add/remove load metrics at runtime. - JBoss Issue Tracker

              [WFLY-2652] Add/remove load metric operations should not require service restart - JBoss Issue Tracker

              1 of 1 people found this helpful
              • 4. Re: Re: How to custom metric + property?
                Robert Ramírez Vique Newbie

                Hello Paul,

                 

                 

                first of all thanks for your response but more important thanks for your big contribution to the mod_cluster project, awsome project!

                 

                 

                About your response, what is the class AverageLoadMetric? I've just seen AverageSystemLoadMetric which, from what I understood, is capturing the global server unix load (not just jboss, and nothing to do with heap and others). If this is the class you proposed I am afraid it cannot work for us, because what we need is to send the metric, whatever metric is configured (probably more related to heap + cpu + business than system load), to mod_cluster & to CloudWatch, not just send the last minute Unix load.

                 

                 

                I didn't know that was not possible to change the metric at runtime even though I understand that will be available at some point in the future.

                 

                Also, about the properties ... I tried what you proposed implementing or extending AbstractLoadMetric but not succeed. I used standard java beans setters as well have a non parameters constructor. Do you have any example? I am using jboss 7.0.2 and mod_cluster 1.2.3.Final

                 

                cheers, robert

                • 5. Re: Re: Re: How to custom metric + property?
                  Radoslav Husar Master

                  Also, about the properties ... I tried what you proposed implementing or extending AbstractLoadMetric but not succeed. I used standard java beans setters as well have a non parameters constructor. Do you have any example? I am using jboss 7.0.2 and mod_cluster 1.2.3.Final

                  Unless I am mistaken this is a bug. The properties are parsed for and stored in the model, but are never applied.

                   

                  Created Jira to track this https://issues.jboss.org/browse/WFLY-2663

                   

                  About your response, what is the class AverageLoadMetric? I've just seen AverageSystemLoadMetric which, from what I understood, is capturing the global server unix load (not just jboss, and nothing to do with heap and others). If this is the class you proposed I am afraid it cannot work for us, because what we need is to send the metric, whatever metric is configured (probably more related to heap + cpu + business than system load), to mod_cluster & to CloudWatch, not just send the last minute Unix load.

                  Paul was providing an example how you can implement your own metric to add some custom logic by extending the existing metrics so that you don't have to copy the code (or reimplement then from scratch).

                   

                  The name of the class should have been AverageSystemLoadMetric.

                   

                  &lt;property name="..."&gt;...&lt;/property&gt; defines a java bean property - for your LoadMetric class should have an appropriate setter method.

                  Actually, the correct syntax since AS7  is

                   

                  <property name="foo" value="bar"/>
                  
                  
                  • 6. Re: Re: Re: How to custom metric + property?
                    Robert Ramírez Vique Newbie

                    Thanks Radoslav,

                     

                    thanks for your response.

                     

                    Now I get it, you are talking about override each metric to have my own implementation, which will work to send each individual metric load to the external service. This could work.

                     

                    But with this solution I am sending the load disincorporated and without applying the proper weight or capacity. I understand that this cannot be solved with current architecture without changing mod_cluster code, so leaving it as is now. Thanks for your time!

                     

                    About the properties, thanks for pointing out the Bug, I've voted for its resolution

                     

                    cheers, robert

                    • 7. Re: How to custom metric + property?
                      Radoslav Husar Master

                      About the properties, thanks for pointing out the Bug, I've voted for its resolution

                      The first version of the pull request is ready. You can build with this branch and try it out:

                       

                      https://github.com/wildfly/wildfly/pull/5626

                       

                      I also made a quick example on how to use custom metric, see this repo for example:

                       

                      rhusar/mod_cluster-custom-load-metric-example · GitHub

                      1 of 1 people found this helpful
                      • 8. Re: How to custom metric + property?
                        Robert Ramírez Vique Newbie

                        Many thanks Radoslav,

                         

                        that seems to be a good improvement! And also thanks for the good sample on the github repo

                         

                        cheers, robert