Skip to content

Commit a89dec1

Browse files
committed
[metrics] Add more unit related metrics
1 parent 19db08a commit a89dec1

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

src/core/varlink-metrics.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

3+
#include "hashmap.h"
34
#include "json-util.h"
45
#include "manager.h"
6+
#include "list.h"
7+
#include "set.h"
58
#include "sd-json.h"
69
#include "sd-varlink.h"
10+
#include "unit-def.h"
711
#include "varlink-metrics.h"
812

13+
static unsigned get_list_size(Manager *m, UnitType t);
14+
15+
static unsigned get_list_size(Manager *m, UnitType t) {
16+
unsigned count = 0;
17+
18+
assert(m);
19+
// TODO: check t <= UNIT_SCOPE
20+
21+
LIST_FOREACH(units_by_type, _u, m->units_by_type[t])
22+
count++;
23+
24+
return count;
25+
}
26+
927
int vl_method_list(sd_varlink *link, sd_json_variant *parameters, sd_varlink_method_flags_t flags, void *userdata) {
1028
Manager *m = ASSERT_PTR(userdata);
1129
int r;
@@ -22,5 +40,15 @@ int vl_method_list(sd_varlink *link, sd_json_variant *parameters, sd_varlink_met
2240
SD_JSON_BUILD_PAIR_UNSIGNED("value", hashmap_size(m->units)),
2341
SD_JSON_BUILD_PAIR("fields",
2442
SD_JSON_BUILD_OBJECT(
25-
SD_JSON_BUILD_PAIR_STRING("state", "active"))));
43+
SD_JSON_BUILD_PAIR_STRING("state", "active"))),
44+
SD_JSON_BUILD_PAIR_STRING("name", "units"),
45+
SD_JSON_BUILD_PAIR_UNSIGNED("value", get_list_size(m, UNIT_SOCKET)),
46+
SD_JSON_BUILD_PAIR("fields",
47+
SD_JSON_BUILD_OBJECT(
48+
SD_JSON_BUILD_PAIR_STRING("state", "automount"))),
49+
SD_JSON_BUILD_PAIR_STRING("name", "units"),
50+
SD_JSON_BUILD_PAIR_UNSIGNED("value", set_size(m->failed_units)),
51+
SD_JSON_BUILD_PAIR("fields",
52+
SD_JSON_BUILD_OBJECT(
53+
SD_JSON_BUILD_PAIR_STRING("state", "failed"))));
2654
}

0 commit comments

Comments
 (0)