Skip to content

Commit

Permalink
[fix] Account for Plex Pass requirement for CPU and RAM stats feature (
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 authored Oct 15, 2024
1 parent babbeee commit ee20e0a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
19 changes: 16 additions & 3 deletions documentation/DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ updates).

Performance monitoring will report metrics such as:

- CPU usage
- RAM usage
- CPU usage (requires Plex Pass)
- RAM usage (requires Plex Pass)
- Disk space usage
- Plex user count

Expand All @@ -255,6 +255,17 @@ Please be aware of the potential risks of allowing raw SQL queries to be run dir
API. If you do not intend on using the performance monitoring feature, it is recommended to keep SQL queries
disabled (`api_sql = 0` in Tautulli's `config.ini` file).

#### CPU and RAM Monitoring

Tauticord's CPU and RAM monitoring features will [directly communicate with the Plex Media Server](#system-access) to
retrieve statistics. CPU and RAM usage statistics is
a [Plex Pass feature](https://support.plex.tv/articles/200871837-status-and-dashboard/); as a result, this requires a
Plex Pass subscription to work.

Tauticord will automatically determine if the Plex Media Server has a Plex Pass subscription. If this feature is enabled
in the configuration file, but the Plex Media Server does not have a Plex Pass subscription, Tauticord will ignore the
configuration settings and log a warning.

#### Disk Space Monitoring

Tauticord's disk space monitoring feature will analyze the used and total space of the provided folder (default: The
Expand Down Expand Up @@ -301,9 +312,11 @@ Variants:

**This command is locked to administrators only.**

Display graphs for Tautulli play count/duration statistics. This is similar to the "Graphs" section on the Tautulli homepage.
Display graphs for Tautulli play count/duration statistics. This is similar to the "Graphs" section on the Tautulli
homepage.

Variants:

- `/graphs play-count-daily`
- `/graphs play-count-day-of-week`
- `/graphs play-count-hour-of-day`
Expand Down
2 changes: 1 addition & 1 deletion modules/settings/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def to_model(self) -> settings_models.Discord:
channel_name = self.get_value(key="ChannelName", default="tauticord")
channel_name = utils.discord_text_channel_name_format(string=channel_name)
use_summary_message = utils.extract_boolean(self.get_value(key="PostSummaryMessage", default=True))
enable_termination = utils.extract_boolean(self.get_value(key="EnableTermination", default=True))
enable_termination = utils.extract_boolean(self.get_value(key="EnableTermination", default=False))
enable_slash_commands = utils.extract_boolean(self.get_value(key="EnableSlashCommands", default=False))

status_message_settings_data = self.get_subsection_data(key="StatusMessage", optional=True)
Expand Down
3 changes: 2 additions & 1 deletion modules/tasks/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ async def update_activity_summary_message(self,
# update the message regardless of whether the content has changed
self.message = await discord_utils.send_embed_message(embed=summary.embed, message=self.message)

if self.tautulli.plex_pass_feature_is_allowed(feature=self.enable_stream_termination_if_possible):
if self.tautulli.plex_pass_feature_is_allowed(feature=self.enable_stream_termination_if_possible,
warning="Stream termination control requires Plex Pass, ignoring setting..."):
await self.add_stream_number_emoji_reactions(count=len(summary.streams),
emoji_manager=self.emoji_manager)
# on_raw_reaction_add will handle the rest
Expand Down
6 changes: 4 additions & 2 deletions modules/tasks/performance_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ async def update_performance_stats(self) -> None:
await self.edit_stat_voice_channel(voice_channel_settings=settings,
stat=stat)

if self.stats_settings.cpu.enable:
if self.tautulli.plex_pass_feature_is_allowed(feature=self.stats_settings.cpu.enable,
warning="CPU usage stats require Plex Pass, ignoring setting..."):
settings = self.stats_settings.cpu
cpu_percent = self.calculate_cpu_percent()
logging.debug(f"Updating CPU voice channel with new CPU percent: {cpu_percent}")
await self.edit_stat_voice_channel(voice_channel_settings=settings,
stat=cpu_percent)

if self.stats_settings.memory.enable:
if self.tautulli.plex_pass_feature_is_allowed(feature=self.stats_settings.memory.enable,
warning="Memory usage stats require Plex Pass, ignoring setting..."):
settings = self.stats_settings.memory
memory_percent = self.calculate_memory_percent()
logging.debug(f"Updating Memory voice channel with new Memory percent: {memory_percent}")
Expand Down
7 changes: 5 additions & 2 deletions modules/tautulli/tautulli_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ def _error_and_analytics(self, error_message, function_name) -> None:
logging.error(error_message)
self.analytics.event(event_category="Error", event_action=function_name, random_uuid_if_needed=True)

def plex_pass_feature_is_allowed(self, feature: bool) -> bool:
def plex_pass_feature_is_allowed(self, feature: bool, warning: Optional[str] = None) -> bool:
if not self.has_plex_pass:
if feature and warning: # Only log warning if feature was attempted to be used
logging.warning(warning)
return False

return feature
Expand Down Expand Up @@ -345,7 +347,8 @@ def get_play_duration_chart_data(self, chart_type: StatChartType, days: int,

match chart_type:
case StatChartType.DAILY_BY_MEDIA_TYPE:
data = self.api.get_plays_by_date(time_range=days, y_axis=StatMetricType.DURATION.value, user_ids=user_ids)
data = self.api.get_plays_by_date(time_range=days, y_axis=StatMetricType.DURATION.value,
user_ids=user_ids)
case StatChartType.BY_HOUR_OF_DAY:
data = self.api.get_plays_by_hour_of_day(time_range=days, y_axis=StatMetricType.DURATION.value,
user_ids=user_ids)
Expand Down

0 comments on commit ee20e0a

Please sign in to comment.