Files
stethoscope/src/services.h

81 lines
1.6 KiB
C

#ifndef H_SERVICES
#define H_SERVICES
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <string.h>
#include <pthread.h>
#include "../deps/vector/vector.h"
#include "util.h"
enum State { NONE, DOWN, PARTIAL, UP };
struct StatusPeroid;
struct ServerStatus;
struct EndpointStatus;
struct Endpoint;
struct Service;
void report();
void* run_endpoint(void* endpoint);
void queue_report(struct EndpointStatus status);
void load_service(struct Service** self);
uint8_t add_endpoint(struct Service* self, const char* uri);
enum State get_state(struct Service** self);
struct ServerStatus* update_server_status(struct Service** self);
const char* state_text(enum State state);
struct StatusPeroid {
unsigned long time;
Vector server_statuses; // of ServerStatus*
};
struct ServerStatus {
struct Service* service;
Vector endpoint_statuses; // of EndpointStatus*
enum State state;
double ping;
};
struct EndpointStatus {
struct Endpoint* endpoint;
enum State state;
double ping;
};
struct Endpoint {
struct Service* service;
uint8_t enabled;
uint8_t running;
char* scheme;
char* target;
uint16_t port;
uint32_t backoff;
time_t last_check;
enum State last_state;
double last_ping;
Vector status_history;
pthread_t thread;
struct addrinfo* addr;
int sockfd;
int last_errno;
};
struct Service {
char* id;
char* name;
char* text;
Vector endpoints;
enum State last_state;
double average_ping;
uint32_t backoff;
};
#endif