pcp
[Top] [All Lists]

pmgraphite character substitution

To: PCP <pcp@xxxxxxxxxxx>
Subject: pmgraphite character substitution
From: Martins Innus <minnus@xxxxxxxxxxx>
Date: Thu, 15 Oct 2015 14:54:36 -0400
Delivered-to: pcp@xxxxxxxxxxx
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
Hi,
It seems like the current versions of graphite/grafana that are bundled with PCP are a little more tolerant of special characters than they used to be.

Such that we could do something like the following to shorten the labels that are displayed in the webapps( diff pasted below)

https://github.com/ubccr/pcp/tree/pmwebd

All my tests with graphite and grafana seem to work with this change. Also changing QA 661 (I think the only test that uses this functionality) seems to pass once the metric names are changed as in my git branch.

The only thing that I think we can't leave unencoded are "dots" in the instance names. So with my change, these become (in a snippet from QA 661):


3123c3123
< "name": "src-2F-node_archive-2E-meta.proc.psinfo.pid.001533 -2F-usr-2F-bin-2F-python -2F-ifs-2F-user-2F-tyearke-2F-test-2F-wait-2E-py",
---
> "name": "src/node_archive.proc.psinfo.pid.001533 /usr/bin/python /ifs/user/tyearke/test/wait%2Epy",


Let me know if there is a reason this shouldn't work, or any other tests I can do. I've looked at several hundred archives over dozens of hosts during the last week or so and it seems to have held up. For me at least it makes reading the metric name and labels easier.

Thanks

Martins



diff --git a/src/pmwebapi/pmgraphite.cxx b/src/pmwebapi/pmgraphite.cxx
index 8d8e0cd..5948cad 100644
--- a/src/pmwebapi/pmgraphite.cxx
+++ b/src/pmwebapi/pmgraphite.cxx
@@ -112,10 +112,10 @@ pmgraphite_metric_encode (const string & foo)
         char c = foo[i];
// Pass through enough characters to make the metric names relatively
         // human-readable in the javascript guis
-        if (isalnum (c) || (c == '_') || (c == ' ')) {
+ if (isalnum (c) || (c == '_') || (c == ' ') || (c == '-') || (c == '/') ) {
             output << c;
         } else {
- output << "-" << hex[ (c >> 4) & 15] << hex[ (c >> 0) & 15] << "-";
+            output << "%" << hex[ (c >> 4) & 15] << hex[ (c >> 0) & 15];
         }
     }
     return output.str ();
@@ -130,8 +130,8 @@ pmgraphite_metric_decode (const string & foo)
     static const char hex[] = "0123456789ABCDEF";
     for (unsigned i = 0; i < foo.size (); i++) {
         char c = foo[i];
-        if (c == '-') {
-            if (i + 3 >= foo.size ()) {
+        if (c == '%') {
+            if (i + 2 >= foo.size ()) {
                 return "";
             }
             const char *p = lower_bound (hex, hex + 16, foo[i + 1]);
@@ -142,11 +142,8 @@ pmgraphite_metric_decode (const string & foo)
             if (*q != foo[i + 2]) {
                 return "";
             }
-            if ('-' != foo[i + 3]) {
-                return "";
-            }
             output += (char) (((p - hex) << 4) | (q - hex));
-            i += 3;            // skip over hex bytes
+            i += 2;            // skip over hex bytes
         } else {
             output += c;
         }
@@ -331,6 +328,13 @@ vector <string> pmgraphite_enumerate_metrics (struct MHD_Connection * connection
                 (char) __pmPathSeparator ())) {
             archivepart = archivepart.substr (archivesdir.size () + 1);
         }
+        // Remove the .meta part
+        string metastring = ".meta";
+        string::size_type metaidx = archivepart.find( metastring );
+
+        if (metaidx != std::string::npos)
+           archivepart.erase(metaidx, metastring.length());
+
         archivepart = pmgraphite_metric_encode (archivepart);

         // Filter out mismatches of the first pattern component.
@@ -1164,7 +1168,8 @@ pmgraphite_fetch_all_series (struct MHD_Connection* connection, const vector<str
             js.t_start = t_start;
             js.t_end = t_end;
             js.t_step = t_step;
-            js.archive = archive_part;
+ // We took off the meta for display purposes, add it back on to open the file
+            js.archive = archive_part+".meta";
             it = jobmap.insert(make_pair(archive_part,js)).first;
         }


<Prev in Thread] Current Thread [Next in Thread>