|
| 1 | +/* |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2023, CloudBees, Inc. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +package jenkins.telemetry.impl; |
| 26 | + |
| 27 | +import edu.umd.cs.findbugs.annotations.NonNull; |
| 28 | +import hudson.Extension; |
| 29 | +import java.time.LocalDate; |
| 30 | +import jenkins.telemetry.Telemetry; |
| 31 | +import net.sf.json.JSONObject; |
| 32 | +import org.kohsuke.accmod.Restricted; |
| 33 | +import org.kohsuke.accmod.restrictions.NoExternalUse; |
| 34 | + |
| 35 | +/** |
| 36 | + * Records approximations of when Jenkins was started and the current time, to allow for computation of uptime. |
| 37 | + */ |
| 38 | +@Extension |
| 39 | +@Restricted(NoExternalUse.class) |
| 40 | +public class Uptime extends Telemetry { |
| 41 | + private static final long START = System.nanoTime(); |
| 42 | + |
| 43 | + @NonNull |
| 44 | + @Override |
| 45 | + public String getDisplayName() { |
| 46 | + return "Uptime"; |
| 47 | + } |
| 48 | + |
| 49 | + @NonNull |
| 50 | + @Override |
| 51 | + public LocalDate getStart() { |
| 52 | + return LocalDate.of(2023, 10, 20); |
| 53 | + } |
| 54 | + |
| 55 | + @NonNull |
| 56 | + @Override |
| 57 | + public LocalDate getEnd() { |
| 58 | + return LocalDate.of(2024, 1, 20); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public JSONObject createContent() { |
| 63 | + return new JSONObject().element("start", START).element("now", System.nanoTime()).element("components", buildComponentInformation()); |
| 64 | + } |
| 65 | +} |
0 commit comments