Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-68608] Add entire disk space usage as JENKINS_FS #71

Merged
merged 5 commits into from
Sep 29, 2022

Conversation

hareldev
Copy link

@hareldev hareldev commented Jul 17, 2022

A common deployment of Jenkins is within a container, where JENKINS_HOME is mounted to a persistent volume.
Following various cases where I've seen differences between this plugin reported JENKINS_HOME usage and the actual one (calculated using du), including JENKINS-68608 I'm creating this PR.

The idea was to add simple, quick way of calculating the entire filesystem disk usage. Filesystem disk usage is acquired using Jenkins.get().getRootDir().getUsableSpace() which does not actually traverse the disk, and takes <1ms to run.

This PR does not change existing entries / calculation method, but add a new entry - JENKINS_FS.

so with the current version of this plugin, /prometheus endpoint will show:

...
# HELP default_jenkins_disk_usage_bytes Disk usage of first level folder in JENKINS_HOME in bytes
# TYPE default_jenkins_disk_usage_bytes gauge
default_jenkins_disk_usage_bytes{directory="JENKINS_HOME",} 3.60921088E8
...

After this PR it will show:

...
# HELP default_jenkins_disk_usage_bytes Disk usage of first level folder in JENKINS_HOME in bytes
# TYPE default_jenkins_disk_usage_bytes gauge
default_jenkins_disk_usage_bytes{directory="JENKINS_HOME",} 3.60921088E8
default_jenkins_disk_usage_bytes{directory="JENKINS_FS",} 1.11412523008E11
...

Example of an actual Jenkins instance running in a container with JENKINS_HOME set in a volume /var/lib/jenkins:

  1. cloudbees-disk-usage-simple-plugin version 0.10 shows 0.7GB is used (which is wrong):
Item name  ↓	Disk usage (kB) 
JENKINS_HOME	746758
  1. du shows 7GB is used:
sh-4.2$ du -sh /var/lib/jenkins/
7.0G    /var/lib/jenkins/
  1. df shows 7.1GB is used by the filesystem:
sh-4.2$ df -h
Filesystem                  Size  Used Avail Use% Mounted on
...
10.0.10.20:/csi-5552521  20G  7.1G   13G  36% /var/lib/jenkins

Installing the plugin with this PR implemented, adds JENKINS_FS with the correct values:

Item name  ↓	Disk usage (kB)   
JENKINS_FS	7409664
JENKINS_HOME	746758

Which could be used instead of JENKINS_HOME is such situation where it's the only folder on the mount.

Tested on various Jenkins versions, runs either on a container, or Windows server.


  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@hareldev hareldev mentioned this pull request Jul 17, 2022
6 tasks
@hareldev hareldev changed the title Add entire disk space usage Add entire disk space usage to prometheus Jul 19, 2022
@hareldev hareldev changed the title Add entire disk space usage to prometheus Add entire disk space usage as JENKINS_FS Jul 19, 2022
@hareldev hareldev marked this pull request as ready for review July 19, 2022 14:41
@PierreBtz
Copy link
Contributor

@hareldev thanks for the contribution. I would like to be sure to understand exactly what issue you are trying to fix.

From my understanding, you would like to address issues like JENKINS-68608 where the size of the folder of a multibranch Pipeline is wrongly reported. However, looking at the PR, I'm under the impression you are not fixing the issue, but rather adding an entirely new endpoint to report the size of the whole FS containing JENKINS.

What I don't exactly get is why you need such endpoint in the first place. Your monitoring system should provide you with all the necessary probes to get this information directly from your VM/container without using Jenkins. Am I missing something?

@hareldev
Copy link
Author

Thanks @PierreBtz for your comment.

The issue as we experience it, is not only bound to multibranch pipelines, but affects all of our jobs folders, which makes us look for additional ways to estimate the entire folder size.
jobs folder for example has the largest deviation. (Example is taken from another Jenkins instance)

sh-4.2$ du -sh /var/lib/jenkins/
1.3G    /var/lib/jenkins/

sh-4.2$ du -sh /var/lib/jenkins/jobs
576M    /var/lib/jenkins/jobs

while the plugin reports of 570MB / 25MB respectively:

Item name  ↓ | Disk usage (kB)
JENKINS_HOME | 574590
JENKINS_HOME/jobs | 25454

Since we don't have any reliable source of estimating the disk space, and in order to avoid high resource usage traversing folders, it is simpler to add the entire FS endpoint to monitor.

I couldn't find any other Jenkins plugin that exposes this entry to /prometheus endpoint, so my suggestion is to include it within the disk usage plugin.

Copy link
Contributor

@PierreBtz PierreBtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hareldev sorry for the delay here :/

Everything looks good. If I was to nitpick, I think we should have two different UsageComputation classes to make things clearer instead of mixing everything in one, but I don't want to bother you with that, it's not blocking, I'll do the refactoring later myself.

I'd like to run one more test on my end but if it's green expect a merge + release within the week. Again, sorry for the delay and thanks for the contribution.

@PierreBtz PierreBtz changed the title Add entire disk space usage as JENKINS_FS [JENKINS-68608] Add entire disk space usage as JENKINS_FS Sep 29, 2022
@PierreBtz PierreBtz merged commit 4fdfcc4 into jenkinsci:master Sep 29, 2022
@PierreBtz
Copy link
Contributor

@hareldev this is available in https://github.com/jenkinsci/cloudbees-disk-usage-simple-plugin/releases/tag/176.v4fdfcc443b_cf, thanks for the contribution.

@hareldev
Copy link
Author

hareldev commented Oct 8, 2022

@PierreBtz Thanks for the merge!
Let me know if you would want me to make a change to the classes, or anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants