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 # requires 1.4.0 to run with multiple units due to bug before that:
18 # https://github.com/prometheus/node_exporter/pull/2475
21 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
23 if [[ ! $SERVICE_RESULT ]]; then
24 echo "$0: error, no SERVICE_RESULT var."
30 if [[ ! $ser_name ]]; then
31 echo "$0: error, no arg service name passed."
35 dir
=/var
/lib
/prometheus
/node-exporter
36 if [[ ! -e $dir ]]; then
40 f
=$dir/${ser_name}-result.prom
46 # https://www.freedesktop.org/software/systemd/man/systemd.exec.html
47 if [[ $SERVICE_RESULT != success
]]; then
55 count
=$
(( count
+ 1 ))
65 printf 'node_systemd_unit_result_fail_count{name="%s"} %s\n' "$ser_name" "$count" >$ftmp