opentsdb特殊字符问题
Opentsdb对特殊字符规范如下:
代码实现如下
public final class net.opentsdb.core.Tags
/**
* Ensures that a given string is a valid metric name or tag name/value.
* @param what A human readable description of what's being validated.
* @param s The string to validate.
* @throws IllegalArgumentException if the string isn't valid.
*/
public static void validateString(final String what, final String s) {
if (s == null) {
throw new IllegalArgumentException("Invalid " + what + ": null");
} else if ("".equals(s)) {
throw new IllegalArgumentException("Invalid " + what + ": empty string");
}
final int n = s.length();
for (int i = 0; i < n; i++) {
final char c = s.charAt(i);
if (!(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9') || c == '-' || c == '_' || c == '.'
|| c == '/' || Character.isLetter(c) || isAllowSpecialChars(c))) {
throw new IllegalArgumentException("Invalid " + what
+ " (\"" + s + "\"): illegal character: " + c);
}
}
}
从上述代码里可以看到Opentsdb支持自定义允许的特殊字符,isAllowSpecialChars
public final class net.opentsdb.core.TSDB
if (config.getString("tsd.core.tag.allow_specialchars") != null) {
Tags.setAllowSpecialChars(config.getString("tsd.core.tag.allow_specialchars"));
}
所以只需要在opentsdb的配置文件里加上该属性配置就可以,
例如: tsd.core.tag.allow_specialchars = : 就将“:”设置为允许的字符了 。
很奇怪的在于opentsdb的官方文档里没有列出该配置属性
OpenTSDB Configuration.
写入opentsdb之前进行数据转换。
private static String convert(String in) {
return in == null ? null :
in.toLowerCase().replaceAll("[^-_a-z0-9.\\u4e00-\\u9fa5]", "_");
}
关于opentsdb重复插入数据后报错。
Request failed: Internal Server Error
net.opentsdb.core.IllegalDataException:Duplicate timestamp for key=[68,
-110, -13, 90, 60, -97, 96, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 0, 95, 0, 0, 3,
0, 0, 4], ms_offset=1356000, older=[66, -41, -21, -63], newer=[66, -41,
-21, -60]; set tsd.storage.fix_duplicates=true to fix automatically or run
Fsck
其实这个错误提示已经非常的明显了,就是在Opentsdb的配置文件opentsdb.conf当中,追加上这个配置条件tsd.storage.fix_duplicates=true即可,如下图所示:
这样我们就可以替换重复的数据,Opentsdb可以重新使用,但是这个配置文件是什么意思呢,官网上说这个配置文件的意思是:
Whether or not to accept the last written value when parsing data points with duplicate timestamps. When enabled in conjunction with compactions, a compacted column will be written with the latest data points.
这句话的意思是当同一个时间点有多个值得时候,是否接受最后一个解析数据点的数据,当启用这个fix_duplicates配置的时候,这个列将采用最是的点位这个时间点的值。然后这个配置默认为false,所以我们需要开启这个点。
所以,当我们出现错误时,一定要学会去看提示+官网,百分之80问题可以迎刃而解~