[SOLVED] Task log retention

jlsol1

New Member
Sep 18, 2023
1
0
1
Hi, is there any way of increasing the length of time that logs are stored in /var/log/pve/tasks? It doesn't look like they are cleanup up by logrotate.
 
  • Like
Reactions: jlsol1
Hi, no there is no option to configure this. The size of the archived tasks is hard coded to about 1000 entries, as you can see here https://git.proxmox.com/?p=pve-comm...6f62250b47c7b4aee163d2adeb847685;hb=HEAD#l354

The tasks are cleaned up once they are not referenced by index.1 anymore, which happens here https://git.proxmox.com/?p=pve-mana...4e01931b2f6b9577c49b0514745ba9eb;hb=HEAD#l129
I made a script that changes the number of 20,000 entries (around 1 year task history) by cron.

How the Script Works
This script automatically increases the number of Proxmox VE Task History entries by modifying the $maxsize parameter in the /usr/share/perl5/PVE/RESTEnvironment.pm file. By default, this parameter limits the task history to about 1000 entries ($maxsize = 50000). The script changes it to allow for 20,000 entries ($maxsize = 1000000).

Key Features:

  1. Checks for the existence of the target file.
  2. Searches for the specific $maxsize line.
  3. If found:
    • Creates a timestamped backup of the original file.
    • Replaces the line with the updated $maxsize value.
    • Logs the action in journald.
    • Restarts necessary Proxmox services (pvedaemon and pveproxy).
  4. Automatically runs at system boot and every hour using a cron job.

Create the script at /etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh:
Bash:
#!/bin/bash

# /etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh

# Path to the RESTEnvironment.pm file
FILE="/usr/share/perl5/PVE/RESTEnvironment.pm"

# Search and replacement strings
SEARCH="my \$maxsize = 50000; # about 1000 entries"
REPLACE="my \$maxsize = 1000000; # about 20000 entries, around 1 year task history"

# Check if the file exists
if [[ -f "$FILE" ]]; then
    # Check if the target string exists in the file
    if grep -qF "$SEARCH" "$FILE"; then
        logger -t change_pve_task_history_size "String found in $FILE. Replacing '$SEARCH' with '$REPLACE'."
       
        # Create a backup of the file
        BACKUP_FILE="$FILE.$(date +%Y%m%d_%H%M%S)"
        cp "$FILE" "$BACKUP_FILE"
        logger -t change_pve_task_history_size "Backup created: $BACKUP_FILE"
       
        # Replace the target string in the file
        sed -i "s|$SEARCH|$REPLACE|" "$FILE"
        logger -t change_pve_task_history_size "String replaced successfully in $FILE."
       
        # Restart Proxmox services
        systemctl restart pvedaemon.service pveproxy.service
        logger -t change_pve_task_history_size "Services restarted."
    else
        logger -t change_pve_task_history_size "Search string not found in $FILE. No changes made."
    fi
else
    logger -t change_pve_task_history_size "File $FILE does not exist!"
fi


Create a cron job file at /etc/cron.d/change_pve_task_history_size:
Bash:
# Cron job for updating Proxmox task history size

# /etc/cron.d/change_pve_task_history_size

@reboot root /etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh
0 * * * * root /etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh


Test the Script:Run the script manually to ensure it works as expected:

/etc/cronscripts/change_pve_task_history_size/update_pve_max_task_history_size.sh

Verify Logs:Check the logs in journald:


journalctl -t change_pve_task_history_size

Example Log Output
Bash:
Jan 06 12:00:00 hostname change_pve_task_history_size[1234]: String found in /usr/share/perl5/PVE/RESTEnvironment.pm. Replacing 'my $maxsize = 50000; # about 1000 entries' with 'my $maxsize = 1000000; # about 20000 entries, around 1 year task history'.
Jan 06 12:00:00 hostname change_pve_task_history_size[1234]: Backup created: /usr/share/perl5/PVE/RESTEnvironment.pm.20250106_120000
Jan 06 12:00:00 hostname change_pve_task_history_size[1234]: String replaced successfully in /usr/share/perl5/PVE/RESTEnvironment.pm.
Jan 06 12:00:01 hostname change_pve_task_history_size[1234]: Services restarted.
 
Hi, no there is no option to configure this. The size of the archived tasks is hard coded to about 1000 entries, as you can see here https://git.proxmox.com/?p=pve-comm...6f62250b47c7b4aee163d2adeb847685;hb=HEAD#l354

The tasks are cleaned up once they are not referenced by index.1 anymore, which happens here https://git.proxmox.com/?p=pve-mana...4e01931b2f6b9577c49b0514745ba9eb;hb=HEAD#l129

I'm trying to review the task history for an LXC and the LXC has _ZERO_ task entries for the last year, but I know for a fact there's multiple. Can we _please_ have this number increased by... a lot? Or changed in nature so that task history limits are at least per-object?
 
  • Like
Reactions: santiagobiali
I just ran into the same thing. PBS does solve this much better with respect to longevity of messages. There is no index, but archive and it has thousands of entries.

It would be really great to have better this. I just opened a bug report for this.

PBS adding additional logging capabilities is neat, I didn't realise that! Thanks for adding that!

That being said, I do think some aspects of logging consistency, length, etc, could/should be improved without relying on PBS. HOWEVER I am also a fan of PBS adding even more logging capabilities on top of that (so long as it doesn't become a "required component for actually good logging" situation).

Neat! Thanks for creating the bug report @LnxBil ❤️ Now to see if I can remember my creds for that...
 
For those interested, with a simple script that introductes these changes and tests reliably, see https://gitea.virtnet.bond/Joseph.Rawlings/change_pve_task_history_size. This includes both the original with a source.md and my automated single file install script with testing. It is being used currently in a cluster utilizing Proxmox 9.1.1 (Current as of posting). You can see all steps in a git style repository of my changes or implement his via the directories with a git command should you desire. All credit goes to Dmitrius7 who wrote the original code.

DISCLAIMER OF WARRANTY
The software, scripts, documentation, and any related materials (“Materials”) are provided “AS IS”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the authors, contributors, or Virtnet.bond be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the Materials or the use of the Materials.

LIMITATION OF LIABILITY
To the maximum extent permitted by applicable law, Virtnet.bond and its contributors shall not be liable for any direct, indirect, incidental, consequential, special, exemplary, or punitive damages, including loss of data, loss of profits, system failure, or other commercial damages or losses, arising out of or related to your use or inability to use the Materials, even if advised of the possibility of such damages.


INDEMNIFICATION
By using or distributing the Materials, you agree to indemnify, defend, and hold harmless Virtnet.bond, its owners, affiliates, and contributors from and against any and all claims, liabilities, damages, losses, costs, expenses, or demands (including reasonable attorneys’ fees) arising out of or related to:
  1. Your use, modification, or distribution of the Materials;
  2. Your violation of any applicable law or regulation; or
  3. Any claim alleging that your use of the Materials caused damage to any person, entity, or system.
NO OBLIGATION TO SUPPORT
Virtnet.bond and contributors have no obligation to provide maintenance, support, updates, or fixes. Use of the Materials is entirely at your own risk.
 
I'm trying to review the task history for an LXC and the LXC has _ZERO_ task entries for the last year, but I know for a fact there's multiple. Can we _please_ have this number increased by... a lot? Or changed in nature so that task history limits are at least per-object?
To add here a little hint:
If the LXC has moved the node, the tasks made, are only save on the node where it was running at the time.
 
  • Like
Reactions: BloodyIron