Projet

Général

Profil

Révision e527db57

IDe527db57a53d6456a68e3512e7f5aa2f222e07f2
Parent c594a164
Enfant 44d57dcb

Ajouté par Pierre-Alain TORET il y a plus de 7 ans

Improve plugins call to status and few other fixes

Signed-off-by: Pierre-Alain TORET <>

Voir les différences:

plugins/syncthing/syncthing_
1
#!/usr/bin/env sh
1
#!/bin/sh
2 2
# -*- sh -*-
3 3
: <<=cut
4 4
=head1 NAME
......
34 34
MIT
35 35
=cut
36 36

  
37
getstatus() {
38
    "$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/status"
39
}
40

  
37 41
cpu() {
38 42
    case $1 in
39 43
        config)
......
46 50
EOM
47 51
            exit 0;;
48 52
        *)
49
			CPU=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.cpuPercent')
50
            printf "syncthing_cpu.value %s\\n" "$CPU"
53
            STATUS=$(getstatus)
54
			CPU=$(echo "$STATUS" | "$JQ" '.cpuPercent')
55
            printf "syncthing_cpu.value %s\n" "$CPU"
51 56
    esac
52 57
}
53 58

  
......
67 72
EOM
68 73
            exit 0;;
69 74
	    *)
70
            STATUS=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status)
71
            ALL=$(echo "$STATUS" | $JQ '.alloc')
72
            SYS=$(echo "$STATUS" | $JQ '.sys')
73
            printf "syncthing_mem_all.value %s\\n" "$ALL"
74
            printf "syncthing_mem_sys.value %s\\n" "$SYS"
75
            STATUS=$(getstatus)
76
            ALL=$(echo "$STATUS" | "$JQ" '.alloc')
77
            SYS=$(echo "$STATUS" | "$JQ" '.sys')
78
            printf "syncthing_mem_all.value %s\n" "$ALL"
79
            printf "syncthing_mem_sys.value %s\n" "$SYS"
75 80
    esac
76 81
}
77 82

  
......
86 91
EOM
87 92
            exit 0;;
88 93
        *)
89
            UPTIME=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.uptime')
90
            printf "syncthing_uptime.value %s\\n" "$UPTIME"
94
            STATUS=$(getstatus)
95
            UPTIME=$(echo "$STATUS" | "$JQ" '.uptime')
96
            printf "syncthing_uptime.value %s\n" "$UPTIME"
91 97
    esac
92 98
}
93 99

  
......
102 108
EOM
103 109
            exit 0;;
104 110
        *)
105
            GOROUTINES=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/status | $JQ '.goroutines')
106
            printf "syncthing_goroutine.value %s\\n" "$GOROUTINES"
111
            STATUS=$(getstatus)
112
            GOROUTINES=$(echo "$STATUS" | "$JQ" '.goroutines')
113
            printf "syncthing_goroutine.value %s\n" "$GOROUTINES"
107 114
    esac
108 115
}
109 116

  
......
127 134
EOM
128 135
            exit 0;;
129 136
	    *)
130
            CONNECTIONS=$($CURL -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto"://"$syncthing_host":"$syncthing_port"/rest/system/connections)
131
            IBT=$(echo "$CONNECTIONS" | $JQ '.total | .inBytesTotal')
132
            OBT=$(echo "$CONNECTIONS" | $JQ '.total | .outBytesTotal')
137
            CONNECTIONS=$("$CURL" -s -X GET -H "X-API-Key: $syncthing_apikey" "$syncthing_proto://$syncthing_host:$syncthing_port/rest/system/connections")
138
            IBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .inBytesTotal')
139
            OBT=$(echo "$CONNECTIONS" | "$JQ" '.total | .outBytesTotal')
133 140
            printf "syncthing_transfer_up.value %s\\n" "$IBT"
134 141
            printf "syncthing_transfer_down.value %s\\n" "$OBT"
135 142
    esac

Formats disponibles : Unified diff