[scripting] A way to add datatraffic

Icheb

Verified User
Joined
Sep 15, 2003
Messages
556
Location
The Netherlands
I'm currently working on a script that is able to read out the used datatraffic for a certain user for some non DA related services. But I wanted to use the datatraffic system within DA for this.

Is there any way I can safely add traffic to user x without breaking any files ?
Or connect DA to a mysql DB which would contain the extra used traffic for all users ?

(Just one method would really be enough ;))
 
Hello.

Append the number of bytes to the

/usr/local/directadmin/data/users/username/bandwidth.tally

John
 
Please post this when you get it finished :D

I'd love it to count bytes for wget & shoutcast :)
 
l0rdphi1 said:
Please post this when you get it finished :D

I'd love it to count bytes for wget & shoutcast :)

That's gonna be quite hard, since I didn't keep a real track of everything I tried.
At the moment I'm using the program IPFM to figure out what and how traffic was generated...

The only thing I don't see yet is the format of these bandwidth.tally entry's...

example:
41708392.000000
10688725.000000
10032376.000000
18267274.000000
5165004.000000
4417240.000000
3608098.000000
4720176.000000

I would think these to be bytes, but why is the . there, since all stuff behind it are all 0's...
 
Yes, if I remember correctly, those are bytes. God knows why the .000000 is there.
 
This has put another idea into my mind... email alerts upon users coming close to their quotas :) - user definable % usage for alerts of course... anyone interested in such a script?

Chris
 
ProWebUK said:
This has put another idea into my mind... email alerts upon users coming close to their quotas :) - user definable % usage for alerts of course... anyone interested in such a script?

Chris

That would be cool if integrated in DA :)

John...? :p
 
Hello,

Yes, the .00000 at the end don't really serve any purpose, but because it use the "double" format instead of "int" or "long", it adds the zeros. You don't need to add them if you don't want to, it should be able to read a regular number just fine.

Current DA *does* send an notification when bandwidth reaches a certain limit. Users are notified at 80% and Resellers at 75%. They are also given an estimate for how many days they have left (simple math for the rate of usage to figure out number of days left)

Those %'s are currently hard coded, and cannot be changed.

John
 
DirectAdmin Support said:

Current DA *does* send an notification when bandwidth reaches a certain limit. Users are notified at 80% and Resellers at 75%. They are also given an estimate for how many days they have left (simple math for the rate of usage to figure out number of days left)

Give me a break.. you beat me to everything :rolleyes: :D

Chris (Trying to find a feature not implemented into DA already)
 
ProWebUK said:
Give me a break.. you beat me to everything :rolleyes: :D

Chris (Trying to find a feature not implemented into DA already)

I know something :D

How about with each monthly tally the traffic values are *stored* into a log of somekind so that the user or the admin can see the final traffic of that month...

Yes, the .00000 at the end don't really serve any purpose, but because it use the "double" format instead of "int" or "long", it adds the zeros. You don't need to add them if you don't want to, it should be able to read a regular number just fine.
Ok, that's enough info :D
Well, knowing some programming languages don't like working with other formats, I'll just convert my values into a string so that I can add the . and the 0's before I add it to the file.
 
Icheb said:
I know something :D

How about with each monthly tally the traffic values are *stored* into a log of somekind so that the user or the admin can see the final traffic of that month...

Just run a cron command that runs 5 minutes before DA resets it...

Code:
10 1 1 * * root cp /etc/usr/local/directadmin/data/users/username/bandwidth.tally /var/log/bandwidth_usage.log

That will backup the bandwidth usage 10 minutes before it gets reset on a standard DA install - with it that simple you can only have data backed up for 1 month - a 5 minutes script could get that to store X months worth of backlogs, compress old logs if needed and setup logrotate to include them...

Note the above cron will only work for 1 user (replacing "username" with that user) - will look at getting something in place for this - maybe log for each user then have a tool which can print a list of all users with some stats such as

Bandwidth Used
Bandwidth allocated
% Usage
Average Monthly usage (based over X months)

That the kind of thing you are looking for? or a simple backup of logs per domain (using the same format while - simply copied?)

Chris
 
That the kind of thing you are looking for?

Yes, partially, I will need to dump this info into a db, which can be accessed by users who log in to my company's website to provide some graphical views...

Instead of a cp command, wouldn't it be better if it called for a certain script that can add all these values (or a total of them) to a database ? (Perl?)
I must admit, I know absolutely nothing about perl scripting at the moment, so personally I am unable to make something like this. (Although I could make a script in PHP to do it)
 
I'm not there with perl either... but it could be put on a cronjob with output (averages and actual data) placed into a mysql database directly.

Chris
 
ProWebUK said:
I'm not there with perl either... but it could be put on a cronjob with output (averages and actual data) placed into a mysql database directly.

Chris

What do you mean with directly ?
A cronjob that's giving out certain values directly converted within the cronjob to SQL query's that will be added to a db using the mysql client within the same cronjob ?

If that's the case, I would give it up right now, I know it's doable, just not by me. Simple bash scripting ok, but this isn't simple anymore :D

But how about a bash script called just before DA's monthly tally that reads out the values and puts them into a db ?
(Although I don't really know how to get Bash to generate nice SQL query's)

(I'd rather give it a try in PHP :D)
 
Well, you can use mysql directly from shell / bash - therefore you can insert data into a mysql database that can then be used in whatever way you wish - perl, php etc... you simply code a script to grab those values and do what you want... the shell script would give the ability to quickly view backlogs of any domain full stats etc if I were to do it - mysql would just be a further add-on for any users wishing to expand on the stats retrieved.

If you would prefer it could be 'modular' for example the script runs and passes a set of variables (including different stats / figures etc) to a php file.... then your simply passing the php script with variables from the shell script - not sure how I would do that but it's certainly something to look into.

Chris
 
Just to let you know I have done the script to get all users and get their bandwidth data... so insert directly into mysql or would you prefer variables passed through to your own script?

Chris
 
ProWebUK said:
Just to let you know I have done the script to get all users and get their bandwidth data... so insert directly into mysql or would you prefer variables passed through to your own script?

Chris

WOW

If you want, directly into a database would be fine by me (this way other users can use it as well)
 
are there some updates?

'offtopic'

is there a script that sends every last day of a month a totally report of used traffic & mb's etc about users/resellers?
 
Back
Top