Plugin Directory

Changeset 3490329


Ignore:
Timestamp:
03/24/2026 07:50:02 PM (4 days ago)
Author:
satollo
Message:

Version 1.0.2

Location:
satollo-monitor
Files:
47 added
7 edited
3 copied

Legend:

Unmodified
Added
Removed
  • satollo-monitor/trunk/admin/activate.php

    r3481978 r3490329  
    2323            PRIMARY KEY (`id`),
    2424            KEY `name` (`name`)
     25            ) $charset_collate;";
     26
     27dbDelta($sql);
     28if ($wpdb->last_error) {
     29    error_log($wpdb->last_error);
     30}
     31
     32$sql = "CREATE TABLE `" . $wpdb->prefix . "monitor_aiclient` (
     33            `id` int(11) NOT NULL AUTO_INCREMENT,
     34            `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
     35            `provider` varchar(200) NOT NULL DEFAULT '',
     36            `model` varchar(200) NOT NULL DEFAULT '',
     37            `tokens` int NOT NULL DEFAULT 0,
     38            `duration` double DEFAULT 0,
     39            `context` varchar(50) NOT NULL DEFAULT '',
     40            PRIMARY KEY (`id`)
    2541            ) $charset_collate;";
    2642
  • satollo-monitor/trunk/admin/admin.php

    r3484639 r3490329  
    7070                    }
    7171                    break;
     72                case 'aiclient':
     73                    switch ($subpage) {
     74                        case 'logs':
     75                            include __DIR__ . '/aiclient/logs.php';
     76                            break;
     77                        default:
     78                            include __DIR__ . '/aiclient/index.php';
     79                    }
     80                    break;
    7281                case 'http':
    7382                    switch ($subpage) {
  • satollo-monitor/trunk/admin/aiclient/index.php

    r3484639 r3490329  
    11<?php
    2 
    32defined('ABSPATH') || exit;
    43
     
    76global $wpdb;
    87
    9 $per_day = $wpdb->get_results("select date(created) as date, count(*) as total from {$wpdb->prefix}monitor_rest where created > DATE_SUB(NOW(), INTERVAL 30 DAY) group by date(created) order by date(created) asc");
     8$per_day = $wpdb->get_results("select date(created) as date, count(*) as total, sum(tokens) as tokens from {$wpdb->prefix}monitor_aiclient where created > DATE_SUB(NOW(), INTERVAL 30 DAY) group by date(created) order by date(created) asc");
    109$per_day_x = [];
    1110$per_day_y = [];
     
    1413    $per_day_x[] = $data->date;
    1514    $per_day_y[] = $data->total;
     15    $per_day_tokens[] = $data->tokens;
    1616}
    17 
    1817?>
    1918<?php include __DIR__ . '/../menu.php'; ?>
    20 <div class="wrap" id="monitor-emails">
     19<div class="wrap">
    2120    <?php include __DIR__ . '/nav.php'; ?>
     21
     22    <div id="graph-calls" style="margin: 2rem 0"></div>
     23    <div id="graph-tokens" style="margin: 2rem 0"></div>
     24
     25    <script>
     26        jQuery(function () {
     27            var layout = {
     28                title: {text: 'Calls per day'}
     29            };
     30            var data = [{
     31                    x: <?= json_encode($per_day_x); ?>,
     32                    y: <?= json_encode($per_day_y); ?>,
     33                    type: 'scatter'
     34                }
     35
     36            ];
     37
     38            Plotly.newPlot('graph-calls', data, layout);
     39
     40            var layout = {
     41                title: {text: 'Calls per day'}
     42            };
     43            var data_tokens = [{
     44                    x: <?= json_encode($per_day_x); ?>,
     45                    y: <?= json_encode($per_day_tokens); ?>,
     46                    type: 'scatter'
     47                }
     48
     49            ];
     50
     51            Plotly.newPlot('graph-tokens', data_tokens, {
     52                title: {text: 'Tokens per day'}
     53            });
     54        });
     55    </script>
    2256
    2357    <table class="widefat" style="width: auto">
     
    2660                <th><?php esc_html_e('Date', 'satollo-monitor'); ?></th>
    2761                <th><?php esc_html_e('Count', 'satollo-monitor'); ?></th>
     62                <th><?php esc_html_e('Tokens', 'satollo-monitor'); ?></th>
    2863            </tr>
    2964        </thead>
     
    3368                    <td><?php echo esc_html($data->date); ?></td>
    3469                    <td><?php echo esc_html($data->total); ?></td>
     70                    <td><?php echo esc_html($data->tokens); ?></td>
    3571                </tr>
    3672            <?php } ?>
  • satollo-monitor/trunk/admin/aiclient/logs.php

    r3484639 r3490329  
    1111    check_admin_referer('monitor-action');
    1212    if (isset($_POST['clear'])) {
    13         $wpdb->query("truncate {$wpdb->prefix}monitor_rest");
     13        $wpdb->query("truncate {$wpdb->prefix}monitor_aiclient");
    1414    }
    1515}
     
    2828        $columns = [
    2929            'created' => __('Created', 'satollo-monitor'),
    30             'code' => __('Code', 'satollo-monitor'),
    31             'method' => __('Method', 'satollo-monitor'),
    32             'route' => __('Route', 'satollo-monitor'),
    33             'params' => __('Params', 'satollo-monitor'),
     30            'provider' => __('Provider', 'satollo-monitor'),
     31            'model' => __('Model', 'satollo-monitor'),
     32            'tokens' => __('Tokens', 'satollo-monitor'),
     33            'duration' => __('Duration (s)', 'satollo-monitor'),
     34            'context' => __('Context', 'satollo-monitor'),
    3435        ];
    3536        return $columns;
     
    4748        $per_page = 50;
    4849        $current_page = $this->get_pagenum();
    49         $total_items = (int) $wpdb->get_var("select count(*) from {$wpdb->prefix}monitor_rest");
     50        $total_items = (int) $wpdb->get_var("select count(*) from {$wpdb->prefix}monitor_aiclient");
    5051
    5152        $this->set_pagination_args([
     
    5455        ]);
    5556
    56         $this->items = $wpdb->get_results($wpdb->prepare("select * from {$wpdb->prefix}monitor_rest order by id desc limit %d offset %d",
     57        $this->items = $wpdb->get_results($wpdb->prepare("select * from {$wpdb->prefix}monitor_aiclient order by id desc limit %d offset %d",
    5758                        $per_page, ($current_page - 1) * $per_page));
    5859    }
     
    6263            case 'created':
    6364                return esc_html($item->created);
    64             case 'method':
    65                 return esc_html($item->method);
    66             case 'code':
    67                 return esc_html($item->code);
    68             case 'route':
    69                 return esc_html($item->route);
     65            case 'model':
     66                return esc_html($item->model);
     67            case 'tokens':
     68                return esc_html($item->tokens);
     69            case 'provider':
     70                return esc_html($item->provider);
     71            case 'duration':
     72                return round($item->duration, 3);
    7073            case 'context':
    7174                return esc_html($item->context);
     
    98101        <?php wp_nonce_field('monitor-action'); ?>
    99102        <button name="clear" class="button button-secondary"><?php esc_html_e('Clear', 'satollo-monitor'); ?></button>
    100         <a href="<?php echo esc_attr(get_rest_url()); ?>" class="button button-secondary" target="_blank"><?php esc_html_e('See main endpoint', 'satollo-monitor'); ?></a>
    101103    </form>
    102104
  • satollo-monitor/trunk/admin/aiclient/nav.php

    r3482094 r3490329  
    11<?php defined('ABSPATH') || exit; ?>
    22<p>
    3     <a href="?page=monitor&section=rest"><?php esc_html_e('Overview', 'satollo-monitor'); ?></a>
    4     | <a href="?page=monitor&section=rest&subpage=logs"><?php esc_html_e('Logs', 'satollo-monitor'); ?></a>
     3    <a href="?page=monitor&section=aiclient"><?php esc_html_e('Overview', 'satollo-monitor'); ?></a>
     4    | <a href="?page=monitor&section=aiclient&subpage=logs"><?php esc_html_e('Logs', 'satollo-monitor'); ?></a>
    55</p>
  • satollo-monitor/trunk/admin/assets/admin.css

    r3484639 r3490329  
    7272}
    7373
     74#monitor-menu-nav a.monitor-on::after {
     75  content: "";
     76  position: relative;
     77  top: -5px;
     78  display: inline-block;
     79  width: 8px;
     80  height: 8px;
     81  background-color: #ff69b4;
     82  border-radius: 50%;
     83  margin-left: 3px;
     84  vertical-align: middle;
     85  /* Adds a soft green glow around the dot */
     86  box-shadow: 0 0 0 rgba(255, 105, 180, 0.4);
     87  animation: pulse 2s infinite;
     88}
     89
     90@keyframes pulse {
     91  0% { box-shadow: 0 0 0 0 rgba(255, 105, 180, 0.7); }
     92  70% { box-shadow: 0 0 0 6px rgba(255, 105, 180, 0); }
     93  100% { box-shadow: 0 0 0 0 rgba(255, 105, 180, 0); }
     94}
    7495
    7596/* GENERAL */
  • satollo-monitor/trunk/admin/menu.php

    r3481978 r3490329  
    11<?php
    22defined('ABSPATH') || exit;
     3
     4$monitor_settings = get_option('monitor_settings');
     5$abilities_on = isset($monitor_settings['abilities']);
     6$rest_on = isset($monitor_settings['rest']);
     7$emails_on = isset($monitor_settings['emails']);
     8$http_on = isset($monitor_settings['http']);
     9$scheduler_on = isset($monitor_settings['scheduler']);
     10$aiclient_on = isset($monitor_settings['aiclient']);
    311?>
    412
     
    715    <div id="monitor-menu-nav">
    816        <ul>
    9             <li><a href="?page=monitor&section=scheduler">Scheduler</a></li>
    10             <li><a href="?page=monitor&section=http">HTTP</a></li>
    11             <li><a href="?page=monitor&section=abilities">Abilities</a></li>
    12             <li><a href="?page=monitor&section=rest">REST API</a></li>
    13             <li><a href="?page=monitor&section=emails">Emails</a></li>
     17            <li><a href="?page=monitor&section=scheduler" class="<?= $scheduler_on ? 'monitor-on' : '' ?>">Scheduler</a></li>
     18            <li><a href="?page=monitor&section=http" class="<?= $http_on ? 'monitor-on' : '' ?>">HTTP</a></li>
     19            <li><a href="?page=monitor&section=abilities" class="<?= $abilities_on ? 'monitor-on' : '' ?>">Abilities</a></li>
     20            <li><a href="?page=monitor&section=aiclient" class="<?= $aiclient_on ? 'monitor-on' : '' ?>">AI Client</a></li>
     21            <li><a href="?page=monitor&section=rest" class="<?= $rest_on ? 'monitor-on' : '' ?>">REST API</a></li>
     22            <li><a href="?page=monitor&section=emails" class="<?= $emails_on ? 'monitor-on' : '' ?>">Emails</a> </li>
    1423            <li><a href="?page=monitor&section=users">Users</a></li>
    1524            <li><a href="?page=monitor&section=settings">Settings</a></li>
     
    2231    jQuery(function () {
    2332        jQuery('#monitor-menu-nav a').each(function () {
    24            if (location.href.indexOf(this.href) >= 0) {
    25                jQuery(this).addClass('monitor-active');
    26            }
     33            if (location.href.indexOf(this.href) >= 0) {
     34                jQuery(this).addClass('monitor-active');
     35            }
    2736        });
    2837    });
  • satollo-monitor/trunk/admin/settings.php

    r3481978 r3490329  
    2929        <?php wp_nonce_field('monitor-save'); ?>
    3030        <table class="form-table" role="presentation">
     31            <tr>
     32                <th>
     33                    <?php esc_html_e('Monitor AI Client', 'satollo-monitor'); ?>
     34                </th>
     35                <td>
     36                    <input type="checkbox" value="1" name="data[aiclient]" <?= isset($data['aiclient']) ? 'checked' : ''; ?>>
     37                </td>
     38            </tr>
    3139            <tr>
    3240                <th>
  • satollo-monitor/trunk/readme.txt

    r3484639 r3490329  
    55Tested up to: 6.9
    66Requires PHP: 8.1
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    3232* Scheduler runs with detailed jobs data
    3333* Abilities invocation
     34* AI Client calls (WP 7.0+)
    3435
    35 Please, [read the official page for more details](htps://www.satollo.net/plugins/monitor) for more detail, examples of problems and solutions.
     36Please, [read the official page for more details](https://www.satollo.net/plugins/monitor) for more detail, examples of problems and solutions.
    3637
    3738= Contacts, Requests, Bugs =
     
    7980== Changelog ==
    8081
     82= 1.0.2 =
     83
     84* Added monitoring of AI Client (WP 7.0+)
     85
    8186= 1.0.1 =
    8287
  • satollo-monitor/trunk/satollo-monitor.php

    r3484639 r3490329  
    66 * Plugin Name: Monitor: Scheduler, Emails, API, HTTP and more
    77 * Description: Records and displays WP events: abilities calls, scheduler job executions, http calls, emails, and so on
    8  * Version: 1.0.1
     8 * Version: 1.0.2
    99 * Author: Stefano Lissa
    1010 * Author URI: https://www.satollo.net
     
    1818defined('ABSPATH') || exit;
    1919
    20 define('SATOLLO_MONITOR_VERSION', '1.0.1');
     20define('SATOLLO_MONITOR_VERSION', '1.0.2');
    2121
    2222/** @var wpdb $wpdb */
     
    298298        return $result;
    299299    }, 99, 3);
     300}
     301
     302if (!empty($monitor_settings['aiclient'])) {
     303    global $monitor_aiclient_log_start;
     304    add_action('wp_ai_client_before_generate_result', function ($event) {
     305        global $monitor_aiclient_log_start;
     306        $monitor_aiclient_log_start = microtime(true);
     307    });
     308
     309    add_action('wp_ai_client_after_generate_result', function ($event) {
     310        global $wpdb, $monitor_settings, $monitor_aiclient_log_start;
     311        /** @var WordPress\AiClient\Events\AfterGenerateResultEvent $event */
     312
     313        $context = monitor_get_context();
     314
     315        $tokens = $event->getResult()->getTokenUsage()->getTotalTokens();
     316        $model = $event->getModel()->metadata()->getName() ?? '';
     317        $provider = $event->getModel()->providerMetadata()->getName() ?? '';
     318
     319        $wpdb->insert($wpdb->prefix . 'monitor_aiclient', [
     320            'provider' => $provider,
     321            'model' => $model,
     322            'tokens' => $tokens,
     323            'context' => $context,
     324            'duration' => microtime(true) - $monitor_aiclient_log_start]);
     325    });
     326
    300327}
    301328
Note: See TracChangeset for help on using the changeset viewer.