blob: 915cced842bda453dcfd716859c2f6e43704472d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.jdisc.state;
import com.yahoo.vespa.defaults.Defaults;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.time.Instant;
import java.util.Set;
/**
* @author olaa
*/
public class CoredumpGatherer {
private static final Path COREDUMP_PATH = Path.of(Defaults.getDefaults().underVespaHome("var/crash/processing"));
protected static JSONObject gatherCoredumpMetrics() {
int coredumps = getNumberOfCoredumps();
JSONObject packet = new JSONObject();
try {
packet.put("status_code", coredumps == 0 ? 0 : 1);
packet.put("status_msg", coredumps == 0 ? "OK" : String.format("Found %d coredumps", coredumps));
packet.put("timestamp", Instant.now().getEpochSecond());
packet.put("application", "system-coredumps-processing");
} catch (JSONException e) {}
return packet;
}
private static int getNumberOfCoredumps() {
try {
return (int) Files.walk(COREDUMP_PATH)
.filter(Files::isRegularFile)
.count();
} catch (NoSuchFileException e) {
return 0;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
|