| 1 |
/** |
| 2 |
* collectd - src/slurm.c |
| 3 |
* Copyright (C) 2018 Pablo Llopis |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify it |
| 6 |
* under the terms of the GNU General Public License as published by the |
| 7 |
* Free Software Foundation; only version 2 of the License is applicable. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, but |
| 10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License along |
| 15 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 16 |
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 |
* |
| 18 |
* Authors: |
| 19 |
* Pablo Llopis <pablo.llopis at gmail.com> |
| 20 |
**/ |
| 21 |
|
| 22 |
#define _DEFAULT_SOURCE |
| 23 |
#define _BSD_SOURCE |
| 24 |
|
| 25 |
#include "collectd.h" |
| 26 |
|
| 27 |
#include "plugin.h" |
| 28 |
#include "utils/common/common.h" |
| 29 |
|
| 30 |
#include <slurm/slurm.h> |
| 31 |
#include <slurm/slurm_errno.h> |
| 32 |
#include <stdio.h> |
| 33 |
#include <stdlib.h> |
| 34 |
#include <string.h> |
| 35 |
#include <sys/types.h> |
| 36 |
|
| 37 |
#define PLUGIN_NAME "slurm" |
| 38 |
#define PART_NAME_SIZE 128 |
| 39 |
|
| 40 |
/* this function declaration is missing in slurm.h */ |
| 41 |
extern void slurm_free_stats_response_msg(stats_info_response_msg_t *msg); |
| 42 |
|
| 43 |
enum slurm_node_states { |
| 44 |
MAINT_NONRESP, |
| 45 |
MAINT, |
| 46 |
REBOOT_NONRESP, |
| 47 |
REBOOT, |
| 48 |
DRAINING_MAINT, |
| 49 |
DRAINING_REBOOT, |
| 50 |
DRAINING_POWERUP, |
| 51 |
DRAINING_POWERDOWN, |
| 52 |
DRAINING_NONRESP, |
| 53 |
DRAINING, |
| 54 |
DRAINED_MAINT, |
| 55 |
DRAINED_REBOOT, |
| 56 |
DRAINED_POWERUP, |
| 57 |
DRAINED_POWERDOWN, |
| 58 |
DRAINED_NONRESP, |
| 59 |
DRAINED, |
| 60 |
FAILING_NONRESP, |
| 61 |
FAILING, |
| 62 |
FAIL_NONRESP, |
| 63 |
FAIL, |
| 64 |
CANCEL_REBOOT, |
| 65 |
POWER_DOWN, |
| 66 |
POWER_UP, |
| 67 |
DOWN_MAINT, |
| 68 |
DOWN_REBOOT, |
| 69 |
DOWN_POWERUP, |
| 70 |
DOWN_POWERDOWN, |
| 71 |
DOWN_NONRESP, |
| 72 |
DOWN, |
| 73 |
ALLOCATED_MAINT, |
| 74 |
ALLOCATED_REBOOT, |
| 75 |
ALLOCATED_POWERUP, |
| 76 |
ALLOCATED_POWERDOWN, |
| 77 |
ALLOCATED_NONRESP, |
| 78 |
ALLOCATED_COMP, |
| 79 |
ALLOCATED, |
| 80 |
COMPLETING_MAINT, |
| 81 |
COMPLETING_REBOOT, |
| 82 |
COMPLETING_POWERUP, |
| 83 |
COMPLETING_POWERDOWN, |
| 84 |
COMPLETING_NONRESP, |
| 85 |
COMPLETING, |
| 86 |
IDLE_MAINT, |
| 87 |
IDLE_REBOOT, |
| 88 |
IDLE_POWERUP, |
| 89 |
IDLE_POWERDOWN, |
| 90 |
IDLE_NONRESP, |
| 91 |
PERFCTRS, |
| 92 |
RESERVED, |
| 93 |
IDLE, |
| 94 |
MIXED_MAINT, |
| 95 |
MIXED_REBOOT, |
| 96 |
MIXED_POWERUP, |
| 97 |
MIXED_POWERDOWN, |
| 98 |
MIXED_NONRESP, |
| 99 |
MIXED, |
| 100 |
FUTURE_MAINT, |
| 101 |
FUTURE_REBOOT, |
| 102 |
FUTURE_POWERUP, |
| 103 |
FUTURE_POWERDOWN, |
| 104 |
FUTURE_NONRESP, |
| 105 |
FUTURE, |
| 106 |
RESUME, |
| 107 |
UNKNOWN_NONRESP, |
| 108 |
UNKNOWN, |
| 109 |
UNKNOWN2 |
| 110 |
}; |
| 111 |
|
| 112 |
char *node_state_names[] = {"MAINT_NONRESP", |
| 113 |
"MAINT", |
| 114 |
"REBOOT_NONRESP", |
| 115 |
"REBOOT", |
| 116 |
"DRAINING_MAINT", |
| 117 |
"DRAINING_REBOOT", |
| 118 |
"DRAINING_POWERUP", |
| 119 |
"DRAINING_POWERDOWN", |
| 120 |
"DRAINING_NONRESP", |
| 121 |
"DRAINING", |
| 122 |
"DRAINED_MAINT", |
| 123 |
"DRAINED_REBOOT", |
| 124 |
"DRAINED_POWERUP", |
| 125 |
"DRAINED_POWERDOWN", |
| 126 |
"DRAINED_NONRESP", |
| 127 |
"DRAINED", |
| 128 |
"FAILING_NONRESP", |
| 129 |
"FAILING", |
| 130 |
"FAIL_NONRESP", |
| 131 |
"FAIL", |
| 132 |
"CANCEL_REBOOT", |
| 133 |
"POWER_DOWN", |
| 134 |
"POWER_UP", |
| 135 |
"DOWN_MAINT", |
| 136 |
"DOWN_REBOOT", |
| 137 |
"DOWN_POWERUP", |
| 138 |
"DOWN_POWERDOWN", |
| 139 |
"DOWN_NONRESP", |
| 140 |
"DOWN", |
| 141 |
"ALLOCATED_MAINT", |
| 142 |
"ALLOCATED_REBOOT", |
| 143 |
"ALLOCATED_POWERUP", |
| 144 |
"ALLOCATED_POWERDOWN", |
| 145 |
"ALLOCATED_NONRESP", |
| 146 |
"ALLOCATED_COMP", |
| 147 |
"ALLOCATED", |
| 148 |
"COMPLETING_MAINT", |
| 149 |
"COMPLETING_REBOOT", |
| 150 |
"COMPLETING_POWERUP", |
| 151 |
"COMPLETING_POWERDOWN", |
| 152 |
"COMPLETING_NONRESP", |
| 153 |
"COMPLETING", |
| 154 |
"IDLE_MAINT", |
| 155 |
"IDLE_REBOOT", |
| 156 |
"IDLE_POWERUP", |
| 157 |
"IDLE_POWERDOWN", |
| 158 |
"IDLE_NONRESP", |
| 159 |
"PERFCTRS", |
| 160 |
"RESERVED", |
| 161 |
"IDLE", |
| 162 |
"MIXED_MAINT", |
| 163 |
"MIXED_REBOOT", |
| 164 |
"MIXED_POWERUP", |
| 165 |
"MIXED_POWERDOWN", |
| 166 |
"MIXED_NONRESP", |
| 167 |
"MIXED", |
| 168 |
"FUTURE_MAINT", |
| 169 |
"FUTURE_REBOOT", |
| 170 |
"FUTURE_POWERUP", |
| 171 |
"FUTURE_POWERDOWN", |
| 172 |
"FUTURE_NONRESP", |
| 173 |
"FUTURE", |
| 174 |
"RESUME", |
| 175 |
"UNKNOWN_NONRESP", |
| 176 |
"UNKNOWN", |
| 177 |
"?"}; |
| 178 |
|
| 179 |
/* based on src/common/slurm_protocol_defs.c node_state_string function */ |
| 180 |
uint8_t slurm_node_state(uint32_t inx) { |
| 181 |
int base = (inx & NODE_STATE_BASE); |
| 182 |
bool comp_flag = (inx & NODE_STATE_COMPLETING); |
| 183 |
bool drain_flag = (inx & NODE_STATE_DRAIN); |
| 184 |
bool fail_flag = (inx & NODE_STATE_FAIL); |
| 185 |
bool maint_flag = (inx & NODE_STATE_MAINT); |
| 186 |
bool net_flag = (inx & NODE_STATE_NET); |
| 187 |
bool reboot_flag = (inx & NODE_STATE_REBOOT); |
| 188 |
bool res_flag = (inx & NODE_STATE_RES); |
| 189 |
bool resume_flag = (inx & NODE_RESUME); |
| 190 |
bool no_resp_flag = (inx & NODE_STATE_NO_RESPOND); |
| 191 |
bool power_down_flag = (inx & NODE_STATE_POWER_SAVE); |
| 192 |
bool power_up_flag = (inx & NODE_STATE_POWER_UP); |
| 193 |
|
| 194 |
if (maint_flag) { |
| 195 |
if (drain_flag || (base == NODE_STATE_ALLOCATED) || |
| 196 |
(base == NODE_STATE_DOWN) || (base == NODE_STATE_MIXED)) |
| 197 |
; |
| 198 |
else if (no_resp_flag) |
| 199 |
return MAINT_NONRESP; |
| 200 |
else |
| 201 |
return MAINT; |
| 202 |
} |
| 203 |
if (reboot_flag) { |
| 204 |
if ((base == NODE_STATE_ALLOCATED) || (base == NODE_STATE_MIXED)) |
| 205 |
; |
| 206 |
else if (no_resp_flag) |
| 207 |
return REBOOT_NONRESP; |
| 208 |
else |
| 209 |
return REBOOT; |
| 210 |
} |
| 211 |
if (drain_flag) { |
| 212 |
if (comp_flag || (base == NODE_STATE_ALLOCATED) || |
| 213 |
(base == NODE_STATE_MIXED)) { |
| 214 |
if (maint_flag) |
| 215 |
return DRAINING_MAINT; |
| 216 |
if (reboot_flag) |
| 217 |
return DRAINING_REBOOT; |
| 218 |
if (power_up_flag) |
| 219 |
return DRAINING_POWERUP; |
| 220 |
if (power_down_flag) |
| 221 |
return DRAINING_POWERDOWN; |
| 222 |
if (no_resp_flag) |
| 223 |
return DRAINING_NONRESP; |
| 224 |
return DRAINING; |
| 225 |
} else { |
| 226 |
if (maint_flag) |
| 227 |
return DRAINED_MAINT; |
| 228 |
if (reboot_flag) |
| 229 |
return DRAINED_REBOOT; |
| 230 |
if (power_up_flag) |
| 231 |
return DRAINED_POWERUP; |
| 232 |
if (power_down_flag) |
| 233 |
return DRAINED_POWERDOWN; |
| 234 |
if (no_resp_flag) |
| 235 |
return DRAINED_NONRESP; |
| 236 |
return DRAINED; |
| 237 |
} |
| 238 |
} |
| 239 |
if (fail_flag) { |
| 240 |
if (comp_flag || (base == NODE_STATE_ALLOCATED)) { |
| 241 |
if (no_resp_flag) |
| 242 |
return FAILING_NONRESP; |
| 243 |
return FAILING; |
| 244 |
} else { |
| 245 |
if (no_resp_flag) |
| 246 |
return FAIL_NONRESP; |
| 247 |
return FAIL; |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
if (inx == NODE_STATE_CANCEL_REBOOT) |
| 252 |
return CANCEL_REBOOT; |
| 253 |
if (inx == NODE_STATE_POWER_SAVE) |
| 254 |
return POWER_DOWN; |
| 255 |
if (inx == NODE_STATE_POWER_UP) |
| 256 |
return POWER_UP; |
| 257 |
if (base == NODE_STATE_DOWN) { |
| 258 |
if (maint_flag) |
| 259 |
return DOWN_MAINT; |
| 260 |
if (reboot_flag) |
| 261 |
return DOWN_REBOOT; |
| 262 |
if (power_up_flag) |
| 263 |
return DOWN_POWERUP; |
| 264 |
if (power_down_flag) |
| 265 |
return DOWN_POWERDOWN; |
| 266 |
if (no_resp_flag) |
| 267 |
return DOWN_NONRESP; |
| 268 |
return DOWN; |
| 269 |
} |
| 270 |
|
| 271 |
if (base == NODE_STATE_ALLOCATED) { |
| 272 |
if (maint_flag) |
| 273 |
return ALLOCATED_MAINT; |
| 274 |
if (reboot_flag) |
| 275 |
return ALLOCATED_REBOOT; |
| 276 |
if (power_up_flag) |
| 277 |
return ALLOCATED_POWERUP; |
| 278 |
if (power_down_flag) |
| 279 |
return ALLOCATED_POWERDOWN; |
| 280 |
if (no_resp_flag) |
| 281 |
return ALLOCATED_NONRESP; |
| 282 |
if (comp_flag) |
| 283 |
return ALLOCATED_COMP; |
| 284 |
return ALLOCATED; |
| 285 |
} |
| 286 |
if (comp_flag) { |
| 287 |
if (maint_flag) |
| 288 |
return COMPLETING_MAINT; |
| 289 |
if (reboot_flag) |
| 290 |
return COMPLETING_REBOOT; |
| 291 |
if (power_up_flag) |
| 292 |
return COMPLETING_POWERUP; |
| 293 |
if (power_down_flag) |
| 294 |
return COMPLETING_POWERDOWN; |
| 295 |
if (no_resp_flag) |
| 296 |
return COMPLETING_NONRESP; |
| 297 |
return COMPLETING; |
| 298 |
} |
| 299 |
if (base == NODE_STATE_IDLE) { |
| 300 |
if (maint_flag) |
| 301 |
return IDLE_MAINT; |
| 302 |
if (reboot_flag) |
| 303 |
return IDLE_REBOOT; |
| 304 |
if (power_up_flag) |
| 305 |
return IDLE_POWERUP; |
| 306 |
if (power_down_flag) |
| 307 |
return IDLE_POWERDOWN; |
| 308 |
if (no_resp_flag) |
| 309 |
return IDLE_NONRESP; |
| 310 |
if (net_flag) |
| 311 |
return PERFCTRS; |
| 312 |
if (res_flag) |
| 313 |
return RESERVED; |
| 314 |
return IDLE; |
| 315 |
} |
| 316 |
if (base == NODE_STATE_MIXED) { |
| 317 |
if (maint_flag) |
| 318 |
return MIXED_MAINT; |
| 319 |
if (reboot_flag) |
| 320 |
return MIXED_REBOOT; |
| 321 |
if (power_up_flag) |
| 322 |
return MIXED_POWERUP; |
| 323 |
if (power_down_flag) |
| 324 |
return MIXED_POWERDOWN; |
| 325 |
if (no_resp_flag) |
| 326 |
return MIXED_NONRESP; |
| 327 |
return MIXED; |
| 328 |
} |
| 329 |
if (base == NODE_STATE_FUTURE) { |
| 330 |
if (maint_flag) |
| 331 |
return FUTURE_MAINT; |
| 332 |
if (reboot_flag) |
| 333 |
return FUTURE_REBOOT; |
| 334 |
if (power_up_flag) |
| 335 |
return FUTURE_POWERUP; |
| 336 |
if (power_down_flag) |
| 337 |
return FUTURE_POWERDOWN; |
| 338 |
if (no_resp_flag) |
| 339 |
return FUTURE_NONRESP; |
| 340 |
return FUTURE; |
| 341 |
} |
| 342 |
if (resume_flag) |
| 343 |
return RESUME; |
| 344 |
if (base == NODE_STATE_UNKNOWN) { |
| 345 |
if (no_resp_flag) |
| 346 |
return UNKNOWN_NONRESP; |
| 347 |
return UNKNOWN; |
| 348 |
} |
| 349 |
return UNKNOWN2; |
| 350 |
} |
| 351 |
|
| 352 |
#define NUM_NODE_STATES (sizeof(node_state_names) / sizeof(node_state_names[0])) |
| 353 |
|
| 354 |
typedef struct partition_state_st { |
| 355 |
char name[PART_NAME_SIZE]; |
| 356 |
uint32_t nodes_states_count[NUM_NODE_STATES]; |
| 357 |
/* counts jobs states indexed by enum job_states in slurm.h */ |
| 358 |
uint32_t jobs_states_count[JOB_END]; |
| 359 |
} partition_state_t; |
| 360 |
|
| 361 |
/* based on enum job_states from slurm.h */ |
| 362 |
static const char *job_state_names[] = { |
| 363 |
"pending", "running", "suspended", "complete", "cancelled", "failed", |
| 364 |
"timeout", "node_fail", "preempted", "boot_fail", "deadline", "oom", |
| 365 |
}; |
| 366 |
|
| 367 |
static partition_state_t *alloc_partition_states(uint32_t num_partitions, |
| 368 |
partition_info_t *partitions) { |
| 369 |
partition_state_t *partition_states; |
| 370 |
|
| 371 |
partition_states = |
| 372 |
(partition_state_t *)calloc(num_partitions, sizeof(partition_state_t)); |
| 373 |
if (!partition_states) { |
| 374 |
return NULL; |
| 375 |
} |
| 376 |
|
| 377 |
for (int i = 0; i < num_partitions; i++) |
| 378 |
sstrncpy(partition_states[i].name, partitions[i].name, PART_NAME_SIZE); |
| 379 |
|
| 380 |
return partition_states; |
| 381 |
} |
| 382 |
|
| 383 |
static partition_state_t *find_partition(partition_state_t *partitions, |
| 384 |
uint32_t num_partitions, char *name) { |
| 385 |
partition_state_t *part = NULL; |
| 386 |
|
| 387 |
for (int i = 0; i < num_partitions; i++) { |
| 388 |
if (strncmp(name, partitions[i].name, PART_NAME_SIZE) == 0) |
| 389 |
part = &partitions[i]; |
| 390 |
} |
| 391 |
|
| 392 |
return part; |
| 393 |
} |
| 394 |
|
| 395 |
static void slurm_submit_gauge(const char *plugin_instance, const char *type, |
| 396 |
const char *type_instance, gauge_t value) { |
| 397 |
value_list_t vl = VALUE_LIST_INIT; |
| 398 |
|
| 399 |
vl.values = &(value_t){.gauge = value}; |
| 400 |
vl.values_len = 1; |
| 401 |
sstrncpy(vl.plugin, PLUGIN_NAME, sizeof(vl.plugin)); |
| 402 |
if (plugin_instance != NULL) |
| 403 |
sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); |
| 404 |
sstrncpy(vl.type, type, sizeof(vl.type)); |
| 405 |
if (type_instance != NULL) |
| 406 |
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); |
| 407 |
|
| 408 |
plugin_dispatch_values(&vl); |
| 409 |
} |
| 410 |
|
| 411 |
static void slurm_submit_derive(const char *plugin_instance, const char *type, |
| 412 |
const char *type_instance, derive_t value) { |
| 413 |
value_list_t vl = VALUE_LIST_INIT; |
| 414 |
|
| 415 |
vl.values = &(value_t){.derive = value}; |
| 416 |
vl.values_len = 1; |
| 417 |
sstrncpy(vl.plugin, PLUGIN_NAME, sizeof(vl.plugin)); |
| 418 |
if (plugin_instance != NULL) |
| 419 |
sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); |
| 420 |
sstrncpy(vl.type, type, sizeof(vl.type)); |
| 421 |
if (type_instance != NULL) |
| 422 |
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance)); |
| 423 |
|
| 424 |
plugin_dispatch_values(&vl); |
| 425 |
} |
| 426 |
|
| 427 |
static void slurm_submit_partition(partition_state_t *partition) { |
| 428 |
for (int i = 0; i < JOB_END; i++) { |
| 429 |
slurm_submit_gauge(partition->name, "slurm_job_state", job_state_names[i], |
| 430 |
partition->jobs_states_count[i]); |
| 431 |
} |
| 432 |
for (int i = 0; i < NUM_NODE_STATES; i++) { |
| 433 |
slurm_submit_gauge(partition->name, "slurm_node_state", node_state_names[i], |
| 434 |
partition->nodes_states_count[i]); |
| 435 |
} |
| 436 |
} |
| 437 |
|
| 438 |
static void slurm_submit_stats(stats_info_response_msg_t *stats_resp) { |
| 439 |
// slurm load stats |
| 440 |
slurm_submit_gauge("slurm_load_stats", "threads", "server_thread_count", |
| 441 |
stats_resp->server_thread_count); |
| 442 |
slurm_submit_gauge("slurm_load_stats", "threads", "agent_thread_count", |
| 443 |
stats_resp->agent_count); |
| 444 |
slurm_submit_gauge("slurm_load_stats", "queue_length", "agent_queue_size", |
| 445 |
stats_resp->agent_queue_size); |
| 446 |
slurm_submit_gauge("slurm_load_stats", "queue_length", "dbd_agent_queue_size", |
| 447 |
stats_resp->dbd_agent_queue_size); |
| 448 |
|
| 449 |
// slurm scheduler stats |
| 450 |
slurm_submit_derive("slurm_sched_stats", "slurm_cycles", "schedule_cycles", |
| 451 |
stats_resp->schedule_cycle_counter); |
| 452 |
slurm_submit_gauge("slurm_sched_stats", "slurm_cycle_last", |
| 453 |
"schedule_cycle_last", stats_resp->schedule_cycle_last); |
| 454 |
slurm_submit_derive("slurm_sched_stats", "slurm_cycle_duration", |
| 455 |
"schedule_cycle_duration", |
| 456 |
stats_resp->schedule_cycle_sum); |
| 457 |
slurm_submit_derive("slurm_sched_stats", "slurm_cycle_depth", |
| 458 |
"schedule_cycle_depth", stats_resp->schedule_cycle_depth); |
| 459 |
slurm_submit_gauge("slurm_sched_stats", "queue_length", |
| 460 |
"schedule_queue_length", stats_resp->schedule_queue_len); |
| 461 |
|
| 462 |
// slurm job stats |
| 463 |
slurm_submit_derive("slurm_jobs_stats", "slurm_job_stats", "submitted", |
| 464 |
stats_resp->jobs_submitted); |
| 465 |
slurm_submit_derive("slurm_jobs_stats", "slurm_job_stats", "started", |
| 466 |
stats_resp->jobs_started); |
| 467 |
slurm_submit_derive("slurm_jobs_stats", "slurm_job_stats", "completed", |
| 468 |
stats_resp->jobs_completed); |
| 469 |
slurm_submit_derive("slurm_jobs_stats", "slurm_job_stats", "canceled", |
| 470 |
stats_resp->jobs_canceled); |
| 471 |
slurm_submit_derive("slurm_jobs_stats", "slurm_job_stats", "failed", |
| 472 |
stats_resp->jobs_failed); |
| 473 |
|
| 474 |
// slurm backfill stats |
| 475 |
slurm_submit_derive("slurm_backfill_stats", "slurm_backfilled_jobs", |
| 476 |
"backfilled_jobs", stats_resp->bf_backfilled_jobs); |
| 477 |
// The field bf_backfilled_pack_jobs was renamed in v20.02 to |
| 478 |
// bf_backfilled_het_jobs (commit #7ff37bfa) |
| 479 |
#if SLURM_VERSION_NUMBER >= SLURM_VERSION_NUM(20, 2, 0) |
| 480 |
slurm_submit_derive("slurm_backfill_stats", "slurm_backfilled_jobs", |
| 481 |
"backfilled_het_jobs", |
| 482 |
stats_resp->bf_backfilled_het_jobs); |
| 483 |
#else |
| 484 |
slurm_submit_derive("slurm_backfill_stats", "slurm_backfilled_jobs", |
| 485 |
"backfilled_pack_jobs", |
| 486 |
stats_resp->bf_backfilled_pack_jobs); |
| 487 |
#endif |
| 488 |
slurm_submit_derive("slurm_backfill_stats", "slurm_cycles", "backfill_cycles", |
| 489 |
stats_resp->bf_cycle_counter); |
| 490 |
slurm_submit_gauge("slurm_backfill_stats", "slurm_cycle_last", |
| 491 |
"last_backfill_cycle", stats_resp->bf_cycle_last); |
| 492 |
slurm_submit_derive("slurm_backfill_stats", "slurm_cycle_duration", |
| 493 |
"backfill_cycle_duration", stats_resp->bf_cycle_sum); |
| 494 |
slurm_submit_gauge("slurm_backfill_stats", "slurm_last_cycle_depth", |
| 495 |
"backfill_last_cycle_depth", stats_resp->bf_last_depth); |
| 496 |
slurm_submit_gauge("slurm_backfill_stats", "slurm_last_cycle_depth", |
| 497 |
"backfill_last_cycle_depth_try", |
| 498 |
stats_resp->bf_last_depth_try); |
| 499 |
slurm_submit_derive("slurm_backfill_stats", "slurm_cycle_depth", |
| 500 |
"backfill_cycle_depth", stats_resp->bf_depth_sum); |
| 501 |
slurm_submit_derive("slurm_backfill_stats", "slurm_cycle_depth", |
| 502 |
"backfill_cycle_depth_try", stats_resp->bf_depth_try_sum); |
| 503 |
slurm_submit_gauge("slurm_backfill_stats", "queue_length", |
| 504 |
"backfill_last_queue_length", stats_resp->bf_queue_len); |
| 505 |
slurm_submit_derive("slurm_backfill_stats", "slurm_queue_length", |
| 506 |
"backfill_queue_length", stats_resp->bf_queue_len_sum); |
| 507 |
} |
| 508 |
|
| 509 |
static int slurm_read(void) { |
| 510 |
job_info_msg_t *job_buffer_ptr = NULL; |
| 511 |
job_info_t *job_ptr; |
| 512 |
partition_info_msg_t *part_buffer_ptr = NULL; |
| 513 |
partition_info_t *part_ptr; |
| 514 |
partition_state_t *partition_states; |
| 515 |
partition_state_t *partition_state; |
| 516 |
node_info_msg_t *node_buffer_ptr = NULL; |
| 517 |
node_info_t *node_ptr; |
| 518 |
stats_info_response_msg_t *stats_resp; |
| 519 |
stats_info_request_msg_t stats_req; |
| 520 |
|
| 521 |
if (slurm_load_jobs((time_t)NULL, &job_buffer_ptr, SHOW_ALL)) { |
| 522 |
ERROR(PLUGIN_NAME ": slurm_load_jobs error"); |
| 523 |
return -1; |
| 524 |
} |
| 525 |
|
| 526 |
if (slurm_load_node((time_t)NULL, &node_buffer_ptr, SHOW_ALL)) { |
| 527 |
slurm_free_job_info_msg(job_buffer_ptr); |
| 528 |
ERROR(PLUGIN_NAME ": slurm_load_node error"); |
| 529 |
return -1; |
| 530 |
} |
| 531 |
|
| 532 |
if (slurm_load_partitions((time_t)NULL, &part_buffer_ptr, 0)) { |
| 533 |
slurm_free_job_info_msg(job_buffer_ptr); |
| 534 |
slurm_free_node_info_msg(node_buffer_ptr); |
| 535 |
ERROR(PLUGIN_NAME ": slurm_load_partitions error"); |
| 536 |
return -1; |
| 537 |
} |
| 538 |
|
| 539 |
stats_req.command_id = STAT_COMMAND_GET; |
| 540 |
if (slurm_get_statistics(&stats_resp, &stats_req)) { |
| 541 |
slurm_free_job_info_msg(job_buffer_ptr); |
| 542 |
slurm_free_node_info_msg(node_buffer_ptr); |
| 543 |
slurm_free_partition_info_msg(part_buffer_ptr); |
| 544 |
ERROR(PLUGIN_NAME ": slurm_get_statistics error"); |
| 545 |
} |
| 546 |
|
| 547 |
/* SLURM APIs provide *non-relational* data about nodes, partitions and jobs. |
| 548 |
* We allocate a data structure that relates all three together, and the |
| 549 |
* following |
| 550 |
* two for loops fill this data structure. The data structure is an array |
| 551 |
* of partition_state_t that holds job and node states. */ |
| 552 |
uint32_t num_partitions = part_buffer_ptr->record_count; |
| 553 |
partition_states = |
| 554 |
alloc_partition_states(num_partitions, part_buffer_ptr->partition_array); |
| 555 |
if (!partition_states) { |
| 556 |
slurm_free_job_info_msg(job_buffer_ptr); |
| 557 |
slurm_free_node_info_msg(node_buffer_ptr); |
| 558 |
slurm_free_partition_info_msg(part_buffer_ptr); |
| 559 |
ERROR(PLUGIN_NAME ": alloc_partition_states"); |
| 560 |
return -1; |
| 561 |
} |
| 562 |
|
| 563 |
/* fill partition_states array with per-partition job state information */ |
| 564 |
for (int i = 0; i < job_buffer_ptr->record_count; i++) { |
| 565 |
job_ptr = &job_buffer_ptr->job_array[i]; |
| 566 |
partition_state = |
| 567 |
find_partition(partition_states, num_partitions, job_ptr->partition); |
| 568 |
if (!partition_state) { |
| 569 |
ERROR(PLUGIN_NAME ": slurm_read: cannot find partition %s from jobid %d" |
| 570 |
" in partition list returned by slurm_load_partitions", |
| 571 |
job_ptr->partition, job_ptr->job_id); |
| 572 |
continue; |
| 573 |
} |
| 574 |
|
| 575 |
uint8_t job_state = job_ptr->job_state & JOB_STATE_BASE; |
| 576 |
partition_state->jobs_states_count[job_state]++; |
| 577 |
} |
| 578 |
|
| 579 |
/* fill partition_states array with per-partition node state information */ |
| 580 |
for (int i = 0; i < part_buffer_ptr->record_count; i++) { |
| 581 |
part_ptr = &part_buffer_ptr->partition_array[i]; |
| 582 |
|
| 583 |
partition_state = |
| 584 |
find_partition(partition_states, num_partitions, part_ptr->name); |
| 585 |
if (!partition_state) { |
| 586 |
ERROR(PLUGIN_NAME ": slurm_read: cannot find partition %s" |
| 587 |
" in partition list returned by slurm_load_partitions", |
| 588 |
part_ptr->name); |
| 589 |
continue; |
| 590 |
} |
| 591 |
|
| 592 |
for (int j = 0; part_ptr->node_inx; j += 2) { |
| 593 |
if (part_ptr->node_inx[j] == -1) |
| 594 |
break; |
| 595 |
for (int k = part_ptr->node_inx[j]; k <= part_ptr->node_inx[j + 1]; k++) { |
| 596 |
node_ptr = &node_buffer_ptr->node_array[k]; |
| 597 |
/* some non-existant nodes (name is NULL) may show up as node_state |
| 598 |
* FUTURE */ |
| 599 |
uint8_t node_state = slurm_node_state(node_ptr->node_state); |
| 600 |
partition_state->nodes_states_count[node_state]++; |
| 601 |
} |
| 602 |
} |
| 603 |
} |
| 604 |
|
| 605 |
for (int i = 0; i < num_partitions; i++) |
| 606 |
slurm_submit_partition(&partition_states[i]); |
| 607 |
|
| 608 |
slurm_submit_stats(stats_resp); |
| 609 |
|
| 610 |
slurm_free_job_info_msg(job_buffer_ptr); |
| 611 |
slurm_free_node_info_msg(node_buffer_ptr); |
| 612 |
slurm_free_partition_info_msg(part_buffer_ptr); |
| 613 |
slurm_free_stats_response_msg(stats_resp); |
| 614 |
free(partition_states); |
| 615 |
return 0; |
| 616 |
} |
| 617 |
|
| 618 |
void module_register(void) { plugin_register_read("slurm", slurm_read); } |