Skip to content

Commit

Permalink
Followup fixes to tranmission-rpc bumps
Browse files Browse the repository at this point in the history
Why:
Somehow, I still missed some code paths apparently, despite testing

What:
Switch from getattr to get, which either dict-like objects or the new
Container classes support
Fix some typos
Make sure to use the proper raw name of a metric

Signed-off-by: Alexandros Kosiaris <akosiaris@gmail.com>
  • Loading branch information
akosiaris committed Jun 17, 2024
1 parent 1bb3077 commit 75b7d77
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions collectd_transmission/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}
}
except ImportError:
# SessionStats import failed, assume we are ransmission-rpc < 4.0.0
# SessionStats import failed, assume we are using transmission-rpc < 4.0.0
metrics= {
# General metrics
'general': {
Expand Down Expand Up @@ -118,7 +118,7 @@ def initialize():

def shutdown():
'''
Collectd shutdown routive
Collectd shutdown routine
'''
# Not really any resource to close, just clear the object
data['client'] = None
Expand All @@ -142,7 +142,10 @@ def field_getter(stats, key, category):
if category == 'current':
return stats.current_stats.get(key)
# We are in "general"
return getattr(stats, key)
try:
return stats.get(key)
except AttributeError:
return getattr(stats, key)


def get_stats():
Expand All @@ -164,12 +167,12 @@ def get_stats():
# Let's get our data
for category, catmetrics in metrics.items():
for metric, attrs in catmetrics.items():
metric_name = getattr(attrs, 'name', metric)
metric_name = attrs.get('name', metric)
values = collectd.Values(
type=attrs['type'],
plugin=PLUGIN_NAME,
type_instance=f'{category}-{metric_name}')
values.dispatch(values=[field_getter(stats, metric, category)])
values.dispatch(values=[field_getter(stats, metric_name, category)])


# Register our functions
Expand Down

0 comments on commit 75b7d77

Please sign in to comment.