<commit_before>package hudson.node_monitors;

import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.model.Computer;
import hudson.model.Descriptor;
import hudson.remoting.VirtualChannel;
import org.kohsuke.stapler.StaplerRequest;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;

/**
 * Checks available disk space of the node.
 * Requres Mustang.
 *
 * @author <NAME>
 * @since 1.123
 */
public class DiskSpaceMonitor extends NodeMonitor {
    public Descriptor<NodeMonitor> getDescriptor() {
        return DESCRIPTOR;
    }

    public Long getFreeSpace(Computer c) {
        return DESCRIPTOR.get(c);
    }

    /**
     * Returns the HTML representation of the space.
     */
    public String toHtml(long space) {
        space/=1024L;   // convert to KB
        space/=1024L;   // convert to MB
        if(space<1024) {
            // less than a GB
            return "<span class=error>"+new BigDecimal(space).scaleByPowerOfTen(-3).toPlainString()+"GB<span>";
        }

        return space/1024+"GB";
    }

    public static final AbstractNodeMonitorDescriptor<Long> DESCRIPTOR = new AbstractNodeMonitorDescriptor<Long>(DiskSpaceMonitor.class) {
        protected Long monitor(Computer c) throws IOException, InterruptedException {
            FilePath p = c.getNode().getRootPath();
            if(p==null) return null;

            return p.act(new FileCallable<Long>() {
                public Long invoke(File f, VirtualChannel channel) throws IOException {
                    return f.getUsableSpace();
                }
            });
        }

        public String getDisplayName() {
            return "Free Disk Space";
        }

        public NodeMonitor newInstance(StaplerRequest req) throws FormException {
            return new DiskSpaceMonitor();
        }
    };
}<commit_msg>disk space monitor was not working.<commit_after>package hudson.node_monitors;

import hudson.FilePath;
import hudson.FilePath.FileCallable;
import hudson.model.Computer;
import hudson.model.Descriptor;
import hudson.remoting.VirtualChannel;
import org.kohsuke.stapler.StaplerRequest;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;

/**
 * Checks available disk space of the node.
 * Requres Mustang.
 *
 * @author <NAME>
 * @since 1.123
 */
public class DiskSpaceMonitor extends NodeMonitor {
    public Descriptor<NodeMonitor> getDescriptor() {
        return DESCRIPTOR;
    }

    public Long getFreeSpace(Computer c) {
        return DESCRIPTOR.get(c);
    }

    /**
     * Returns the HTML representation of the space.
     */
    public String toHtml(long space) {
        space/=1024L;   // convert to KB
        space/=1024L;   // convert to MB
        if(space<1024) {
            // less than a GB
            return "<span class=error>"+new BigDecimal(space).scaleByPowerOfTen(-3).toPlainString()+"GB<span>";
        }

        return space/1024+"GB";
    }

    public static final AbstractNodeMonitorDescriptor<Long> DESCRIPTOR = new AbstractNodeMonitorDescriptor<Long>(DiskSpaceMonitor.class) {
        protected Long monitor(Computer c) throws IOException, InterruptedException {
            FilePath p = c.getNode().getRootPath();
            if(p==null) return null;

            return p.act(new GetUsableSpace());
        }

        public String getDisplayName() {
            return "Free Disk Space";
        }

        public NodeMonitor newInstance(StaplerRequest req) throws FormException {
            return new DiskSpaceMonitor();
        }
    };

    private static final class GetUsableSpace implements FileCallable<Long> {
        public Long invoke(File f, VirtualChannel channel) throws IOException {
            return f.getUsableSpace();
        }
        private static final long serialVersionUID = 1L;
    }
}
{'fraction_non_alphanumeric': 0.09547346514047866, 'fraction_numerical': 0.011186264308012487, 'mean_word_length': 2.641098484848485, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7588352', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1033, 'n_words': 274}