public static Metric from ( String fullName , double value ) { String [ ] pieces = fullName . split ( "\\." ) ; Preconditions . checkArgument ( pieces . length > 1 , "Incorrect metrics name: %s." , fullName ) ; String hostname = null ; String id = null ; String name = null ; int tagStartIdx = 0 ; // Master or cluster metrics don't have hostname included. if ( pieces [ 0 ] . equals ( MetricsSystem . InstanceType . MASTER . toString ( ) ) || pieces [ 0 ] . equals ( MetricsSystem . CLUSTER . toString ( ) ) ) { name = pieces [ 1 ] ; tagStartIdx = 2 ; } else { if ( pieces [ 1 ] . contains ( ID_SEPARATOR ) ) { String [ ] ids = pieces [ 1 ] . split ( ID_SEPARATOR ) ; hostname = ids [ 0 ] ; id = ids [ 1 ] ; } else { hostname = pieces [ 1 ] ; } name = pieces [ 2 ] ; tagStartIdx = 3 ; } MetricsSystem . InstanceType instance = MetricsSystem . InstanceType . fromString ( pieces [ 0 ] ) ; Metric metric = new Metric ( instance , hostname , id , name , value ) ; // parse tags for ( int i = tagStartIdx ; i < pieces . length ; i ++ ) { String tagStr = pieces [ i ] ; if ( ! tagStr . contains ( TAG_SEPARATOR ) ) { // Unknown tag continue ; } int tagSeparatorIdx = tagStr . indexOf ( TAG_SEPARATOR ) ; metric . addTag ( tagStr . substring ( 0 , tagSeparatorIdx ) , tagStr . substring ( tagSeparatorIdx + 1 ) ) ; } return metric ; }
Creates the metric from the full name and the value .