Reworked cli show mem to yang domains
This commit is contained in:
parent
212be7ad57
commit
8901d00e47
6 changed files with 53 additions and 199 deletions
|
|
@ -1423,10 +1423,12 @@ from_client_stats(clixon_handle h,
|
||||||
char *str;
|
char *str;
|
||||||
int modules = 0;
|
int modules = 0;
|
||||||
yang_stmt *yspec;
|
yang_stmt *yspec;
|
||||||
yang_stmt *ymodext;
|
yang_stmt *ymounts;
|
||||||
|
yang_stmt *ydomain;
|
||||||
cxobj *xt = NULL;
|
cxobj *xt = NULL;
|
||||||
int ret;
|
char *name;
|
||||||
int inext;
|
int inext;
|
||||||
|
int inext2;
|
||||||
|
|
||||||
if ((str = xml_find_body(xe, "modules")) != NULL)
|
if ((str = xml_find_body(xe, "modules")) != NULL)
|
||||||
modules = strcmp(str, "true") == 0;
|
modules = strcmp(str, "true") == 0;
|
||||||
|
|
@ -1449,46 +1451,29 @@ from_client_stats(clixon_handle h,
|
||||||
if (clixon_stats_datastore_get(h, "startup", cbret) < 0)
|
if (clixon_stats_datastore_get(h, "startup", cbret) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
cprintf(cbret, "</datastores>");
|
cprintf(cbret, "</datastores>");
|
||||||
/* per module-set, first configuration, then main dbspec, then mountpoints */
|
if ((ymounts = clixon_yang_mounts_get(h)) == NULL){
|
||||||
|
clixon_err(OE_YANG, ENOENT, "Top-level yang mounts not found");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
cprintf(cbret, "<module-sets xmlns=\"%s\">", CLIXON_LIB_NS);
|
cprintf(cbret, "<module-sets xmlns=\"%s\">", CLIXON_LIB_NS);
|
||||||
cprintf(cbret, "<module-set><name>clixon-config</name>");
|
inext = 0;
|
||||||
yspec = clicon_config_yang(h); /* Note switch yspec to config (not data) */
|
while ((ydomain = yn_iter(ymounts, &inext)) != NULL) {
|
||||||
if (clixon_stats_module_get(h, yspec, cbret) < 0)
|
name = yang_argument_get(ydomain);
|
||||||
goto done;
|
/* per module-set, first configuration, then main dbspec, then mountpoints */
|
||||||
if (modules){
|
cprintf(cbret, "<module-set>");
|
||||||
inext = 0;
|
cprintf(cbret, "<name>%s</name>", name);
|
||||||
while ((ym = yn_iter(yspec, &inext)) != NULL) {
|
if (clixon_stats_module_get(h, ydomain, cbret) < 0)
|
||||||
cprintf(cbret, "<module><name>%s</name>", yang_argument_get(ym));
|
|
||||||
if (clixon_stats_module_get(h, ym, cbret) < 0)
|
|
||||||
goto done;
|
|
||||||
cprintf(cbret, "</module>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cprintf(cbret, "</module-set>");
|
|
||||||
cprintf(cbret, "<module-set><name>main</name>");
|
|
||||||
yspec = clicon_dbspec_yang(h);
|
|
||||||
if (clixon_stats_module_get(h, yspec, cbret) < 0)
|
|
||||||
goto done;
|
|
||||||
if (modules){
|
|
||||||
inext = 0;
|
|
||||||
while ((ym = yn_iter(yspec, &inext)) != NULL) {
|
|
||||||
cprintf(cbret, "<module><name>%s</name>", yang_argument_get(ym));
|
|
||||||
if (clixon_stats_module_get(h, ym, cbret) < 0)
|
|
||||||
goto done;
|
|
||||||
cprintf(cbret, "</module>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cprintf(cbret, "</module-set>");
|
|
||||||
/* Mountpoints */
|
|
||||||
if ((ymodext = yang_find(yspec, Y_MODULE, "ietf-yang-schema-mount")) != NULL){
|
|
||||||
if ((ret = xmldb_get0(h, "running", YB_MODULE, NULL, "/", 1, 0, &xt, NULL, NULL)) < 0)
|
|
||||||
goto done;
|
|
||||||
if (ret == 0){
|
|
||||||
clixon_err(OE_DB, 0, "Error when reading from running, unknown error");
|
|
||||||
goto done;
|
goto done;
|
||||||
|
if (modules){
|
||||||
|
inext2 = 0;
|
||||||
|
while ((ym = yn_iter(ydomain, &inext2)) != NULL) {
|
||||||
|
cprintf(cbret, "<module><name>%s</name>", yang_argument_get(ym));
|
||||||
|
if (clixon_stats_module_get(h, ym, cbret) < 0)
|
||||||
|
goto done;
|
||||||
|
cprintf(cbret, "</module>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (xt && yang_schema_mount_statistics(h, xt, modules, cbret) < 0)
|
cprintf(cbret, "</module-set>");
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
cprintf(cbret, "</module-sets>");
|
cprintf(cbret, "</module-sets>");
|
||||||
cprintf(cbret, "</rpc-reply>");
|
cprintf(cbret, "</rpc-reply>");
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,6 @@ You can see which CLISPEC it generates via clixon_cli -D 2:
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <assert.h> // XXX
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
/* cligen */
|
/* cligen */
|
||||||
|
|
|
||||||
|
|
@ -1887,23 +1887,21 @@ cli_show_statistics(clixon_handle h,
|
||||||
size_t sz;
|
size_t sz;
|
||||||
size_t tsz0;
|
size_t tsz0;
|
||||||
size_t tsz;
|
size_t tsz;
|
||||||
yang_stmt *yspec;
|
yang_stmt *ymounts;
|
||||||
cvec *cvv1 = NULL;
|
yang_stmt *ydomain;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
cxobj *xp;
|
cxobj *xp;
|
||||||
char *name;
|
char *name;
|
||||||
cxobj *x;
|
cxobj *x;
|
||||||
uint64_t u64;
|
uint64_t u64;
|
||||||
char *unit;
|
char *unit;
|
||||||
yang_stmt *ymounts;
|
|
||||||
int inext;
|
int inext;
|
||||||
int i;
|
|
||||||
|
|
||||||
if (argv == NULL || (cvec_len(argv) < 1 || cvec_len(argv) > 2)){
|
if (argv == NULL || (cvec_len(argv) < 1 || cvec_len(argv) > 2)){
|
||||||
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend|all) [detail]]");
|
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend|all) [detail]]");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
yspec = clicon_dbspec_yang(h);
|
ydomain = clicon_dbspec_yang(h);
|
||||||
cv = cvec_i(argv, 0);
|
cv = cvec_i(argv, 0);
|
||||||
what = cv_string_get(cv);
|
what = cv_string_get(cv);
|
||||||
if (strcmp(what, "cli") == 0)
|
if (strcmp(what, "cli") == 0)
|
||||||
|
|
@ -1931,67 +1929,29 @@ cli_show_statistics(clixon_handle h,
|
||||||
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
clixon_err(OE_PLUGIN, errno, "cbuf_new");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
if ((ymounts = clixon_yang_mounts_get(h)) == NULL){
|
||||||
|
clixon_err(OE_YANG, ENOENT, "Top-level yang mounts not found");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
if (cli) {
|
if (cli) {
|
||||||
if (!detail) {
|
if (!detail) {
|
||||||
cligen_output(stdout, "%-25s %-10s\n", "YANG", "Mem");
|
cligen_output(stdout, "%-25s %-10s\n", "YANG", "Mem");
|
||||||
}
|
}
|
||||||
nr = 0; sz = 0;
|
inext = 0;
|
||||||
if (yang_stats(yspec, 0, &nr, &sz) < 0)
|
while ((ydomain = yn_iter(ymounts, &inext)) != NULL) {
|
||||||
goto done;
|
name = yang_argument_get(ydomain);
|
||||||
tnr = nr;
|
nr = 0; sz = 0;
|
||||||
tsz = sz;
|
if (yang_stats(ydomain, 0, &nr, &sz) < 0)
|
||||||
if (detail) {
|
|
||||||
cligen_output(stdout, "YANG-top-level-size: %" PRIu64 "\n", sz);
|
|
||||||
cligen_output(stdout, "YANG-top-level-nr: %" PRIu64 "\n", nr);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
translatenumber(sz, &u64, &unit);
|
|
||||||
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "Top-level", u64, unit);
|
|
||||||
}
|
|
||||||
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")) {
|
|
||||||
if ((ymounts = clixon_yang_mounts_get(h)) == NULL){
|
|
||||||
clixon_err(OE_YANG, ENOENT, "Top-level yang mounts not found");
|
|
||||||
goto done;
|
goto done;
|
||||||
|
tnr = nr;
|
||||||
|
tsz = sz;
|
||||||
|
if (detail) {
|
||||||
|
cligen_output(stdout, "YANG-%s-size: %" PRIu64 "\n", name, sz);
|
||||||
|
cligen_output(stdout, "YANG-%s-nr: %" PRIu64 "\n", name, nr);
|
||||||
}
|
}
|
||||||
inext = 0;
|
else{
|
||||||
while ((yspec = yn_iter(ymounts, &inext)) != NULL) {
|
translatenumber(sz, &u64, &unit);
|
||||||
cvv1 = NULL;
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", yang_argument_get(ydomain), u64, unit);
|
||||||
if (yang_keyword_get(yspec) == Y_SPEC &&
|
|
||||||
yang_flag_get(yspec, YANG_FLAG_SPEC_MOUNT) != 0x0 &&
|
|
||||||
(cvv1 = yang_cvec_get(yspec)) != NULL){
|
|
||||||
nr = 0; sz = 0;
|
|
||||||
if (yang_stats(yspec, 0, &nr, &sz) < 0)
|
|
||||||
goto done;
|
|
||||||
tnr += nr;
|
|
||||||
tsz += sz;
|
|
||||||
i = 0;
|
|
||||||
cv = NULL;
|
|
||||||
while ((cv = cvec_each(cvv1, cv)) != NULL) {
|
|
||||||
if (detail){
|
|
||||||
if (i == cvec_len(cvv1)-1) {
|
|
||||||
cligen_output(stdout, "YANG-mount-point-%s-size: %" PRIu64 "\n", cv_name_get(cv), sz);
|
|
||||||
cligen_output(stdout, "YANG-mount-point-%s-nr: %" PRIu64 "\n", cv_name_get(cv), nr);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cligen_output(stdout, "YANG-mount-point-%s-size: shared\n", cv_name_get(cv));
|
|
||||||
cligen_output(stdout, "YANG-mount-point-%s-nr: shared\n", cv_name_get(cv));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (i == cvec_len(cvv1)-1) {
|
|
||||||
if (strlen(cv_name_get(cv)) > 25)
|
|
||||||
cligen_output(stdout, "%s \n %-25s", cv_name_get(cv), "");
|
|
||||||
else
|
|
||||||
cligen_output(stdout, "%-25s", cv_name_get(cv));
|
|
||||||
translatenumber(sz, &u64, &unit);
|
|
||||||
cligen_output(stdout, "%" PRIu64 "%-10s\n", u64, unit);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
cligen_output(stdout, "%s\n", cv_name_get(cv));
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (detail){
|
if (detail){
|
||||||
|
|
@ -2002,6 +1962,9 @@ cli_show_statistics(clixon_handle h,
|
||||||
translatenumber(tsz, &u64, &unit);
|
translatenumber(tsz, &u64, &unit);
|
||||||
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "YANG Total", u64, unit);
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "YANG Total", u64, unit);
|
||||||
}
|
}
|
||||||
|
if (!detail) {
|
||||||
|
cligen_output(stdout, "%-25s\n", "CLIspec");
|
||||||
|
}
|
||||||
tnr0 = tnr;
|
tnr0 = tnr;
|
||||||
tsz0 = tsz;
|
tsz0 = tsz;
|
||||||
tnr = 0;
|
tnr = 0;
|
||||||
|
|
@ -2031,6 +1994,7 @@ cli_show_statistics(clixon_handle h,
|
||||||
translatenumber(tsz0+tsz, &u64, &unit);
|
translatenumber(tsz0+tsz, &u64, &unit);
|
||||||
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "Mem Total", u64, unit);
|
cligen_output(stdout, "%-25s %" PRIu64 "%-10s\n", "Mem Total", u64, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (backend) {
|
if (backend) {
|
||||||
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
cprintf(cb, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||||
|
|
@ -2055,7 +2019,7 @@ cli_show_statistics(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cligen_output(stdout, "%-25s %-10s\n", "XML Datastore", "Mem");
|
cligen_output(stdout, "%-25s %-10s\n", "Datastore", "Mem");
|
||||||
tsz = 0;
|
tsz = 0;
|
||||||
if ((xp = xml_find_type(xret, NULL, "datastores", CX_ELMNT)) != NULL){
|
if ((xp = xml_find_type(xret, NULL, "datastores", CX_ELMNT)) != NULL){
|
||||||
x = NULL;
|
x = NULL;
|
||||||
|
|
@ -2085,9 +2049,10 @@ cli_show_statistics(clixon_handle h,
|
||||||
while ((x = xml_child_each(xp, x, CX_ELMNT)) != NULL) {
|
while ((x = xml_child_each(xp, x, CX_ELMNT)) != NULL) {
|
||||||
if (strcmp(xml_name(x), "module-set") != 0)
|
if (strcmp(xml_name(x), "module-set") != 0)
|
||||||
continue;
|
continue;
|
||||||
|
if ((name = xml_find_body(x, "name")) == NULL)
|
||||||
|
continue;
|
||||||
parse_uint64(xml_find_body(x, "size"), &sz, NULL);
|
parse_uint64(xml_find_body(x, "size"), &sz, NULL);
|
||||||
tsz += sz;
|
tsz += sz;
|
||||||
name = xml_find_body(x, "name");
|
|
||||||
translatenumber(sz, &u64, &unit);
|
translatenumber(sz, &u64, &unit);
|
||||||
if (strlen(name) > 25){
|
if (strlen(name) > 25){
|
||||||
cligen_output(stdout, "%s\n", name);
|
cligen_output(stdout, "%s\n", name);
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ int xml_yang_mount_set(clixon_handle h, cxobj *x, yang_stmt *yspec);
|
||||||
int yang_mount_xtop2xmnt(cxobj *xtop, cvec **cvvp);
|
int yang_mount_xtop2xmnt(cxobj *xtop, cvec **cvvp);
|
||||||
int yang_mount_yspec2ymnt(yang_stmt *yspec, cvec **cvvp);
|
int yang_mount_yspec2ymnt(yang_stmt *yspec, cvec **cvvp);
|
||||||
int yang_schema_mount_statedata(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr);
|
int yang_schema_mount_statedata(clixon_handle h, yang_stmt *yspec, char *xpath, cvec *nsc, cxobj **xret, cxobj **xerr);
|
||||||
int yang_schema_mount_statistics(clixon_handle h, cxobj *xt, int modules, cbuf *cb);
|
|
||||||
int yang_schema_yanglib_parse_mount(clixon_handle h, cxobj *xt);
|
int yang_schema_yanglib_parse_mount(clixon_handle h, cxobj *xt);
|
||||||
int yang_schema_get_child(clixon_handle h, cxobj *x1, cxobj *x1c, yang_stmt **yc);
|
int yang_schema_get_child(clixon_handle h, cxobj *x1, cxobj *x1c, yang_stmt **yc);
|
||||||
int yang_schema_yspec_rm(clixon_handle h, cxobj *xmnt);
|
int yang_schema_yspec_rm(clixon_handle h, cxobj *xmnt);
|
||||||
|
|
|
||||||
|
|
@ -695,100 +695,6 @@ yang_schema_mount_statedata(clixon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Statistics about mountpoints
|
|
||||||
*
|
|
||||||
* @param[in] h Clixon handle
|
|
||||||
* @param[in] xtop Top XML node
|
|
||||||
* @param[in] modules
|
|
||||||
* @param[in] cb
|
|
||||||
* @retval 0 OK
|
|
||||||
* @retval -1 Error
|
|
||||||
* @see yang_schema_mount_statedata
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
yang_schema_mount_statistics(clixon_handle h,
|
|
||||||
cxobj *xtop,
|
|
||||||
int modules,
|
|
||||||
cbuf *cb)
|
|
||||||
{
|
|
||||||
int retval = -1;
|
|
||||||
cvec *cvv = NULL;
|
|
||||||
cg_var *cv;
|
|
||||||
cxobj *xmnt;
|
|
||||||
yang_stmt *yspec;
|
|
||||||
yang_stmt *ym;
|
|
||||||
int ret;
|
|
||||||
char *xpath = NULL;
|
|
||||||
uint64_t nr;
|
|
||||||
size_t sz;
|
|
||||||
cg_var *cv1;
|
|
||||||
yang_stmt *yspec1;
|
|
||||||
int inext;
|
|
||||||
|
|
||||||
if (yang_mount_xtop2xmnt(xtop, &cvv) < 0)
|
|
||||||
goto done;
|
|
||||||
cv = NULL;
|
|
||||||
while ((cv = cvec_each(cvv, cv)) != NULL) {
|
|
||||||
if ((xmnt = cv_void_get(cv)) == NULL)
|
|
||||||
continue;
|
|
||||||
if ((ret = xml_yang_mount_get(h, xmnt, NULL, &xpath, &yspec)) < 0)
|
|
||||||
goto done;
|
|
||||||
if (ret == 0)
|
|
||||||
continue;
|
|
||||||
cprintf(cb, "<module-set><name>mountpoint: ");
|
|
||||||
xml_chardata_cbuf_append(cb, 0, xpath);
|
|
||||||
cprintf(cb, "</name>");
|
|
||||||
nr = 0; sz = 0;
|
|
||||||
cv1 = NULL; /* For detecting shared YANGs */
|
|
||||||
if (yspec) {
|
|
||||||
cv1 = cv;
|
|
||||||
while ((cv1 = cvec_each(cvv, cv1)) != NULL) {
|
|
||||||
if (cv == cv1)
|
|
||||||
continue;
|
|
||||||
if ((ret = xml_yang_mount_get(h, cv_void_get(cv1), NULL, NULL, &yspec1)) < 0)
|
|
||||||
goto done;
|
|
||||||
if (yspec1 && yspec == yspec1)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cv1 != NULL || yspec == NULL){
|
|
||||||
cprintf(cb, "<nr>%" PRIu64 "</nr><size>%zu</size>", nr, sz);
|
|
||||||
cprintf(cb, "</module-set>");
|
|
||||||
if (xpath){
|
|
||||||
free(xpath);
|
|
||||||
xpath = NULL;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (yang_stats(yspec, 0, &nr, &sz) < 0)
|
|
||||||
goto done;
|
|
||||||
cprintf(cb, "<nr>%" PRIu64 "</nr><size>%zu</size>", nr, sz);
|
|
||||||
if (modules){
|
|
||||||
inext = 0;
|
|
||||||
while ((ym = yn_iter(yspec, &inext)) != NULL) {
|
|
||||||
cprintf(cb, "<module><name>%s</name>", yang_argument_get(ym));
|
|
||||||
nr = 0; sz = 0;
|
|
||||||
if (yang_stats(ym, 0, &nr, &sz) < 0)
|
|
||||||
goto done;
|
|
||||||
cprintf(cb, "<nr>%" PRIu64 "</nr><size>%zu</size>", nr, sz);
|
|
||||||
cprintf(cb, "</module>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cprintf(cb, "</module-set>");
|
|
||||||
if (xpath){
|
|
||||||
free(xpath);
|
|
||||||
xpath = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
retval = 0;
|
|
||||||
done:
|
|
||||||
if (xpath)
|
|
||||||
free(xpath);
|
|
||||||
if (cvv)
|
|
||||||
cvec_free(cvv);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! Get yanglib from user plugin callback, parse it and mount it
|
/*! Get yanglib from user plugin callback, parse it and mount it
|
||||||
*
|
*
|
||||||
* Optionally check for shared yspec
|
* Optionally check for shared yspec
|
||||||
|
|
|
||||||
|
|
@ -423,10 +423,10 @@ module clixon-lib {
|
||||||
}
|
}
|
||||||
container module-sets{
|
container module-sets{
|
||||||
list module-set{
|
list module-set{
|
||||||
description "Statistics per group of module, eg top-level and mount-points";
|
description "Statistics per domain, eg top-level and mount-points";
|
||||||
key "name";
|
key "name";
|
||||||
leaf name{
|
leaf name{
|
||||||
description "Name of YANG module.";
|
description "Name of YANG domain.";
|
||||||
type string;
|
type string;
|
||||||
}
|
}
|
||||||
leaf nr{
|
leaf nr{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue