counters introduced, working
This commit is contained in:
parent
2f4aa1c412
commit
dd67b4d5db
1
client.c
1
client.c
@ -305,6 +305,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime, u_int8_t automatic)
|
|||||||
} else
|
} else
|
||||||
fatal("recvfrom");
|
fatal("recvfrom");
|
||||||
}
|
}
|
||||||
|
counters.recv_client_pkts++;
|
||||||
|
|
||||||
if (somsg.msg_flags & MSG_TRUNC) {
|
if (somsg.msg_flags & MSG_TRUNC) {
|
||||||
client_log_error(p, "recvmsg packet", EMSGSIZE);
|
client_log_error(p, "recvmsg packet", EMSGSIZE);
|
||||||
|
28
control.c
28
control.c
@ -198,6 +198,7 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt)
|
|||||||
struct ctl_show_status c_status;
|
struct ctl_show_status c_status;
|
||||||
struct ctl_show_peer c_peer;
|
struct ctl_show_peer c_peer;
|
||||||
struct ctl_show_sensor c_sensor;
|
struct ctl_show_sensor c_sensor;
|
||||||
|
struct ntpd_counters c_counters;
|
||||||
int cnt;
|
int cnt;
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
|
|
||||||
@ -234,6 +235,11 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt)
|
|||||||
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_STATUS, 0, 0, -1,
|
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_STATUS, 0, 0, -1,
|
||||||
&c_status, sizeof (c_status));
|
&c_status, sizeof (c_status));
|
||||||
break;
|
break;
|
||||||
|
case IMSG_CTL_SHOW_COUNTERS:
|
||||||
|
build_show_counters(&c_counters);
|
||||||
|
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_COUNTERS, 0, 0, -1,
|
||||||
|
&c_counters, sizeof (c_counters));
|
||||||
|
break;
|
||||||
case IMSG_CTL_SHOW_PEERS:
|
case IMSG_CTL_SHOW_PEERS:
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
|
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
|
||||||
@ -261,6 +267,10 @@ control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt)
|
|||||||
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_STATUS, 0, 0, -1,
|
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_STATUS, 0, 0, -1,
|
||||||
&c_status, sizeof (c_status));
|
&c_status, sizeof (c_status));
|
||||||
|
|
||||||
|
build_show_counters(&c_counters);
|
||||||
|
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_COUNTERS, 0, 0, -1,
|
||||||
|
&c_counters, sizeof (c_counters));
|
||||||
|
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
|
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
|
||||||
build_show_peer(&c_peer, p);
|
build_show_peer(&c_peer, p);
|
||||||
@ -306,6 +316,24 @@ session_socket_nonblockmode(int fd)
|
|||||||
fatal("fcntl F_SETFL");
|
fatal("fcntl F_SETFL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
init_ntpd_counters(struct ntpd_counters *c)
|
||||||
|
{
|
||||||
|
c->recv_client_pkts = 0;
|
||||||
|
c->recv_server_pkts = 0;
|
||||||
|
c->ignored_server_pkts = 0;
|
||||||
|
c->answered_server_pkts = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
build_show_counters(struct ntpd_counters *cc)
|
||||||
|
{
|
||||||
|
cc->recv_client_pkts = counters.recv_client_pkts;
|
||||||
|
cc->recv_server_pkts = counters.recv_server_pkts;
|
||||||
|
cc->ignored_server_pkts = counters.ignored_server_pkts;
|
||||||
|
cc->answered_server_pkts = counters.answered_server_pkts;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
build_show_status(struct ctl_show_status *cs)
|
build_show_status(struct ctl_show_status *cs)
|
||||||
{
|
{
|
||||||
|
4
ntp.c
4
ntp.c
@ -49,6 +49,8 @@ u_int peer_cnt;
|
|||||||
u_int sensors_cnt;
|
u_int sensors_cnt;
|
||||||
extern u_int constraint_cnt;
|
extern u_int constraint_cnt;
|
||||||
|
|
||||||
|
struct ntpd_counters counters;
|
||||||
|
|
||||||
void ntp_sighdlr(int);
|
void ntp_sighdlr(int);
|
||||||
int ntp_dispatch_imsg(void);
|
int ntp_dispatch_imsg(void);
|
||||||
int ntp_dispatch_imsg_dns(void);
|
int ntp_dispatch_imsg_dns(void);
|
||||||
@ -194,6 +196,8 @@ ntp_main(struct ntpd_conf *nconf, struct passwd *pw, int argc, char **argv)
|
|||||||
TAILQ_INIT(&ctl_conns);
|
TAILQ_INIT(&ctl_conns);
|
||||||
sensor_init();
|
sensor_init();
|
||||||
|
|
||||||
|
init_ntpd_counters(&counters);
|
||||||
|
|
||||||
log_info("ntp engine ready");
|
log_info("ntp engine ready");
|
||||||
|
|
||||||
ctl_cnt = 0;
|
ctl_cnt = 0;
|
||||||
|
35
ntpd.c
35
ntpd.c
@ -55,6 +55,7 @@ int writefreq(double);
|
|||||||
void ctl_main(int, char*[]);
|
void ctl_main(int, char*[]);
|
||||||
const char *ctl_lookup_option(char *, const char **);
|
const char *ctl_lookup_option(char *, const char **);
|
||||||
void show_status_msg(struct imsg *);
|
void show_status_msg(struct imsg *);
|
||||||
|
void show_counters_msg(struct imsg *);
|
||||||
void show_peer_msg(struct imsg *, int);
|
void show_peer_msg(struct imsg *, int);
|
||||||
void show_sensor_msg(struct imsg *, int);
|
void show_sensor_msg(struct imsg *, int);
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ extern u_int constraint_cnt;
|
|||||||
const char *showopt;
|
const char *showopt;
|
||||||
|
|
||||||
static const char *ctl_showopt_list[] = {
|
static const char *ctl_showopt_list[] = {
|
||||||
"peers", "Sensors", "status", "all", NULL
|
"counters", "peers", "Sensors", "status", "all", NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -96,7 +97,7 @@ usage(void)
|
|||||||
|
|
||||||
if (strcmp(__progname, "ntpctl") == 0)
|
if (strcmp(__progname, "ntpctl") == 0)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: ntpctl -s all | peers | Sensors | status\n");
|
"usage: ntpctl -s all | peers | Sensors | status | counters\n");
|
||||||
else
|
else
|
||||||
fprintf(stderr, "usage: %s [-dnv] [-f file]\n",
|
fprintf(stderr, "usage: %s [-dnv] [-f file]\n",
|
||||||
__progname);
|
__progname);
|
||||||
@ -648,6 +649,9 @@ ctl_main(int argc, char *argv[])
|
|||||||
case 'a':
|
case 'a':
|
||||||
action = CTL_SHOW_ALL;
|
action = CTL_SHOW_ALL;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
action = CTL_SHOW_COUNTERS;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (action == -1)
|
if (action == -1)
|
||||||
@ -689,6 +693,10 @@ ctl_main(int argc, char *argv[])
|
|||||||
imsg_compose(ibuf_ctl, IMSG_CTL_SHOW_ALL,
|
imsg_compose(ibuf_ctl, IMSG_CTL_SHOW_ALL,
|
||||||
0, 0, -1, NULL, 0);
|
0, 0, -1, NULL, 0);
|
||||||
break;
|
break;
|
||||||
|
case CTL_SHOW_COUNTERS:
|
||||||
|
imsg_compose(ibuf_ctl, IMSG_CTL_SHOW_COUNTERS,
|
||||||
|
0, 0, -1, NULL, 0);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
errx(1, "invalid action");
|
errx(1, "invalid action");
|
||||||
break; /* NOTREACHED */
|
break; /* NOTREACHED */
|
||||||
@ -716,6 +724,10 @@ ctl_main(int argc, char *argv[])
|
|||||||
show_status_msg(&imsg);
|
show_status_msg(&imsg);
|
||||||
done = 1;
|
done = 1;
|
||||||
break;
|
break;
|
||||||
|
case CTL_SHOW_COUNTERS:
|
||||||
|
show_counters_msg(&imsg);
|
||||||
|
done = 1;
|
||||||
|
break;
|
||||||
case CTL_SHOW_PEERS:
|
case CTL_SHOW_PEERS:
|
||||||
show_peer_msg(&imsg, 0);
|
show_peer_msg(&imsg, 0);
|
||||||
if (imsg.hdr.type ==
|
if (imsg.hdr.type ==
|
||||||
@ -733,6 +745,9 @@ ctl_main(int argc, char *argv[])
|
|||||||
case IMSG_CTL_SHOW_STATUS:
|
case IMSG_CTL_SHOW_STATUS:
|
||||||
show_status_msg(&imsg);
|
show_status_msg(&imsg);
|
||||||
break;
|
break;
|
||||||
|
case IMSG_CTL_SHOW_COUNTERS:
|
||||||
|
show_counters_msg(&imsg);
|
||||||
|
break;
|
||||||
case IMSG_CTL_SHOW_PEERS:
|
case IMSG_CTL_SHOW_PEERS:
|
||||||
show_peer_msg(&imsg, 1);
|
show_peer_msg(&imsg, 1);
|
||||||
break;
|
break;
|
||||||
@ -777,6 +792,22 @@ ctl_lookup_option(char *cmd, const char **list)
|
|||||||
return (item);
|
return (item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
show_counters_msg(struct imsg *imsg)
|
||||||
|
{
|
||||||
|
struct ntpd_counters *ccounters;
|
||||||
|
|
||||||
|
if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(struct ntpd_counters))
|
||||||
|
fatalx("invalid IMSG_CTL_SHOW_STATUS received");
|
||||||
|
|
||||||
|
ccounters = (struct ntpd_counters *)imsg->data;
|
||||||
|
|
||||||
|
printf("%lld packets received as client\n", ccounters->recv_client_pkts);
|
||||||
|
printf("%lld packets received as server\n", ccounters->recv_server_pkts);
|
||||||
|
printf("%lld packets ignored as server\n", ccounters->ignored_server_pkts);
|
||||||
|
printf("%lld packets answered as server\n", ccounters->answered_server_pkts);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
show_status_msg(struct imsg *imsg)
|
show_status_msg(struct imsg *imsg)
|
||||||
{
|
{
|
||||||
|
14
ntpd.h
14
ntpd.h
@ -254,6 +254,15 @@ struct ntpd_conf {
|
|||||||
int tmpfail;
|
int tmpfail;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ntpd_counters {
|
||||||
|
u_int64_t recv_client_pkts;
|
||||||
|
u_int64_t recv_server_pkts;
|
||||||
|
u_int64_t ignored_server_pkts;
|
||||||
|
u_int64_t answered_server_pkts;
|
||||||
|
};
|
||||||
|
|
||||||
|
void init_ntpd_counters(struct ntpd_counters *c);
|
||||||
|
|
||||||
struct ctl_show_status {
|
struct ctl_show_status {
|
||||||
time_t constraint_median;
|
time_t constraint_median;
|
||||||
time_t constraint_last;
|
time_t constraint_last;
|
||||||
@ -316,6 +325,8 @@ enum imsg_type {
|
|||||||
IMSG_CTL_SHOW_PEERS_END,
|
IMSG_CTL_SHOW_PEERS_END,
|
||||||
IMSG_CTL_SHOW_SENSORS,
|
IMSG_CTL_SHOW_SENSORS,
|
||||||
IMSG_CTL_SHOW_SENSORS_END,
|
IMSG_CTL_SHOW_SENSORS_END,
|
||||||
|
IMSG_CTL_SHOW_COUNTERS,
|
||||||
|
IMSG_CTL_SHOW_COUNTERS_END,
|
||||||
IMSG_CTL_SHOW_ALL,
|
IMSG_CTL_SHOW_ALL,
|
||||||
IMSG_CTL_SHOW_ALL_END,
|
IMSG_CTL_SHOW_ALL_END,
|
||||||
IMSG_SYNCED,
|
IMSG_SYNCED,
|
||||||
@ -327,6 +338,7 @@ enum ctl_actions {
|
|||||||
CTL_SHOW_STATUS,
|
CTL_SHOW_STATUS,
|
||||||
CTL_SHOW_PEERS,
|
CTL_SHOW_PEERS,
|
||||||
CTL_SHOW_SENSORS,
|
CTL_SHOW_SENSORS,
|
||||||
|
CTL_SHOW_COUNTERS,
|
||||||
CTL_SHOW_ALL
|
CTL_SHOW_ALL
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -344,6 +356,7 @@ time_t scale_interval(time_t);
|
|||||||
time_t error_interval(void);
|
time_t error_interval(void);
|
||||||
extern struct ntpd_conf *conf;
|
extern struct ntpd_conf *conf;
|
||||||
extern struct ctl_conns ctl_conns;
|
extern struct ctl_conns ctl_conns;
|
||||||
|
extern struct ntpd_counters counters;
|
||||||
|
|
||||||
#define SCALE_INTERVAL(x) MAXIMUM(5, (x) / 10)
|
#define SCALE_INTERVAL(x) MAXIMUM(5, (x) / 10)
|
||||||
|
|
||||||
@ -428,6 +441,7 @@ struct ctl_conn *control_connbyfd(int);
|
|||||||
int control_close(int);
|
int control_close(int);
|
||||||
int control_dispatch_msg(struct pollfd *, u_int *);
|
int control_dispatch_msg(struct pollfd *, u_int *);
|
||||||
void session_socket_nonblockmode(int);
|
void session_socket_nonblockmode(int);
|
||||||
|
void build_show_counters(struct ntpd_counters *);
|
||||||
void build_show_status(struct ctl_show_status *);
|
void build_show_status(struct ctl_show_status *);
|
||||||
void build_show_peer(struct ctl_show_peer *,
|
void build_show_peer(struct ctl_show_peer *,
|
||||||
struct ntp_peer *);
|
struct ntp_peer *);
|
||||||
|
11
server.c
11
server.c
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "ntpd.h"
|
#include "ntpd.h"
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
|
setup_listeners(struct servent *se, struct ntpd_conf *lconf, u_int *cnt)
|
||||||
{
|
{
|
||||||
@ -169,11 +170,14 @@ server_dispatch(int fd, struct ntpd_conf *lconf)
|
|||||||
} else
|
} else
|
||||||
fatal("recvfrom");
|
fatal("recvfrom");
|
||||||
}
|
}
|
||||||
|
counters.recv_server_pkts++;
|
||||||
|
|
||||||
rectime = gettime_corrected();
|
rectime = gettime_corrected();
|
||||||
|
|
||||||
if (ntp_getmsg((struct sockaddr *)&fsa, buf, size, &query) == -1)
|
if (ntp_getmsg((struct sockaddr *)&fsa, buf, size, &query) == -1) {
|
||||||
|
counters.ignored_server_pkts++;
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
memset(&reply, 0, sizeof(reply));
|
memset(&reply, 0, sizeof(reply));
|
||||||
if (lconf->status.synced)
|
if (lconf->status.synced)
|
||||||
@ -185,8 +189,10 @@ server_dispatch(int fd, struct ntpd_conf *lconf)
|
|||||||
reply.status |= MODE_SERVER;
|
reply.status |= MODE_SERVER;
|
||||||
else if ((query.status & MODEMASK) == MODE_SYM_ACT)
|
else if ((query.status & MODEMASK) == MODE_SYM_ACT)
|
||||||
reply.status |= MODE_SYM_PAS;
|
reply.status |= MODE_SYM_PAS;
|
||||||
else /* ignore packets of different type (e.g. bcast) */
|
else { /* ignore packets of different type (e.g. bcast) */
|
||||||
|
counters.ignored_server_pkts++;
|
||||||
return (0);
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
reply.stratum = lconf->status.stratum;
|
reply.stratum = lconf->status.stratum;
|
||||||
reply.ppoll = query.ppoll;
|
reply.ppoll = query.ppoll;
|
||||||
@ -199,5 +205,6 @@ server_dispatch(int fd, struct ntpd_conf *lconf)
|
|||||||
reply.refid = lconf->status.refid;
|
reply.refid = lconf->status.refid;
|
||||||
|
|
||||||
ntp_sendmsg(fd, (struct sockaddr *)&fsa, &reply);
|
ntp_sendmsg(fd, (struct sockaddr *)&fsa, &reply);
|
||||||
|
counters.answered_server_pkts++;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user