UNSOLVED

McBride1

updated

10 years ago

M

McBride1

1 Message

0

785

July 18th, 2016 11:00

PostgreSQL-queries for statistical purposes

Hello everyone,

Like the most of you I'm also a Avamar-user and very font of stats and graphs.

For the past couple of weeks I've been trying to create the following stats:

  1. Amount of data protected per domain (as in a domain in Avamar Administration, not Data Domain(s)).
  2. Amount of data protected per domain per server/client.
  3. Amount of servers/clients per domain (once again, as in domain in Administration, not Data Domain(s)).

What I've done so far is try to merge this SQL-code

select CASE WHEN display_name is NULL

                 THEN client_name

            ELSE display_name

       END as "ClientName",

       plugin_name as "PlugInName",

       CASE WHEN sch_sum_bytes is NULL

                 THEN '/Client On-Demand Data'

            WHEN adhoc_max_bytes is NULL

                 THEN 'All Custom Datasets'

            WHEN sch_sum_bytes >= adhoc_max_bytes

                 THEN 'All Custom Datasets'

            WHEN sch_sum_bytes < adhoc_max_bytes

                 THEN '/Client On-Demand Data'

            ELSE 'REPORT ERROR'

       END as "Dataset",

       cast((

       CASE WHEN sch_sum_bytes is NULL

                 THEN adhoc_max_bytes

            WHEN adhoc_max_bytes is NULL

                 THEN sch_sum_bytes

            WHEN sch_sum_bytes >= adhoc_max_bytes

                 THEN sch_sum_bytes

            WHEN sch_sum_bytes < adhoc_max_bytes

                 THEN adhoc_max_bytes

            ELSE 99999999

       END) / 1024/1024/1024 as numeric(30,4)) as "TotalGBProtected",

          c.agent_version as "Version",

          c.os_type as "OS",

          case when c.is_client_os='t' then 'true' when c.is_client_os='f' and c.agent_version !~ '^1.|^2.|^3.|^4.|^5.|^6.0' then 'false' else 'unknown' end as "IsClientOS"

from (select cid, client_name, display_name,

              plugin_name,

              sum( sch_max_bytes ) as sch_sum_bytes

       from ( select cid, client_name, display_name,                 

                     plugin_name,

                     dataset,

                     max(bytes_scanned) as sch_max_bytes

              from v_activities_2

              where (v_activities_2.status_code in (30000, 30005)) and

                    (v_activities_2.type like '%Backup%') and

                    (v_activities_2.dataset not like '/Client On-Demand Data') and

                    (expiration_ts = '0' or expiration_ts::double precision >= extract( epoch from now() ))

              group by cid, client_name, display_name, plugin_name, dataset ) as sel1

       group by cid, client_name, display_name, plugin_name ) as sel2

FULL JOIN

       ( select cid, client_name, display_name, plugin_name, max(bytes_scanned) as adhoc_max_bytes

              from v_activities_2

              where (v_activities_2.status_code in (30000, 30005)) and

                    (v_activities_2.type like '%Backup%') and

                    (v_activities_2.dataset like '/Client On-Demand Data') and

                    (expiration_ts = '0' or expiration_ts::double precision >= extract( epoch from now() ))

              group by cid, client_name, display_name, plugin_name ) as sel3

USING (cid, client_name, display_name, plugin_name) LEFT JOIN clients c USING (cid)

which has this result:

screenshot.18-07-2016_19.46.56001.png

with a few blocks of SQL-code

select

       CASE

         WHEN

           length(substr(full_domain_name, 1, length(full_domain_name) - length(client_name))) = 1

         THEN

           substr(full_domain_name, 1, length(full_domain_name) - length(client_name))

         ELSE

           substr(full_domain_name, 1, length(full_domain_name) - length(client_name) - 1)

         END  as "ClientDomain",

       CASE WHEN display_client_name is NULL

                 THEN client_name

            ELSE display_client_name

       END as "ClientName",

       to_char(created, 'mm/dd/yyyy') as "RegisteredDate",

       registered as "Activated",

       to_char(registered_ts, 'mm/dd/yyyy hh24:mi:ss') as "ActivatedDateTime",

       to_char(checkin_ts, 'mm/dd/yyyy hh24:mi:ss') as "LastCheckedIn",

       contact_name as "ContactName",

       contact_phone as "ContactPhone",

       contact_email as "ContactEmail",

       contact_location as "ContactLocation",

       contact_notes as "ContactNotes",

       os_type as "OS",

       agent_version as "ClientVersion",

       client_addr as "ClientAddr"

  from v_clients_2, axion_systems

  where has_backups = true

    and axion_systems.systemid = 1

    and full_domain_name not like '%MC_RETIRED%'

