| 129 | } |
| 130 | |
| 131 | int fs_renew_stats(fs_evs *sock, const cJSON *ev) |
| 132 | { |
| 133 | fs_stats stats; |
| 134 | char *s, *end; |
| 135 | |
| 136 | memset(&stats, 0, sizeof stats); |
| 137 | |
| 138 | s = cJSON_GetObjectItem((cJSON *)ev, "Idle-CPU")->valuestring; |
| 139 | stats.id_cpu = strtof(s, &end); |
| 140 | if (*end) { |
| 141 | LM_ERR("bad Idle-CPU: %s\n", s); |
| 142 | return -1; |
| 143 | } |
| 144 | |
| 145 | s = cJSON_GetObjectItem((cJSON *)ev, "Session-Count")->valuestring; |
| 146 | stats.sess = strtol(s, &end, 0); |
| 147 | if (*end) { |
| 148 | LM_ERR("bad Session-Count: %s\n", s); |
| 149 | return -1; |
| 150 | } |
| 151 | |
| 152 | s = cJSON_GetObjectItem((cJSON *)ev, "Max-Sessions")->valuestring; |
| 153 | stats.max_sess = strtol(s, &end, 0); |
| 154 | if (*end) { |
| 155 | LM_ERR("bad Max-Sessions: %s\n", s); |
| 156 | return -1; |
| 157 | } |
| 158 | |
| 159 | stats.valid = 1; |
| 160 | |
| 161 | LM_DBG("FS stats (%s:%d), idle cpu: %.3f, sessions: %d/%d\n%s\n", |
| 162 | sock->host.s, sock->port, stats.id_cpu, stats.sess, stats.max_sess, |
| 163 | sock->handle->last_sr_event->body); |
| 164 | |
| 165 | lock_start_write(sock->stats_lk); |
| 166 | sock->stats = stats; |
| 167 | lock_stop_write(sock->stats_lk); |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | int fs_raise_event(fs_evs *sock, const char *name, const char *body) |
| 173 | { |
no test coverage detected