1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.opentsdb;
7
8 configFile = pkgs.writeText "opentsdb.conf" cfg.config;
9
10in {
11
12 ###### interface
13
14 options = {
15
16 services.opentsdb = {
17
18 enable = mkOption {
19 type = types.bool;
20 default = false;
21 description = ''
22 Whether to run OpenTSDB.
23 '';
24 };
25
26 package = mkOption {
27 type = types.package;
28 default = pkgs.opentsdb;
29 defaultText = literalExpression "pkgs.opentsdb";
30 description = ''
31 OpenTSDB package to use.
32 '';
33 };
34
35 user = mkOption {
36 type = types.str;
37 default = "opentsdb";
38 description = ''
39 User account under which OpenTSDB runs.
40 '';
41 };
42
43 group = mkOption {
44 type = types.str;
45 default = "opentsdb";
46 description = ''
47 Group account under which OpenTSDB runs.
48 '';
49 };
50
51 port = mkOption {
52 type = types.int;
53 default = 4242;
54 description = ''
55 Which port OpenTSDB listens on.
56 '';
57 };
58
59 config = mkOption {
60 type = types.lines;
61 default = ''
62 tsd.core.auto_create_metrics = true
63 tsd.http.request.enable_chunked = true
64 '';
65 description = ''
66 The contents of OpenTSDB's configuration file
67 '';
68 };
69
70 };
71
72 };
73
74 ###### implementation
75
76 config = mkIf config.services.opentsdb.enable {
77
78 systemd.services.opentsdb = {
79 description = "OpenTSDB Server";
80 wantedBy = [ "multi-user.target" ];
81 requires = [ "hbase.service" ];
82
83 environment.JAVA_HOME = "${pkgs.jre}";
84 path = [ pkgs.gnuplot ];
85
86 preStart =
87 ''
88 COMPRESSION=NONE HBASE_HOME=${config.services.hbase.package} ${cfg.package}/share/opentsdb/tools/create_table.sh
89 '';
90
91 serviceConfig = {
92 PermissionsStartOnly = true;
93 User = cfg.user;
94 Group = cfg.group;
95 ExecStart = "${cfg.package}/bin/tsdb tsd --staticroot=${cfg.package}/share/opentsdb/static --cachedir=/tmp/opentsdb --port=${toString cfg.port} --config=${configFile}";
96 };
97 };
98
99 users.users.opentsdb = {
100 description = "OpenTSDB Server user";
101 group = "opentsdb";
102 uid = config.ids.uids.opentsdb;
103 };
104
105 users.groups.opentsdb.gid = config.ids.gids.opentsdb;
106
107 };
108}