MCPcopy Index your code
hub / github.com/OpenTSDB/opentsdb / respondAsciiQuery

Method respondAsciiQuery

src/tsd/GraphHandler.java:920–975  ·  view source on GitHub ↗

Respond to a query that wants the output in ASCII. When a query specifies the "ascii" query string parameter, we send the data points back to the client in plain text instead of sending a PNG. @param query The query we're currently serving. @param max_age The maximum time (in seconds) we wanna a

(final HttpQuery query,
                                        final int max_age,
                                        final String basepath,
                                        final Plot plot)

Source from the content-addressed store, hash-verified

918 * @param plot The plot object to generate Gnuplot's input files.
919 */
920 private static void respondAsciiQuery(final HttpQuery query,
921 final int max_age,
922 final String basepath,
923 final Plot plot) {
924 final String path = basepath + ".txt";
925 PrintWriter asciifile;
926 try {
927 asciifile = new PrintWriter(path);
928 } catch (IOException e) {
929 query.internalError(e);
930 return;
931 }
932 try {
933 final StringBuilder tagbuf = new StringBuilder();
934 for (final DataPoints dp : plot.getDataPoints()) {
935 final String metric = dp.metricName();
936 tagbuf.setLength(0);
937 for (final Map.Entry<String, String> tag : dp.getTags().entrySet()) {
938 tagbuf.append(' ').append(tag.getKey())
939 .append('=').append(tag.getValue());
940 }
941 for (final DataPoint d : dp) {
942 if (d.isInteger()) {
943 printMetricHeader(asciifile, metric, d.timestamp());
944 asciifile.print(d.longValue());
945 } else {
946 // Doubles require extra processing.
947 final double value = d.doubleValue();
948
949 // Value might be NaN or infinity.
950 if (Double.isInfinite(value)) {
951 // Infinity is invalid.
952 throw new IllegalStateException("Infinity:" + value
953 + " d=" + d + ", query=" + query);
954 } else if (Double.isNaN(value)) {
955 // NaNs should be skipped.
956 continue;
957 }
958
959 printMetricHeader(asciifile, metric, d.timestamp());
960 asciifile.print(value);
961 }
962
963 asciifile.print(tagbuf);
964 asciifile.print('\n');
965 }
966 }
967 } finally {
968 asciifile.close();
969 }
970 try {
971 query.sendFile(path, max_age);
972 } catch (IOException e) {
973 query.internalError(e);
974 }
975 }
976
977 /**

Callers 1

doGraphMethod · 0.95

Calls 14

printMetricHeaderMethod · 0.95
sendFileMethod · 0.80
metricNameMethod · 0.65
getTagsMethod · 0.65
isIntegerMethod · 0.65
timestampMethod · 0.65
longValueMethod · 0.65
doubleValueMethod · 0.65
internalErrorMethod · 0.45
getDataPointsMethod · 0.45
appendMethod · 0.45
getKeyMethod · 0.45

Tested by

no test coverage detected