@@ -78,6 +78,7 @@ typedef struct {
78
78
ngx_pid_t owner ;
79
79
80
80
ngx_msec_t access_time ;
81
+ ngx_msec_t last_event_time ;
81
82
82
83
ngx_uint_t fall_count ;
83
84
ngx_uint_t rise_count ;
@@ -805,6 +806,12 @@ static ngx_check_status_command_t ngx_check_status_commands[] = {
805
806
};
806
807
807
808
809
+ static char * week [] = { "Sun" , "Mon" , "Tue" , "Wed" , "Thu" , "Fri" , "Sat" };
810
+ static char * months [] = { "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" ,
811
+ "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec"
812
+ };
813
+
814
+
808
815
static ngx_uint_t ngx_http_upstream_check_shm_generation = 0 ;
809
816
static ngx_http_upstream_check_peers_t * check_peers_ctx = NULL ;
810
817
@@ -2583,8 +2590,8 @@ ngx_http_upstream_check_status_update(ngx_http_upstream_check_peer_t *peer,
2583
2590
} else {
2584
2591
peer -> shm -> rise_count ++ ;
2585
2592
peer -> shm -> fall_count = 0 ;
2586
- if (peer -> shm -> down && peer -> shm -> rise_count >= ucscf -> rise_count ) {
2587
- peer -> shm -> down = 0 ;
2593
+ if (peer -> shm -> rise_count >= ucscf -> rise_count && peer -> shm -> down == 1 && ngx_atomic_cmp_set ( & peer -> shm -> down , 1 , 0 ) ) {
2594
+ peer -> shm -> last_event_time = ngx_current_msec ;
2588
2595
ngx_log_error (NGX_LOG_ERR , ngx_cycle -> log , 0 ,
2589
2596
"enable check peer: %V, raise: %ui/%ui" ,
2590
2597
& peer -> check_peer_addr -> name ,
@@ -2594,8 +2601,8 @@ ngx_http_upstream_check_status_update(ngx_http_upstream_check_peer_t *peer,
2594
2601
} else {
2595
2602
peer -> shm -> rise_count = 0 ;
2596
2603
peer -> shm -> fall_count ++ ;
2597
- if (! peer -> shm -> down && peer -> shm -> fall_count >= ucscf -> fall_count ) {
2598
- peer -> shm -> down = 1 ;
2604
+ if (peer -> shm -> fall_count >= ucscf -> fall_count && peer -> shm -> down == 0 && ngx_atomic_cmp_set ( & peer -> shm -> down , 0 , 1 ) ) {
2605
+ peer -> shm -> last_event_time = ngx_current_msec ;
2599
2606
ngx_log_error (NGX_LOG_ERR , ngx_cycle -> log , 0 ,
2600
2607
"disable check peer: %V, fall: %ui/%ui" ,
2601
2608
& peer -> check_peer_addr -> name ,
@@ -2952,11 +2959,22 @@ ngx_http_upstream_check_status_html_format(ngx_buf_t *b,
2952
2959
" <th>Fall counts</th>\n"
2953
2960
" <th>Check type</th>\n"
2954
2961
" <th>Check port</th>\n"
2962
+ " <th>Uptime or First failure since</th>\n"
2963
+ " <th>Elapse in seconds</th>\n"
2955
2964
" </tr>\n" ,
2956
2965
count , ngx_http_upstream_check_shm_generation );
2957
2966
2958
2967
for (i = 0 ; i < peers -> peers .nelts ; i ++ ) {
2959
2968
2969
+ u_char event_time_str [sizeof ("Mon 28 Sep 1970 06:00:00 UTC" )];
2970
+ ngx_tm_t tm ;
2971
+ ngx_gmtime (peer [i ].shm -> last_event_time / 1000 , & tm );
2972
+ (void ) ngx_sprintf (event_time_str ,
2973
+ "%s %02d %s %4d %02d:%02d:%02d UTC" ,
2974
+ week [tm .ngx_tm_wday ], tm .ngx_tm_mday ,
2975
+ months [tm .ngx_tm_mon - 1 ], tm .ngx_tm_year ,
2976
+ tm .ngx_tm_hour , tm .ngx_tm_min , tm .ngx_tm_sec );
2977
+
2960
2978
if (flag & NGX_CHECK_STATUS_DOWN ) {
2961
2979
2962
2980
if (!peer [i ].shm -> down ) {
@@ -2980,6 +2998,8 @@ ngx_http_upstream_check_status_html_format(ngx_buf_t *b,
2980
2998
" <td>%ui</td>\n"
2981
2999
" <td>%V</td>\n"
2982
3000
" <td>%ui</td>\n"
3001
+ " <td>%s</td>\n"
3002
+ " <td>%d</td>\n"
2983
3003
" </tr>\n" ,
2984
3004
peer [i ].shm -> down ? " bgcolor=\"#FF0000\"" : "" ,
2985
3005
i ,
@@ -2989,7 +3009,9 @@ ngx_http_upstream_check_status_html_format(ngx_buf_t *b,
2989
3009
peer [i ].shm -> rise_count ,
2990
3010
peer [i ].shm -> fall_count ,
2991
3011
& peer [i ].conf -> check_type_conf -> name ,
2992
- peer [i ].conf -> port );
3012
+ peer [i ].conf -> port ,
3013
+ event_time_str ,
3014
+ (int )((ngx_current_msec - peer [i ].shm -> last_event_time ) / 1000 ));
2993
3015
}
2994
3016
2995
3017
b -> last = ngx_snprintf (b -> last , b -> end - b -> last ,
@@ -3008,6 +3030,15 @@ ngx_http_upstream_check_status_csv_format(ngx_buf_t *b,
3008
3030
peer = peers -> peers .elts ;
3009
3031
for (i = 0 ; i < peers -> peers .nelts ; i ++ ) {
3010
3032
3033
+ u_char event_time_str [sizeof ("Mon 28 Sep 1970 06:00:00 UTC" )];
3034
+ ngx_tm_t tm ;
3035
+ ngx_gmtime (peer [i ].shm -> last_event_time / 1000 , & tm );
3036
+ (void ) ngx_sprintf (event_time_str ,
3037
+ "%s %02d %s %4d %02d:%02d:%02d UTC" ,
3038
+ week [tm .ngx_tm_wday ], tm .ngx_tm_mday ,
3039
+ months [tm .ngx_tm_mon - 1 ], tm .ngx_tm_year ,
3040
+ tm .ngx_tm_hour , tm .ngx_tm_min , tm .ngx_tm_sec );
3041
+
3011
3042
if (flag & NGX_CHECK_STATUS_DOWN ) {
3012
3043
3013
3044
if (!peer [i ].shm -> down ) {
@@ -3022,15 +3053,17 @@ ngx_http_upstream_check_status_csv_format(ngx_buf_t *b,
3022
3053
}
3023
3054
3024
3055
b -> last = ngx_snprintf (b -> last , b -> end - b -> last ,
3025
- "%ui,%V,%V,%s,%ui,%ui,%V,%ui\n" ,
3056
+ "%ui,%V,%V,%s,%ui,%ui,%V,%ui,%s,%d \n" ,
3026
3057
i ,
3027
3058
peer [i ].upstream_name ,
3028
3059
& peer [i ].peer_addr -> name ,
3029
3060
peer [i ].shm -> down ? "down" : "up" ,
3030
3061
peer [i ].shm -> rise_count ,
3031
3062
peer [i ].shm -> fall_count ,
3032
3063
& peer [i ].conf -> check_type_conf -> name ,
3033
- peer [i ].conf -> port );
3064
+ peer [i ].conf -> port ,
3065
+ event_time_str ,
3066
+ (int )((ngx_current_msec - peer [i ].shm -> last_event_time ) / 1000 ));
3034
3067
}
3035
3068
}
3036
3069
@@ -3073,6 +3106,15 @@ ngx_http_upstream_check_status_json_format(ngx_buf_t *b,
3073
3106
last = peers -> peers .nelts - 1 ;
3074
3107
for (i = 0 ; i < peers -> peers .nelts ; i ++ ) {
3075
3108
3109
+ u_char event_time_str [sizeof ("Mon 28 Sep 1970 06:00:00 UTC" )];
3110
+ ngx_tm_t tm ;
3111
+ ngx_gmtime (peer [i ].shm -> last_event_time / 1000 , & tm );
3112
+ (void ) ngx_sprintf (event_time_str ,
3113
+ "%s %02d %s %4d %02d:%02d:%02d UTC" ,
3114
+ week [tm .ngx_tm_wday ], tm .ngx_tm_mday ,
3115
+ months [tm .ngx_tm_mon - 1 ], tm .ngx_tm_year ,
3116
+ tm .ngx_tm_hour , tm .ngx_tm_min , tm .ngx_tm_sec );
3117
+
3076
3118
if (flag & NGX_CHECK_STATUS_DOWN ) {
3077
3119
3078
3120
if (!peer [i ].shm -> down ) {
@@ -3094,7 +3136,9 @@ ngx_http_upstream_check_status_json_format(ngx_buf_t *b,
3094
3136
"\"rise\": %ui, "
3095
3137
"\"fall\": %ui, "
3096
3138
"\"type\": \"%V\", "
3097
- "\"port\": %ui}"
3139
+ "\"port\": %ui, "
3140
+ "\"since\": \"%s\", "
3141
+ "\"elapse\": %d }"
3098
3142
"%s\n" ,
3099
3143
i ,
3100
3144
peer [i ].upstream_name ,
@@ -3104,6 +3148,8 @@ ngx_http_upstream_check_status_json_format(ngx_buf_t *b,
3104
3148
peer [i ].shm -> fall_count ,
3105
3149
& peer [i ].conf -> check_type_conf -> name ,
3106
3150
peer [i ].conf -> port ,
3151
+ event_time_str ,
3152
+ (int )((ngx_current_msec - peer [i ].shm -> last_event_time ) / 1000 ),
3107
3153
(i == last ) ? "" : "," );
3108
3154
}
3109
3155
0 commit comments