Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docker/openstack-accounting/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM registry.cern.ch/cmsmonitoring/cmsmon-py:test

# Copy only the specific files you need instead of cloning entire repos
COPY src/ ./

3 changes: 3 additions & 0 deletions docker/openstack-accounting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Openstack Accounting cron job

Code base of the Docker image used for the openstack-accounting cronjob, which generates data about Openstack usage from different groups and publishes it in the [Openstack Quotas And Usage Monitoring website](https://cmsdatapop.web.cern.ch/cmsdatapop/eos_openstack/openstack_accounting.html) of the CMS Data Popularity service.
58 changes: 58 additions & 0 deletions docker/openstack-accounting/src/cron4openstack_accounting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
##H Script to create CMS Eos path sizes with conditions
##H CMSVOC and CMSMONITORING groups are responsible for this script.
set -e
TZ=UTC
myname=$(basename "$0")
script_dir="$(cd "$(dirname "$0")" && pwd)"
# Get nice util functions
. "${script_dir}"/utils.sh

# Do not change the order of "--output_file"([0],[1]) which is replaced in K8s run
py_input_args=(
--output_file "/eos/user/c/cmsmonit/www/eos_openstack/openstack_accounting.html"
--summary_json "/eos/cms/store/accounting/openstack_accounting_summary.json"
--static_html_dir "${script_dir}/html"
)

# ---------------------------------------------------------------------------------------------------------- Run in K8S
if [ -n "$K8S_ENV" ]; then
# $1: output
# Replace static output file with user arg for testability.
py_input_args[1]=$1

util4logi "${myname} is starting.."
util_cron_send_start "$myname" "1h"

util_kerberos_auth_with_keytab /etc/secrets/keytab
python3 "${script_dir}"/openstack_accounting.py "${py_input_args[@]}" 2>&1

util_cron_send_end "$myname" "1h" "$?"
util4logi "${myname} successfully finished."
exit 0
# break
fi
# Run in LxPlus for test ----------------------------------------------------------------------------------------------

. /cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos7-gcc8-opt/setup.sh

# Catch output to not print successful jobs stdout to email, print when failed
output=$(pip install --user schema 2>&1)
ec=$?
if [ $ec -ne 0 ]; then
echo "$output" - exit code: $ec
exit $ec
fi

if ! [ "$(python -c 'import sys; print(sys.version_info.major)')" = 3 ]; then
echo "It seem python version is not 3.X! Exiting..."
exit 1
fi

# Catch output to not print successful jobs stdout to email, print when failed
output=$(python "{$script_dir}"/openstack_accounting.py "${py_input_args[@]}" 2>&1)
ec=$?
if [ $ec -ne 0 ]; then
echo "$output" - exit code: $ec
exit $ec
fi
227 changes: 227 additions & 0 deletions docker/openstack-accounting/src/html/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- prepared using https://datatables.net/download/ -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-3.6.0/jszip-2.5.0/dt-1.12.1/b-2.2.3/b-colvis-2.2.3/b-html5-2.2.3/b-print-2.2.3/cr-1.5.6/date-1.1.2/kt-2.7.0/rr-1.2.8/sc-2.0.6/sb-1.3.3/sp-2.0.1/sl-1.4.0/sr-1.1.1/datatables.min.css"/>

<!-- Please do not delete below CSSes, important for pretty view -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.12.1/datatables.min.css"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.4/css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.2.2/css/buttons.bootstrap.min.css">

<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
body {
font-family: 'Trebuchet MS', sans-serif;
}
/* Search bar */
#DataTables_Table_0_filter input{
border: 3px solid Tomato;!important;
width: 300px;!important;
font-size: 14px;
font-weight: bold;
}
table th {
white-space: wrap;
}
/* From 2nd column, align to right */
table td:nth-child(n+2) {
text-align: right;
}
/* First row bold */
table td:nth-child(1) {
font-weight: bold;
}
/* Path title */
table th:nth-child(1) {
color: #990000;
}
/* Header rows, total and titles, align right */
table th:nth-child(n+2) {
text-align: right !important;
color: #990000 !important;
}
/* Different background color for even and odd columns */
.table.display tr:nth-child(even) {
/* background-color: #dddfff; */
}
/* No carriage return for values, no break lines */
table tr td {
width: 1%;
white-space: nowrap;
}
/* button */
div.dt-buttons {
float: right;
}
.dt-button.buttons-columnVisibility.active {
background: #FF0000 !important;
color: white !important;
opacity: 0.5;
}
.dt-button.buttons-columnVisibility {
background: black !important;
color: white !important;
opacity: 1;
}

div.dataTables_wrapper {
margin-bottom: 3em;
}

