You've already forked wp-fedistream
feat: Add Prometheus metrics integration
All checks were successful
Create Release Package / build-release (push) Successful in 1m0s
All checks were successful
Create Release Package / build-release (push) Successful in 1m0s
- Add includes/Prometheus/Integration.php with metrics collection - Expose content, engagement, user, WooCommerce, and ActivityPub metrics - Add settings toggle in Integrations tab - Requires WP Prometheus plugin to be active - Bump version to 0.5.0 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,7 @@ use WP_FediStream\Frontend\TemplateLoader;
|
||||
use WP_FediStream\Frontend\Widgets;
|
||||
use WP_FediStream\PostTypes\Artist;
|
||||
use WP_FediStream\WooCommerce\Integration as WooCommerceIntegration;
|
||||
use WP_FediStream\Prometheus\Integration as PrometheusIntegration;
|
||||
use WP_FediStream\WooCommerce\DigitalDelivery;
|
||||
use WP_FediStream\WooCommerce\StreamingAccess;
|
||||
use WP_FediStream\PostTypes\Album;
|
||||
@@ -207,6 +208,11 @@ final class Plugin {
|
||||
new StreamingAccess();
|
||||
}
|
||||
|
||||
// Initialize Prometheus integration.
|
||||
if ( get_option( 'wp_fedistream_enable_prometheus', 0 ) && $this->is_prometheus_active() ) {
|
||||
new PrometheusIntegration();
|
||||
}
|
||||
|
||||
// Initialize user library and notifications.
|
||||
new UserLibrary();
|
||||
new LibraryPage();
|
||||
@@ -448,6 +454,7 @@ final class Plugin {
|
||||
// Get current settings.
|
||||
$enable_activitypub = get_option( 'wp_fedistream_enable_activitypub', 1 );
|
||||
$enable_woocommerce = get_option( 'wp_fedistream_enable_woocommerce', 0 );
|
||||
$enable_prometheus = get_option( 'wp_fedistream_enable_prometheus', 0 );
|
||||
$max_upload_size = get_option( 'wp_fedistream_max_upload_size', 50 );
|
||||
$default_license = get_option( 'wp_fedistream_default_license', 'all-rights-reserved' );
|
||||
|
||||
@@ -486,7 +493,7 @@ final class Plugin {
|
||||
$this->render_settings_tab( $max_upload_size, $default_license );
|
||||
break;
|
||||
case 'integrations':
|
||||
$this->render_integrations_tab( $enable_activitypub, $enable_woocommerce );
|
||||
$this->render_integrations_tab( $enable_activitypub, $enable_woocommerce, $enable_prometheus );
|
||||
break;
|
||||
}
|
||||
?>
|
||||
@@ -525,6 +532,7 @@ final class Plugin {
|
||||
case 'integrations':
|
||||
update_option( 'wp_fedistream_enable_activitypub', isset( $_POST['enable_activitypub'] ) ? 1 : 0 );
|
||||
update_option( 'wp_fedistream_enable_woocommerce', isset( $_POST['enable_woocommerce'] ) ? 1 : 0 );
|
||||
update_option( 'wp_fedistream_enable_prometheus', isset( $_POST['enable_prometheus'] ) ? 1 : 0 );
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Integration settings saved.', 'wp-fedistream' ) . '</p></div>';
|
||||
break;
|
||||
}
|
||||
@@ -719,9 +727,10 @@ final class Plugin {
|
||||
*
|
||||
* @param int $enable_activitypub Whether ActivityPub is enabled.
|
||||
* @param int $enable_woocommerce Whether WooCommerce integration is enabled.
|
||||
* @param int $enable_prometheus Whether Prometheus metrics are enabled.
|
||||
* @return void
|
||||
*/
|
||||
private function render_integrations_tab( int $enable_activitypub, int $enable_woocommerce ): void {
|
||||
private function render_integrations_tab( int $enable_activitypub, int $enable_woocommerce, int $enable_prometheus ): void {
|
||||
?>
|
||||
<form method="post" action="">
|
||||
<?php wp_nonce_field( 'fedistream_save_settings', 'fedistream_settings_nonce' ); ?>
|
||||
@@ -760,6 +769,23 @@ final class Plugin {
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Prometheus Metrics', 'wp-fedistream' ); ?></th>
|
||||
<td>
|
||||
<label>
|
||||
<input type="checkbox" name="enable_prometheus" value="1" <?php checked( $enable_prometheus, 1 ); ?> <?php disabled( ! $this->is_prometheus_active() ); ?>>
|
||||
<?php esc_html_e( 'Enable Prometheus metrics', 'wp-fedistream' ); ?>
|
||||
</label>
|
||||
<?php if ( ! $this->is_prometheus_active() ) : ?>
|
||||
<p class="description" style="color: #d63638;">
|
||||
<span class="dashicons dashicons-dismiss" style="font-size: 16px; width: 16px; height: 16px; vertical-align: text-bottom;"></span>
|
||||
<?php esc_html_e( 'WP Prometheus plugin is not installed or active.', 'wp-fedistream' ); ?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<p class="description"><?php esc_html_e( 'Expose FediStream metrics for Prometheus monitoring.', 'wp-fedistream' ); ?></p>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
@@ -933,4 +959,13 @@ final class Plugin {
|
||||
public function is_activitypub_active(): bool {
|
||||
return class_exists( 'Activitypub\Activitypub' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if WP Prometheus plugin is active.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_prometheus_active(): bool {
|
||||
return defined( 'WP_PROMETHEUS_VERSION' ) || class_exists( 'WP_Prometheus\Plugin' );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user