which has this result:

screenshot.18-07-2016_19.53.00001.png


As stated before, I'm not interested in the outcome of the query above except the "ClientDomain" part (of the code). What I'm trying to do is very simple; I'm using the first query and the "ClientDomain"-code of the second query in combination with a inner/full join-statement, hoping that the outcome will be something like:

screenshot.18-07-2016_19.58.59001.png

But as you may have predicted already, I've not been able to do so .


Can anyone help me please?






  • Maurici0

    1 Message

    353

    0

    Posted July 20th, 2016 13:00

    Hello McBride,


    I've rewritten your query a little bit and added a few items. Let me know if this works for you.


    SELECT

    join_clients.mcs_addr AS "Avamar Node",

    CASE

         WHEN length(substr(join_v_clients.full_domain_name, 1, length(join_v_clients.full_domain_name) - length(join_v_clients.client_name))) = 1

      THEN substr(join_v_clients.full_domain_name, 1, length(join_v_clients.full_domain_name) - length(join_v_clients.client_name))

         ELSE substr(join_v_clients.full_domain_name, 1, length(join_v_clients.full_domain_name) - length(join_v_clients.client_name) - 1)

    END AS "ClientDomain",

    CASE

         WHEN display_name IS NULL

      THEN client_name

         ELSE display_name

    END AS "ClientName",

    plugin_name AS "PlugInName",

    CASE

         WHEN sch_sum_bytes IS NULL

      THEN '/Client On-Demand Data'

         WHEN adhoc_max_bytes IS NULL

      THEN 'All Custom Datasets'

         WHEN sch_sum_bytes >= adhoc_max_bytes

      THEN 'All Custom Datasets'

         WHEN sch_sum_bytes < adhoc_max_bytes

      THEN '/Client On-Demand Data'

         ELSE 'REPORT ERROR'

    END AS "Dataset",

    cast(( CASE WHEN sch_sum_bytes IS NULL

      THEN adhoc_max_bytes

      WHEN adhoc_max_bytes IS NULL

      THEN sch_sum_bytes

      WHEN sch_sum_bytes >= adhoc_max_bytes

      THEN sch_sum_bytes

      WHEN sch_sum_bytes < adhoc_max_bytes

      THEN adhoc_max_bytes

      ELSE 99999999 END) / 1024/1024/1024 AS numeric(30,4)) AS "TotalGBProtected",

    join_clients.agent_version AS "Version",

    join_clients.os_type AS "OS",

    CASE

         WHEN join_clients.is_client_os='t'

      THEN 'true'

         WHEN join_clients.is_client_os='f'

      AND join_clients.agent_version !~ '^1.|^2.|^3.|^4.|^5.|^6.0' THEN 'false'

         ELSE 'unknown'

    END AS "IsClientOS"

    FROM

      (SELECT cid,

              client_name,

              display_name,

              plugin_name,

              sum(sch_max_bytes) AS sch_sum_bytes

       FROM

         (SELECT cid,

                 client_name,

                 display_name,

                 plugin_name,

                 dataset,

                 max(bytes_scanned) AS sch_max_bytes

          FROM v_activities_2

          WHERE (v_activities_2.status_code IN (30000,30005))

            AND (v_activities_2.type LIKE '%Backup%')

            AND (v_activities_2.dataset NOT LIKE '/Client On-Demand Data')

            AND (expiration_ts = '0' OR expiration_ts::double precision >= extract(epoch FROM now()))

          GROUP BY cid,

                   client_name,

                   display_name,

                   plugin_name,

                   dataset) AS sel1

       GROUP BY cid,

                client_name,

                display_name,

                plugin_name) AS sel2

    FULL JOIN

      (SELECT cid,

              client_name,

              display_name,

              plugin_name,

              max(bytes_scanned) AS adhoc_max_bytes

       FROM v_activities_2

       WHERE (v_activities_2.status_code IN (30000,30005))

         AND (v_activities_2.type LIKE '%Backup%')

         AND (v_activities_2.dataset LIKE '/Client On-Demand Data')

         AND (expiration_ts = '0' OR expiration_ts::double precision >= extract(epoch FROM now()))

       GROUP BY cid,

                client_name,

                display_name,

                plugin_name) AS sel3 USING (cid,

                                            client_name,

                                            display_name,

                                            plugin_name)

    LEFT JOIN clients join_clients USING (cid)

    LEFT JOIN v_clients join_v_clients USING (cid,

                                             client_name)