<!-- Divider -->
.divider {
text-align:center;
}
.divider hr {
margin-left:auto;
margin-right:auto;
width:100%;
}
</style>
</head>
<body>
<div class="container-fluid no-padding" style="width: 100%">
<div class="row" style="background-color: #ECF2F9">
<div class="col-xs-6 col-sm-4">
<footer>
<img alt="CERN CMS" src="https://cds.cern.ch/record/1306150/files/cmsLogo_image.jpg"
width="40" height="40">
</footer>
</div>
<div class="col-xs-6 col-sm-4 align-self-center">
<h3> Openstack Quotas And Usage Monitoring </h3>
</div>
<div class="col-xs-6 col-sm-4 text-right ">
<footer>
<img alt="CERN CMS O&C" src="https://cds.cern.ch/record/1306150/files/cmsLogo_image.jpg" style="text-align: right;"
width="40" height="40">
</footer>
</div>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><div><a href="#" onclick="explainFunction()">&darr; How to interpret this table &darr;</a></div></li>
<li style="height: 100%;"> &nbsp; &#9551; &nbsp; </li>
<li><div> <small style="text-align: right;">Last Update UTC: __UPDATE_TIME__ </small> </div></li>
</ul>
</div><!--/.nav-collapse -->
<div class="row" style="background-color: #ECF2F9">
</div>
</div>
<div id="explanations" style="display: none; margin-top: 2%;">
<pre>
Cron script: <a href="https://github.com/dmwm/CMSMonitoring/blob/master/scripts/cron4openstack_accounting.sh" target="_blank">CMSMonitoring/scripts/cron4openstack_accounting.sh</a>
Python code: <a href="https://github.com/dmwm/CMSMonitoring/blob/master/src/python/CMSMonitoring/openstack_accounting.py" target="_blank">openstack_accounting.py</a>
HTML/JS: <a href="https://github.com/dmwm/CMSMonitoring/blob/master/src/html/openstack_accounting/main.html" target="_blank">html/openstack_accounting/main.html</a>
Source Input File: /eos/cms/store/accounting/openstack_accounting_summary.json
Last Update UTC: last modification of input JSON file
Responsible team for the source file: <a href="https://its.cern.ch/jira/browse/CMSVOC" target="_blank">CMS VOC</a>
There are many <b>hidden columns</b>, use <b>Column Visibility</b> button to make them visible.
</pre>
</div>

<div class="container" style="display:block; width:90%">
____SUMMARY_BLOCK____

</div>
<!-- prepared using https://datatables.net/download/ -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/jqc-1.12.4/jszip-2.5.0/dt-1.12.1/af-2.4.0/b-2.2.3/b-colvis-2.2.3/b-html5-2.2.3/b-print-2.2.3/cr-1.5.6/date-1.1.2/fc-4.1.0/fh-3.2.3/r-2.3.0/sb-1.3.3/sp-2.0.1/sl-1.4.0/sr-1.1.1/datatables.min.js"></script>
<!-- Please do not delete below JS which is required for footerCallback-->
<script type="text/javascript" src="https://cdn.datatables.net/fixedheader/3.2.3/js/dataTables.fixedHeader.min.js"></script>
<script>
function explainFunction() {
var x = document.getElementById("explanations");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
<script>
var url = new URL(window.location.href);
var searchString = url.searchParams.get("search");
if (searchString == null){
searchString = ''
}
//
$(document).ready(function () {
var dt = $('table.display').DataTable( {
"orderCellsTop": true,
"dom": "fBrtpli",
"order": [[ 0, "asc" ]],
"pageLength" : 3000,
"scrollX": false,
"oSearch": { "sSearch": searchString },
language: {
search: "_INPUT_",
searchPlaceholder: "--- Search Openstack Project ---",
},
lengthChange: false,
"footerCallback": function ( row, data, start, end, display ) {
// Footer callback is used for calculating Totals
var api = this.api(), data;
api.columns('.sum', { page: 'current'}).every( function () {
var sum = this
.data()
.reduce( function (a, b) {
return parseInt(a) + parseInt(b);
}, 0 );
console.log(sum)
this.footer().innerHTML = sum;
} );
},
// DEFAULT SHOW ONLY: 0: 'Openstack Project Name', 14: 'Total RAM Used', 15: 'Total Cores Used', 16: 'Total Instances Used' and 30: 'Contacts' columns.
// UPDATE WHEN SCHEMA CHANGES!
"columnDefs": [
{
"targets": [0, 14, 15, 16, 30] ,
"visible": true
},
{
"targets": '_all',
"visible": false
}
],
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'excelHtml5',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'pdfHtml5',
exportOptions: {
columns: ':visible'
}
},
'colvis',
{
text: 'Copy search link to clipboard',
action: function ( e, dt, node, config ) {
url.searchParams.set('search', dt.search());
//window.location.replace(url.href);
navigator.clipboard.writeText(url.href);
}
},
]
});
//
dt.buttons().container().appendTo( '#example_wrapper .col-sm-4:eq(0)' );
});
</script>
</body>
<!-- final -->
</html>
Loading