20e7c9b588cf69c17ca57fda652232934a064b0c
2 # Copyright (C) 2022 Ian Kelling
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
19 if [[ ! $SERVICE_RESULT ]]; then
20 echo "$0: error, no SERVICE_RESULT var."
26 if [[ ! $ser_name ]]; then
27 echo "$0: error, no arg service name passed."
31 dir
=/var
/lib
/prometheus
/node-exporter
32 if [[ ! -e $dir ]]; then
36 # we have to merge files due to this:
37 # https://github.com/prometheus/node_exporter/issues/1885
38 # or else we could put the label in the metric name, but that
40 # Note, i found this https://github.com/hansmi/prometheus-textformat-merge
41 # but it seems overkill.
42 f
=$dir/${ser_name}-result-fail.premerge
48 # https://www.freedesktop.org/software/systemd/man/systemd.exec.html
49 if [[ $SERVICE_RESULT != success
]]; then
57 count
=$
(( count
+ 1 ))
67 printf 'node_systemd_unit_result_fail_count{name="%s"} %s\n' "$ser_name" "$count" >$ftmp
71 finaltmp
=$dir/sysd-result-fail.prom.$$
72 cat $dir/*-result-fail.premerge
>$finaltmp
73 mv $finaltmp $dir/sysd-result-fail.prom