@@ -147,8 +147,8 @@ def _get_tag_query_tag(self, sampler, wmi_obj, tag_query):
147147 self .log .debug ("Extracted `tag_queries` tag: '%s'" , tag )
148148 return tag
149149
150- def _extract_metrics (self , wmi_sampler , tag_by , tag_queries , constant_tags , tag_by_prefix ):
151- # type: (WMISampler, str, List[List[str]], List[str], str ) -> List[WMIMetric]
150+ def _extract_metrics (self , wmi_sampler , tag_by , tag_queries , constant_tags ):
151+ # type: (WMISampler, str, List[List[str]], List[str]) -> List[WMIMetric]
152152 """
153153 Extract and tag metrics from the WMISampler.
154154
@@ -174,8 +174,6 @@ def _extract_metrics(self, wmi_sampler, tag_by, tag_queries, constant_tags, tag_
174174
175175 extracted_metrics = []
176176 tag_by = tag_by .lower ()
177- if tag_by_prefix :
178- tag_by_prefix = tag_by_prefix .lower ()
179177
180178 for wmi_obj in wmi_sampler :
181179 tags = list (constant_tags ) if constant_tags else []
@@ -205,13 +203,21 @@ def _extract_metrics(self, wmi_sampler, tag_by, tag_queries, constant_tags, tag_
205203 # Tag with `tag_by` parameter
206204 for t in tag_by .split (',' ):
207205 t = t .strip ()
206+ if ' as ' in t :
207+ t_split = t .split (' as ' )
208+ t = t_split [0 ].strip ()
209+ alias = t_split [1 ].strip ()
210+ else :
211+ alias = None
208212 if normalized_wmi_property == t :
209213 tag_value = str (wmi_value ).lower ()
210214 if tag_queries and tag_value .find ("#" ) > 0 :
211215 tag_value = tag_value [: tag_value .find ("#" )]
212- if tag_by_prefix :
213- t = "{prefix}_{name}" .format (prefix = tag_by_prefix , name = t )
214- tags .append ("{name}:{value}" .format (name = t , value = tag_value ))
216+
217+ if alias :
218+ tags .append ("{name}:{value}" .format (name = alias , value = tag_value ))
219+ else :
220+ tags .append ("{name}:{value}" .format (name = t , value = tag_value ))
215221 continue
216222
217223 # No metric extraction on 'Name' and properties in tag_by
@@ -272,6 +278,7 @@ def _get_instance_key(self, host, namespace, wmi_class, other=None):
272278 def get_running_wmi_sampler (self , properties , filters , ** kwargs ):
273279 # type: (List[str], List[Dict[str, WMIFilter]], **Any) -> WMISampler
274280 tag_by = kwargs .pop ('tag_by' , "" )
281+
275282 return self ._get_running_wmi_sampler (
276283 instance_key = None ,
277284 wmi_class = self .wmi_class ,
0 commit comments